def test_app_post_errors(testapp): with env(GITHUB_USER="******"),\ env(GHIA_CONFIG=(f'{make_path("auth.secret.cfg")}:' f'{make_path("rules.fallback.cfg")}:' f'{make_path("rules.no_fallback.cfg")}')): response = testapp.post( "/", json=load_example("ping_example.json"), headers={ 'X-Hub-Signature': 'sha1=d00e131ec9215b2a349ea1541e01e1a84ac38d8d', 'X-GitHub-Event': 'ping' }) assert "401 Unauthorized" in response.get_data(as_text=True) assert response.status_code == 401 response = testapp.post( "/", json=load_example("ping_example.json"), headers={ 'X-Hub-Signature': 'sha1=d00e131ec9215b2a349ea1541e01e1a84ac38d8e', 'X-GitHub-Event': 'pong' }) assert response.status_code == 501 response = testapp.post("/", json=load_example("issues_wrong_action.json"), headers={'X-GitHub-Event': 'issues'}) assert response.status_code == 501
def test_post_issues_connection_error(mock_session): with pytest.raises(requests.HTTPError): with env(GITHUB_USER="******"),\ env(GHIA_CONFIG=(f'{make_path("auth.secret.cfg")}:' f'{make_path("rules.fallback.cfg")}:' f'{make_path("rules.no_fallback.cfg")}')): config = read_config() session = requests.Session() process_post_issues(load_example("issues_example.json"), config, session)
def test_process_post_issues(mock_session): with env(GITHUB_USER="******"),\ env(GHIA_CONFIG=(f'{make_path("auth.secret.cfg")}:' f'{make_path("rules.fallback.cfg")}:' f'{make_path("rules.no_fallback.cfg")}')): config = read_config() session = requests.Session() response = process_post_issues(load_example("issues_example.json"), config, session) assert "was successfully updated" in response
def test_update_github(mock_session): i = create_issue(load_example("issues_example.json")["issue"]) session = requests.Session() update_github(i, session) i.update_assignees = True with pytest.raises(requests.HTTPError): update_github(i, session) i.update_assignees = False i.update_labels = True with pytest.raises(requests.HTTPError): update_github(i, session)
def test_match_rule(): i = create_issue(load_example("issues_example.json")["issue"]) rule = dict() rule["text"] = list() rule["label"] = list() rule["any"] = list() rule["title"] = list() assert not match_rule(i, rule) rule["text"].append(re.compile("commit")) assert match_rule(i, rule)
def test_app_post_ping(testapp): with env(GITHUB_USER="******"),\ env(GHIA_CONFIG=(f'{make_path("auth.secret.cfg")}:' f'{make_path("rules.fallback.cfg")}:' f'{make_path("rules.no_fallback.cfg")}')): assert "Ping successful" == testapp.post( "/", json=load_example("ping_example.json"), headers={ 'X-Hub-Signature': 'sha1=d00e131ec9215b2a349ea1541e01e1a84ac38d8e', 'X-GitHub-Event': 'ping' }).get_data(as_text=True)
def test_strategy(strategy): i = create_issue(load_example("issues_example.json")["issue"]) users = ("Assignee1", "Assignee2") echoes = apply_strategy(strategy, i, users) if strategy == "append": assert contains_exactly(i.assignees, ("Codertocat", "Assignee1", "Assignee2")) assert len(echoes) == 3 elif strategy == "set": assert contains_exactly(i.assignees, ("Codertocat", )) assert len(echoes) == 1 else: assert contains_exactly(i.assignees, users) assert len(echoes) == 3
def test_create_issue(): i = create_issue(load_example("issues_example.json")["issue"]) assert isinstance(i, Issue) assert i.number == 1 assert i.title == "Spelling error in the README file" assert i.url == "https://api.github.com/repos/Codertocat/Hello-World/issues/1" assert i.html_url == "https://github.com/Codertocat/Hello-World/issues/1" assert i.body == "It looks like you accidently spelled 'commit' with two 't's." assert contains_exactly(i.labels, ("bug", )) assert contains_exactly(i.assignees, ("Codertocat", )) i.add_assignees(("Assignee", )) i.update_assignees = True i.update_labels = True d = i.serialize() assert contains_exactly(d["labels"], ("bug", )) assert contains_exactly(d["assignees"], ("Codertocat", "Assignee"))
def test_process_issue(strategy): i = create_issue(load_example("issues_example.json")["issue"]) rules = dict() rule = dict() rule["text"] = list() rule["label"] = list() rule["any"] = list() rule["title"] = list() rule["text"].append(re.compile("commit")) rules["Assignee1"] = rule echoes = process_issue(i, strategy, rules) if strategy == "append": assert i.update_assignees assert contains_exactly(i.assignees, ["Codertocat", "Assignee1"]) assert len(echoes) == 2 elif strategy == "set": assert not i.update_assignees assert contains_exactly(i.assignees, ["Codertocat"]) assert len(echoes) == 1 else: assert i.update_assignees assert contains_exactly(i.assignees, ["Assignee1"]) assert len(echoes) == 2