Пример #1
0
    def test_async_response(self):
        """
        FakeHttpServer supports asynchronous responses.
        """
        requests = []
        fake_http = FakeHttpServer(
            lambda req: requests.append(req) or NOT_DONE_YET)
        response1_d = fake_http.get_agent().request(
            "GET", b"http://example.com/hello/1")
        response2_d = fake_http.get_agent().request(
            "HEAD", b"http://example.com/hello/2")

        # Wait for the requests to arrive.
        yield wait0()
        [request1, request2] = requests
        self.assertNoResult(response1_d)
        self.assertNoResult(response2_d)
        self.assertEqual(request1.method, "GET")
        self.assertEqual(request1.path, b"http://example.com/hello/1")
        self.assertEqual(request2.method, "HEAD")
        self.assertEqual(request2.path, b"http://example.com/hello/2")

        # Send a response to the second request.
        request2.finish()
        response2 = yield response2_d
        self.assertNoResult(response1_d)
        yield self.assert_response(response2, 200, "")

        # Send a response to the first request.
        request1.write("Thank you for waiting.")
        request1.finish()
        response1 = yield response1_d
        yield self.assert_response(response1, 200, "Thank you for waiting.")
Пример #2
0
    def test_async_response(self):
        """
        FakeHttpServer supports asynchronous responses.
        """
        requests = []
        fake_http = FakeHttpServer(
            lambda req: requests.append(req) or NOT_DONE_YET)
        response1_d = fake_http.get_agent().request(
            "GET", b"http://example.com/hello/1")
        response2_d = fake_http.get_agent().request(
            "HEAD", b"http://example.com/hello/2")

        # Wait for the requests to arrive.
        yield wait0()
        [request1, request2] = requests
        self.assertNoResult(response1_d)
        self.assertNoResult(response2_d)
        self.assertEqual(request1.method, "GET")
        self.assertEqual(request1.path, b"http://example.com/hello/1")
        self.assertEqual(request2.method, "HEAD")
        self.assertEqual(request2.path, b"http://example.com/hello/2")

        # Send a response to the second request.
        request2.finish()
        response2 = yield response2_d
        self.assertNoResult(response1_d)
        yield self.assert_response(response2, 200, "")

        # Send a response to the first request.
        request1.write("Thank you for waiting.")
        request1.finish()
        response1 = yield response1_d
        yield self.assert_response(response1, 200, "Thank you for waiting.")
Пример #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")
Пример #4
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")
Пример #5
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")
Пример #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")