コード例 #1
0
ファイル: test_agentspy.py プロジェクト: withshubh/treq
    def test_provides_iagent(self):
        """
        The agent returned by agent_spy() provides the IAgent interface.
        """
        agent, _ = agent_spy()

        self.assertTrue(IAgent.providedBy(agent))
コード例 #2
0
ファイル: test_fake_connection.py プロジェクト: jerith/txfake
 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")
コード例 #3
0
ファイル: test_fake_connection.py プロジェクト: jerith/txfake
 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")
コード例 #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")
コード例 #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")
コード例 #6
0
ファイル: test_fake_connection.py プロジェクト: jerith/txfake
 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")
コード例 #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=']})
        )
コード例 #8
0
ファイル: test_fake_connection.py プロジェクト: jerith/txfake
 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")