def test_GitHub_fetch_commits_request_not_ok(m): g = GitHub('18f.gsa.gov', '18F') endpoint = "commits" url = "%s/repos/%s/%s/%s" % (g.api, g.owner, g.repo, endpoint) m.get(url, json=[], status_code=404, headers={'Content-Type': 'text/html'}) actual = g.fetch_commits() assert actual is False
def test_GitHub_fetch_endpoint_when_request_not_ok(m): g = GitHub('18f.gsa.gov', '18F') endpoint = "nonexistentendpoint" url = "%s/repos/%s/%s/%s" % (g.api, g.owner, g.repo, endpoint) m.get(url, text="", status_code=404, headers={'Content-Type': 'text/html'}) actual = g.fetch_endpoint(endpoint) assert actual is False
def test_GitHub_fetch_commits_request_ok(m): g = GitHub('18f.gsa.gov', '18F') endpoint = "commits" url = "%s/repos/%s/%s/%s" % (g.api, g.owner, g.repo, endpoint) m.get(url, json=[{"name": "18f.gsa.gov"}], status_code=200) actual = g.fetch_commits() assert actual == [{'name': '18f.gsa.gov'}]
def test_GitHub_fetch_raw_when_request_not_ok(m): g = GitHub('18f.gsa.gov', '18F') request_string = "18F/18f.gsa.gov/staging/go.html" url = "https://raw.githubusercontent.com/18F/18f.gsa.gov/staging/go.html" m.get(url, status_code=418, text="I'm a teapot") actual = g.fetch_raw(request_string) assert actual is False
def test_GitHub_fetch_raw(m): g = GitHub('18f.gsa.gov', '18F') request_string = "18F/18f.gsa.gov/staging/go" url = "https://raw.githubusercontent.com/%s" % request_string m.get(url, text="Success!", status_code=200) actual = g.fetch_raw(request_string) assert actual.text == "Success!"
def test_GitHub_parse_by_key(): g = GitHub('', '') expected = ['data-pull', 'data-push'] data = [{"name": "data-push"}, {"name": "data-pull"}, {"name": "nondata-push"}] actual = g.parse_by_key(data, 'name', 'data') assert expected.sort() == actual.sort()
def test_GitHub_split_by_event(): events = list() expected = list() events.append({'event': 'milestoned', 'name': 'Issue 0'}) events.append({'event': 'closed', 'name': 'Issue 1'}) expected.append(events[0]) g = GitHub('18f.gsa.gov', '18F') actual = g.split_by_event(events, 'milestoned') assert actual == expected
def test_GitHub_fetch_issues(m): g = GitHub('18f.gsa.gov', '18F') url = "%s/repos/%s/%s/issues?per_page=100" % (g.api, g.owner, g.repo) expected = [{"number": i} for i in range(100)] m.get(url, json=expected, status_code=200, headers={'Content-Type': 'application/json'}) actual = g.fetch_issues() assert list(actual) == expected
def test_GitHub_parse_by_key(): g = GitHub('', '') expected = ['data-pull', 'data-push'] data = [{ "name": "data-push" }, { "name": "data-pull" }, { "name": "nondata-push" }] actual = g.parse_by_key(data, 'name', 'data') assert expected.sort() == actual.sort()
def test_GitHub_fetch_issues_request_not_ok(m): g = GitHub('18f.gsa.gov', '18F') url = "%s/repos/%s/%s/issues" % (g.api, g.owner, g.repo) m.get(url, text="I'm a teapot", status_code=418) actual = g.fetch_issues() assert actual == False