Example #1
0
    def _test_request(self, method):
        client = Client()
        client.add_handler('request_send', _test_cb)

        request = Request(method, tests[method]['url'], tests[method]['headers'])

        if 'content' in tests[method]:
            request.content = tests[method]['content']

        resp = client.request(request)

        self.assertTrue(resp)
        self.assertEqual(resp.status, 204)
Example #2
0
    def test_prepare(self):
        request = Request('FOO', 'http')
        client = Client()
        client.add_handler('request_prepare', _cb_request_prepare)

        resp = client.request(request)
        self.assertEqual(resp.status, 400)

        handlers = Handlers()
        handlers.add_handler('request_prepare', _cb_request_prepare_change_request)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'PUT')

        handlers = Handlers()
        handlers.add_handler('request_prepare', _cb_request_prepare_do_nothing)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'FOO')
        self.assertEqual(req.url, 'http')
Example #3
0
    def test_prepare(self):
        request = Request('FOO', 'http')
        client = Client()
        client.add_handler('request_prepare', _cb_request_prepare)

        resp = client.request(request)
        self.assertEqual(resp.status, 400)

        handlers = Handlers()
        handlers.add_handler('request_prepare',
                             _cb_request_prepare_change_request)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'PUT')

        handlers = Handlers()
        handlers.add_handler('request_prepare', _cb_request_prepare_do_nothing)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'FOO')
        self.assertEqual(req.url, 'http')
Example #4
0
 def test_response(self):
     request = Request('GET', 'http')
     client = Client()
     client.add_handler('request_send', _cb_request_send)
     #client.add_handler('response_done', _cb_response_done)
     resp = client.request(request)
Example #5
0
 def test_response(self):
     request = Request('GET', 'http')
     client = Client()
     client.add_handler('request_send', _cb_request_send)
     #client.add_handler('response_done', _cb_response_done)
     resp = client.request(request)
Example #6
0
 def test_headers(self):
     client = Client()
     self.assertTrue(client.default_headers.get('Connection'))
     self.assertEqual(client.default_headers.get('User-Agent'), 'python-fluffyhttp')
Example #7
0
 def test_base(self):
     client = Client()
     self.assertTrue(client)
     self.assertEqual(client.agent, 'python-fluffyhttp')
     client = Client(agent='foo')
     self.assertEqual(client.agent, 'foo')