def test_valid_response_codes(self): rh = MockRequestHandler( responses=[ Response(status_code=200), Response(status_code=200), Response(status_code=204), Response(status_code=204), ] ) agent = make_bamboo_agent(rh) agent.request(Request("/", method=Method.Get)) agent.request(Request("/", method=Method.Post)) agent.request(Request("/", method=Method.Delete)) agent.request(Request("/", method=Method.Put))
def test_allow_redirect(self): rh = MockRequestHandler( responses=[ Response(status_code=200), Response(status_code=302), Response(status_code=302), ] ) agent = make_bamboo_agent(rh) agent.request(Request("/", method=Method.Post), allow_redirect=True) agent.request(Request("/", method=Method.Post), allow_redirect=True) self.assertRaises( ServerCommunicationError, partial(agent.request, Request("/", method=Method.Post)), )
def test_returns_response(self): response = Response(content=b"[]") request = Request("/my/path") rh = MockRequestHandler(responses=[response]) agent = make_bamboo_agent(rh) self.assertEqual(agent.request(request), response) self.assert_requests(rh.requests, request)
def test_timeout(self): urlopen = MockUrlOpen() handler = HttpRequestHandler( "http://host/", auth=("", ""), timeout=0, urlopen=urlopen ) handler(Request("/my/path", method=Method.Put)) self.assertEqual(urlopen.timeout, 0)
def test_read_no_data(self): handler = HttpRequestHandler( "http://host/", auth=("", ""), timeout=0, urlopen=MockUrlOpen(status_code=204, content=b"[1, 2, 3]"), ) response = handler(Request("/my/path"), read=False) self.assertEqual(response.content, None) self.assertEqual(response.status_code, 204)
def do(self, method: Method): content_length = int(self.headers.get("Content-Length", 0)) self.Requests.append( Request( self.path, content=self.rfile.read(content_length), method=method, )) response = self.Responses.pop(0) response() self.send_response(response.status_code) for header, value in (response.header or {}).items(): self.send_header(header, value) self.end_headers() self.wfile.write(bytes(response))
def test_default_request(self): urlopen = MockUrlOpen() handler = HttpRequestHandler( "http://host/sub", urlopen=urlopen, auth=("user", "password"), timeout=0 ) handler(Request("/my/path")) self.assertEqual(urlopen.url, "http://host/sub/my/path") self.assertEqual(urlopen.method, "GET") self.assertEqual( urlopen.header, { "Authorization": "Basic dXNlcjpwYXNzd29yZA==", "X-atlassian-token": "no-check", }, )
def test_change_state(self): rh = MockRequestHandler(responses=[ActionResponse()]) agent = make_bamboo_agent(rh) agent.state.set("key", dict(sub="value")) agent.change(Request("/"), state_update=lambda s: s["key"].pop("sub")) self.assertEqual(agent.state["key"], dict())
def request(agent_id: int) -> Request: return Request( f"/rest/api/latest/agent/assignment?executorType=AGENT&executorId={ agent_id }" )
def request(agent_id: int, etype: str, eid: int) -> Request: return Request( f"/rest/api/latest/agent/assignment?executorType=AGENT&executorId={ agent_id }&assignmentType={ etype }&entityId={ eid }", method=Method.Delete, )
def request(agent_id: int, name: str) -> Request: return Request( f"/admin/agent/updateAgentDetails.action?agentId={ agent_id }&agentName={ name }&save=Update", method=Method.Post, )
def request() -> Request: return Request("/rest/api/latest/agent/authentication?pending=true")
def request() -> Request: return Request("/rest/api/latest/agent/")
def request(agent_id: int) -> Request: return Request(f"/admin/agent/enableAgent.action?agentId={agent_id}", method=Method.Post)
def request(uuid: str) -> Request: return Request(f"/rest/api/latest/agent/authentication/{uuid}", method=Method.Put)
def request(etype: str) -> Request: return Request( f"/rest/api/latest/agent/assignment/search?searchTerm=&executorType=AGENT&entityType={ etype }", )
def test_timeout(self): rh = MockRequestHandler(responses=[Response(status_code=200)]) agent = make_bamboo_agent(rh, http_timeout=0) agent.request(Request("/")) self.assertEqual(rh.timeout, 0)
def test_suppress_change_in_check_mode(self): rh = MockRequestHandler() agent = make_bamboo_agent(rh, check_mode=True) agent.change(Request("/"), state_update=None) self.assertEqual(len(rh.requests), 0)
def test_forward_request(self): request = Request("/my/path") rh = MockRequestHandler(responses=[Response()]) agent = make_bamboo_agent(rh) agent.change(request, state_update=None) self.assert_requests(rh.requests, request)