コード例 #1
0
 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))
コード例 #2
0
 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)),
     )
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
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)
コード例 #6
0
    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))
コード例 #7
0
    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",
            },
        )
コード例 #8
0
 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())
コード例 #9
0
 def request(agent_id: int) -> Request:
     return Request(
         f"/rest/api/latest/agent/assignment?executorType=AGENT&executorId={ agent_id }"
     )
コード例 #10
0
 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,
     )
コード例 #11
0
 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,
     )
コード例 #12
0
 def request() -> Request:
     return Request("/rest/api/latest/agent/authentication?pending=true")
コード例 #13
0
 def request() -> Request:
     return Request("/rest/api/latest/agent/")
コード例 #14
0
 def request(agent_id: int) -> Request:
     return Request(f"/admin/agent/enableAgent.action?agentId={agent_id}",
                    method=Method.Post)
コード例 #15
0
 def request(uuid: str) -> Request:
     return Request(f"/rest/api/latest/agent/authentication/{uuid}",
                    method=Method.Put)
コード例 #16
0
 def request(etype: str) -> Request:
     return Request(
         f"/rest/api/latest/agent/assignment/search?searchTerm=&executorType=AGENT&entityType={ etype }",
     )
コード例 #17
0
 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)
コード例 #18
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)
コード例 #19
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)