예제 #1
0
    def test_update_route_and_change_its_id(self):
        router = Router()
        router.add_route({
            'id': 'id1',
            'path': '/endpoint\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        router.update_route({
            'id': 'id2',
            'path': '/endpoint\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        }, 'id1')
예제 #2
0
    def test_add_duplicate_route_raises_exception(self):
        router = Router()
        route = router.add_route({
            'id': 'id1',
            'path': '/endpoint_\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        with pytest.raises(DuplicateRouteError):
            route = router.add_route({
                'id': 'id1',
                'path': '/endpoint_\\w*',
                'responses': [
                    {
                        'id': 'response_1',
                        'body': {
                            'works': True
                        }
                    }
                ]
            })
예제 #3
0
    def test_update_route_to_that_already_exists(self):
        router = Router()
        router.add_route({
            'id': 'id1',
            'path': '/endpoint\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        router.add_route({
            'id': 'id2',
            'path': '/endpoint\\w*',
            'responses': [
                {
                    'id': 'response_2',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        with pytest.raises(DuplicateRouteError):
            router.update_route({
                'id': 'id1',
                'path': '/endpoint\\w*',
                'responses': [
                    {
                        'id': 'response_1',
                        'body': {
                            'works': True
                        }
                    }
                ]
            }, 'id2')
예제 #4
0
    def test_get_route(self):
        router = Router()
        route = router.add_route({
            'id': 'id1',
            'path': '/endpoint_\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        assert router.get_route('id1') is route
예제 #5
0
    def test_add_route(self):
        router = Router()
        route = router.add_route({
            'id': 'id1',
            'path': '/endpoint_\\w*',
            'responses': [
                {
                    'id': 'response_1',
                    'body': {
                        'works': True
                    }
                }
            ]
        })

        assert list(router.routes) == [route]
예제 #6
0
 def test_match_with_no_matching_route(self):
     router = Router()
     route = router.add_route({
         'id': 'id1',
         'path': '/endpoint\\w*',
         'responses': [
             {
                 'id': 'response_1',
                 'body': {
                     'works': True
                 }
             }
         ]
     })
     request = IncomingTestRequest(
         base_url='http://localhost/',
         full_path='/test',
         method='GET'
     )
     
     assert router.match(request) is None