Beispiel #1
0
 def test_unexisting_phase(self):
     handler = Handlers()
     with self.assertRaises(Exception) as cm:
         handler.handlers('foo')
     exception = cm.exception
     self.assertTrue(exception)
     pass
Beispiel #2
0
 def test_unexisting_phase(self):
     handler = Handlers()
     with self.assertRaises(Exception) as cm:
         handler.handlers('foo')
     exception = cm.exception
     self.assertTrue(exception)
     pass
Beispiel #3
0
    def test_add_remove_handler(self):
        handlers = Handlers()
        handlers.add_handler('request_send', _cb_request_send)
        self.assertTrue(handlers.handlers('request_send'))

        handlers.remove_handler('request_send')
        self.assertFalse(handlers.handlers('request_send'))
Beispiel #4
0
    def test_overwrite_handlers(self):
        request = Request('GET', 'http')
        handlers = Handlers()
        handlers.add_handler('request_send', lambda r: 1)
        resp = handlers.dispatch('request_send', request)
        self.assertEqual(resp, 1)

        handlers.add_handler('request_send', lambda r: 2)
        resp = handlers.dispatch('request_send', request)
        self.assertEqual(resp, 2)
Beispiel #5
0
    def test_add_remove_handler(self):
        handlers = Handlers()
        handlers.add_handler('request_send', _cb_request_send)
        self.assertTrue(handlers.handlers('request_send'))

        handlers.remove_handler('request_send')
        self.assertFalse(handlers.handlers('request_send'))
Beispiel #6
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')
Beispiel #7
0
    def test_overwrite_handlers(self):
        request = Request('GET', 'http')
        handlers = Handlers()
        handlers.add_handler('request_send', lambda r: 1)
        resp = handlers.dispatch('request_send', request)
        self.assertEqual(resp, 1)

        handlers.add_handler('request_send', lambda r: 2)
        resp = handlers.dispatch('request_send', request)
        self.assertEqual(resp, 2)
Beispiel #8
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')
Beispiel #9
0
 def test_execute_handler(self):
     request = Request('GET', 'http')
     handlers = Handlers()
     handlers.add_handler('request_send', _cb_request_send)
     resp = handlers.dispatch('request_send', request)
     self.assertIsInstance(resp, Response)
Beispiel #10
0
 def test_execute_handler(self):
     request = Request('GET', 'http')
     handlers = Handlers()
     handlers.add_handler('request_send', _cb_request_send)
     resp = handlers.dispatch('request_send', request)
     self.assertIsInstance(resp, Response)
Beispiel #11
0
 def test_simple_handler(self):
     handlers = Handlers()
     self.assertTrue(handlers)