Skip to content

Instantly share code, notes, and snippets.

View edthrn's full-sized avatar

ed edthrn

View GitHub Profile
@edthrn
edthrn / 1-Unit-testing with PyGithub.md
Last active October 19, 2023 05:09
Unit-testing with PyGithub

Intro

Lately, I've been building a Python platform that relies heavily on interactions with Github. Instead of re-inventing the wheel, I decided to go with PyGithub as a wrapper around Github v3 API.

The problem

This library implements the full API, which allows me to be very productive when I need to add a workflow in my platform that involves Github. However, it quickly became a real PITA to write unit tests. Even if the package comes with its own testing Framework, it is not documented yet and I didn't manage to crack it up in a decent amount of time.

I decided to hack the testing a little bit, using another very cool package, httpretty. Httpretty allows you to monkey patch the socket module during testing, so you can respond anything you want to any kind of network requests. Here's what I came up with, do not hesitate to give any feedback.


@edthrn
edthrn / cognito-auth.js
Last active August 15, 2018 17:11
A sample use case of sending a message to an API protected by AWS Cognito.
function ajax(method, url, data, callback) {
var req = new XMLHttpRequest();
req.open(method, url);
req.addEventListener("load", function () {
if (req.status >= 200 && req.status < 400) {
callback();
} else {
console.error(req.status + " " + req.statusText + " " + url);
}
@edthrn
edthrn / Makefile
Created July 26, 2018 20:44 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)