Beispiel #1
0
 def test_raise_error_if_update_on_different_stream_id(self):
     """A Stream should not update on an event with different stream id"""
     stream = Stream(stream_id=1, headers={'method': 'GET'})
     new_event = DataReceived()
     new_event.stream_id = 2
     new_event.data = b''
     with self.assertRaises(DifferentStreamIdException):
         stream.update(new_event)
    def test_raise_error_on_non_existing_route(self):
        """If a route doesn't exist, should raise error"""
        router = Router(None)
        stream = Stream(1, {':path': 'x', ':method': 'GET'})

        # should raise a more specific error in the future
        with self.assertRaises(Exception):
            coroutine = router.handle_route(None, stream)
            k.run(coroutine)
    def test_get_existing_route(self):
        router = Router(None)

        async def f(req, res):
            assert req.stream.headers[':path'] == 'x'
            assert res.http is None

        router.register('GET', route='x', handler=f)

        stream = Stream(1, {':path': 'x', ':method': 'GET'})
        coroutine = router.handle_route(None, stream)
        k.run(coroutine)
    def test_parameterized_route(self):
        router = Router(None)

        async def f(req, res):
            self.assertIsNone(res.http)
            self.assertEqual(req.para['userId'], '123')
            self.assertEqual(req.para['name'], 'John')

        router.register('GET', route='user/{userId}/name/{name}', handler=f)

        stream = Stream(1, {':path': 'user/123/name/John', ':method': 'GET'})
        c = router.handle_route(None, stream)
        k.run(c)
Beispiel #5
0
    def test_raise_error_on_non_existing_route(self):
        """
		If a route doesn't exist and no default method is given,
		should raise error
		"""
        router = Router(None)
        stream = Stream(1, {':path': 'x', ':method': 'GET'})

        async def f():
            with self.assertRaises(RouteNotRegisteredException):
                await router.handle_route(None, stream)

        self.k.run(f())
Beispiel #6
0
 def test_finalize(self):
     """Should not update a finalized Stream"""
     stream = Stream(stream_id=1, headers={'method': 'GET'})
     stream.finalize()
     with self.assertRaises(Exception):
         new_event = DataReceived()
         new_event.stream_id = 2
         new_event.data = b''
         stream.update(new_event)
Beispiel #7
0
 def test_update_on_same_stream_id_and_finalize_correctly(self):
     stream = Stream(stream_id=1, headers={'method': 'GET'})
     new_event = DataReceived()
     new_event.stream_id = 1
     new_event.data = b'some data '
     stream.update(new_event)
     stream.update(new_event)
     stream.finalize()
     self.assertEqual(b'some data some data ', stream.data)
Beispiel #8
0
 def test_header_not_empty(self):
     """Stream should refuse to construct if the header is Falsy or not a dict"""
     with self.assertRaises(Exception):
         Stream(stream_id=1, headers={})