Exemplo n.º 1
0
    def test_provides_iagent(self):
        """
        The agent returned by agent_spy() provides the IAgent interface.
        """
        agent, _ = agent_spy()

        self.assertTrue(IAgent.providedBy(agent))
Exemplo n.º 2
0
 def test_XMYSTERY_request(self):
     """
     FakeHttpServer can handle a request with an arbitrary verb.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or b"hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("XMYSTERY", b"http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "XMYSTERY")
     self.assertEqual(request.path, b"http://example.com/hello")
     yield self.assert_response(response, 200, b"hi")
Exemplo n.º 3
0
 def test_XMYSTERY_request(self):
     """
     FakeHttpServer can handle a request with an arbitrary verb.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or b"hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("XMYSTERY", b"http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "XMYSTERY")
     self.assertEqual(request.path, b"http://example.com/hello")
     yield self.assert_response(response, 200, b"hi")
Exemplo n.º 4
0
 def test_PUT_request(self):
     """
     FakeHttpServer can handle a PUT request.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or "hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("PUT", "http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "PUT")
     self.assertEqual(request.path, "http://example.com/hello")
     yield self.assert_response(response, 200, "hi")
Exemplo n.º 5
0
 def test_PUT_request(self):
     """
     FakeHttpServer can handle a PUT request.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or "hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("PUT", "http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "PUT")
     self.assertEqual(request.path, "http://example.com/hello")
     yield self.assert_response(response, 200, "hi")
Exemplo n.º 6
0
 def test_simple_request(self):
     """
     FakeHttpServer can handle a simple HTTP request using the IAgent
     provider it supplies.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or b"hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("GET", b"http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "GET")
     self.assertEqual(request.path, b"http://example.com/hello")
     yield self.assert_response(response, 200, b"hi")
Exemplo n.º 7
0
    def test_add_basic_auth(self):
        """
        add_auth() wraps the given agent with one that adds an ``Authorization:
        Basic ...`` HTTP header that contains the given credentials.
        """
        agent, requests = agent_spy()
        authAgent = add_auth(agent, ('username', 'password'))

        authAgent.request(b'method', b'uri')

        self.assertTrue(IAgent.providedBy(authAgent))
        self.assertEqual(
            requests[0].headers,
            Headers({b'authorization': [b'Basic dXNlcm5hbWU6cGFzc3dvcmQ=']})
        )
Exemplo n.º 8
0
 def test_simple_request(self):
     """
     FakeHttpServer can handle a simple HTTP request using the IAgent
     provider it supplies.
     """
     requests = []
     fake_http = FakeHttpServer(lambda req: requests.append(req) or b"hi")
     agent = fake_http.get_agent()
     self.assertTrue(IAgent.providedBy(agent))
     response = yield agent.request("GET", b"http://example.com/hello")
     # We got a valid request and returned a valid response.
     [request] = requests
     self.assertEqual(request.method, "GET")
     self.assertEqual(request.path, b"http://example.com/hello")
     yield self.assert_response(response, 200, b"hi")