Ejemplo n.º 1
0
    def test_post_and_get_are_different(self):
        req = HTTPRequest("/hello")
        resp_partial = functools.partial(HTTPResponse,
                buffer=StringIO("response value"))
        RequestCollection.add(req, resp_partial)

        AsyncHTTPStubClient().fetch("/hello", self.stop, method="POST")
        response = self.wait()
        self.assertEqual(response.code, 404)
Ejemplo n.º 2
0
    def test_post_and_get_are_different(self):
        req = HTTPRequest("/hello")
        resp_partial = functools.partial(HTTPResponse,
                                         buffer=StringIO("response value"))
        RequestCollection.add(req, resp_partial)

        AsyncHTTPStubClient().fetch("/hello", self.stop, method="POST")
        response = self.wait()
        self.assertEqual(response.code, 404)
Ejemplo n.º 3
0
 def test_fetch_string_converts_to_request_object(self):
     req = HTTPRequest("/hello")
     resp_partial = functools.partial(HTTPResponse,
             buffer=StringIO("response value"))
     RequestCollection.add(req, resp_partial)
     client = AsyncHTTPStubClient()
     client.fetch("/hello", self.stop)
     response = self.wait()
     self.assertEqual(response.code, 200)
     self.assertEqual(response.body, "response value")
Ejemplo n.º 4
0
 def test_fetch_string_converts_to_request_object(self):
     req = HTTPRequest("/hello")
     resp_partial = functools.partial(HTTPResponse,
                                      code=200,
                                      buffer=StringIO("response value"))
     RequestCollection.add(req, resp_partial)
     client = AsyncHTTPStubClient()
     client.fetch("/hello", self.stop)
     response = self.wait()
     self.assertEqual(response.code, 200)
     self.assertEqual(response.body, "response value")
Ejemplo n.º 5
0
 def test_return_with_body_json(self):
     st = stub("/hello").and_return(body_json={'name': 'somebody'})
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(json.loads(resp.body).get('name'), 'somebody')
Ejemplo n.º 6
0
 def test_stub_with_method(self):
     st = stub("/hello", method="POST").and_return(body="anything")
     resp_partial = RequestCollection.find(st.request)
     self.assertNotEqual(resp_partial, None)
Ejemplo n.º 7
0
 def test_no_return_args(self):
     st = stub("/hello").and_return()
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(resp.body, b'')
Ejemplo n.º 8
0
 def test_stub_with_method(self):
     st = stub("/hello", method="POST").and_return(body=b"anything")
     resp_partial = RequestCollection.find(st.request)
     self.assertNotEqual(resp_partial, None)
Ejemplo n.º 9
0
 def setUp(self):
     super(ClientTest, self).setUp()
     RequestCollection.reset()
Ejemplo n.º 10
0
 def test_add(self):
     req = HTTPRequest("/hello")
     RequestCollection.add(req, "response val")
     val = RequestCollection._requests["/hello"]["GET"][0]
     self.assertEqual(val, "response val")
Ejemplo n.º 11
0
 def test_reset(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     RequestCollection.reset()
     self.assertEqual(len(RequestCollection._requests), 0)
Ejemplo n.º 12
0
 def test_remove(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     RequestCollection.remove(req)
     val = RequestCollection.find(req)
     self.assertEqual(val, None)
Ejemplo n.º 13
0
 def test_add_with_absolute_url(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     val = RequestCollection._requests["/hello"]["GET"][0]
     self.assertEqual(val, "response val")
Ejemplo n.º 14
0
 def test_add(self):
     req = HTTPRequest("/hello")
     RequestCollection.add(req, "response val")
     val = RequestCollection._requests["/hello"]["GET"][0]
     self.assertEqual(val, "response val")
Ejemplo n.º 15
0
 def test_no_return_args(self):
     st = stub("/hello").and_return()
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(resp.body, '') 
Ejemplo n.º 16
0
 def test_set_response_code_in_stub(self):
     st = stub("/hello").and_return(code=418)
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(resp.code, 418)
Ejemplo n.º 17
0
 def test_add_with_absolute_url(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     val = RequestCollection._requests["/hello"]["GET"][0]
     self.assertEqual(val, "response val")
Ejemplo n.º 18
0
 def test_remove(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     RequestCollection.remove(req)
     val = RequestCollection.find(req)
     self.assertEqual(val, None)
Ejemplo n.º 19
0
 def test_reset(self):
     req = HTTPRequest("http://www.example.com:8000/hello")
     RequestCollection.add(req, "response val")
     RequestCollection.reset()
     self.assertEqual(len(RequestCollection._requests), 0)
Ejemplo n.º 20
0
 def test_stub_no_return_doesnt_add_to_collection(self):
     st = stub("/hello")
     self.assertNotEqual(st.request, None)
     resp_partial = RequestCollection.find(st.request)
     self.assertEqual(resp_partial, None)
Ejemplo n.º 21
0
 def test_no_body(self):
     st = stub("/hello").and_return(body=None)
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request, 200)
     self.assertEqual(resp.body, '') 
Ejemplo n.º 22
0
 def test_return_with_body_json(self):
     st = stub("/hello").and_return(body_json={'name': 'somebody'})
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(
         json.loads(resp.body.decode()).get('name'), 'somebody')
Ejemplo n.º 23
0
 def test_stub_no_return_doesnt_add_to_collection(self):
     st = stub("/hello")
     self.assertNotEqual(st.request, None)
     resp_partial = RequestCollection.find(st.request)
     self.assertEqual(resp_partial, None)
Ejemplo n.º 24
0
 def test_set_response_code_in_stub(self):
     st = stub("/hello").and_return(code=418)
     resp_partial = RequestCollection.find(st.request)
     resp = resp_partial(st.request)
     self.assertEqual(resp.code, 418)
Ejemplo n.º 25
0
 def setUp(self):
     super(ClientTest, self).setUp()
     RequestCollection.reset()