def test_bugs_fails_on_network_error(db): with bugs_session() as bugs: def dud_post(url, auth, json): class _PostReturn: status_code = 400 return _PostReturn() new_config = config.copy() new_config["BUG_TOOL_ENABLED"] = True with patch("couchers.servicers.bugs.config", new_config): with patch("couchers.servicers.bugs.requests.post", dud_post): with pytest.raises(grpc.RpcError) as e: res = bugs.ReportBug( bugs_pb2.ReportBugReq( subject="subject", description="description", results="results", frontend_version="frontend_version", user_agent="user_agent", page="page", user_id=99, )) assert e.value.code() == grpc.StatusCode.INTERNAL
def test_bugs_disabled(): with bugs_session() as bugs, pytest.raises(grpc.RpcError) as e: bugs.ReportBug( bugs_pb2.ReportBugReq( subject="subject", description="description", results="results", frontend_version="frontend_version", user_agent="user_agent", page="page", user_id=99, )) assert e.value.code() == grpc.StatusCode.UNAVAILABLE
def test_bugs_with_user(db): user, token = generate_user(username="******") with bugs_session() as bugs: def dud_post(url, auth, json): assert url == "https://api.github.com/repos/org/repo/issues" assert auth == ("user", "token") assert json == { "title": "subject", "body": ("Subject: subject\nDescription:\ndescription\n\nResults:\nresults\n\nBackend version: " + config["VERSION"] + "\nFrontend version: frontend_version\nUser Agent: user_agent\nPage: page\nUser (spoofable): testing_user (1)" ), "labels": ["bug tool"], } class _PostReturn: status_code = 201 def json(self): return {"number": 11} return _PostReturn() new_config = config.copy() new_config["BUG_TOOL_ENABLED"] = True with patch("couchers.servicers.bugs.config", new_config): with patch("couchers.servicers.bugs.requests.post", dud_post): res = bugs.ReportBug( bugs_pb2.ReportBugReq( subject="subject", description="description", results="results", frontend_version="frontend_version", user_agent="user_agent", page="page", user_id=user.id, )) assert res.bug_id == "#11" assert res.bug_url == "https://github.com/org/repo/issues/11"