Пример #1
0
    def test_static_route(self):
        def route_url(route_name, **kwargs):
            return '/' + route_name

        templater = api_config.AngularRouteTemplater(route_url, params=[])

        assert templater.route_template('foo') == '/foo'
Пример #2
0
    def test_route_with_id_placeholder(self):
        def route_url(route_name, **kwargs):
            return '/{}/{}'.format(route_name, kwargs['id'])

        templater = api_config.AngularRouteTemplater(route_url, params=['id'])

        assert templater.route_template('foo') == '/foo/:id'
Пример #3
0
    def test_custom_parameter(self):
        def route_url(_, **kwargs):
            return '/things/{}'.format(kwargs['thing_id'])

        templater = api_config.AngularRouteTemplater(route_url, params=['thing_id'])

        assert templater.route_template('foo') == '/things/:thing_id'
Пример #4
0
    def test_parameter_substrings(self):
        def route_url(_, **kwargs):
            return '/api/{}/things/{}'.format(kwargs['id'], kwargs['thing_id'])

        templater = api_config.AngularRouteTemplater(route_url,
                                                     params=['id', 'thing_id'])

        assert templater.route_template('foo') == '/api/:id/things/:thing_id'
Пример #5
0
    def test_multiple_parameters(self):
        def route_url(_, **kwargs):
            return '/{}/{}'.format(kwargs['foo'], kwargs['bar'])

        templater = api_config.AngularRouteTemplater(route_url,
                                                     params=['foo', 'bar'])

        assert templater.route_template('foo') == '/:foo/:bar'