예제 #1
0
    def test_basic_resources(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(self.config, DummyCrudView, 'message', 'messages')

        self.assertEqual('/messages',
                         route_path('messages', testing.DummyRequest()))
        self.assertEqual('/messages/1',
                         route_path('message', testing.DummyRequest(), id=1))
예제 #2
0
 def test_get_collection_nefertari_json(self):
     from nefertari.resource import add_resource_routes
     add_resource_routes(self.config,
                         DummyCrudRenderedView,
                         'message',
                         'messages',
                         renderer='nefertari_json')
     self.assertEqual(self.app.get('/messages').body, six.b('"index"'))
예제 #3
0
 def test_get_collection_nefertari_json(self):
     from nefertari.resource import add_resource_routes
     add_resource_routes(
         self.config,
         DummyCrudView,
         'message',
         'messages',
         renderer='nefertari_json'
     )
     self.assertEqual(self.app.get('/messages').body, '"index"')
예제 #4
0
 def test_get_collection_nefertari_json(self, mock_trigger):
     from nefertari.resource import add_resource_routes
     mock_trigger.side_effect = lambda x, y: x
     add_resource_routes(
         self.config,
         DummyCrudRenderedView,
         'message',
         'messages',
         renderer='nefertari_json'
     )
     self.assertEqual(self.app.get('/messages').body, six.b('"index"'))
예제 #5
0
    def test_resources_with_name_prefix(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(self.config,
                            DummyCrudView,
                            'message',
                            'messages',
                            name_prefix="special_")

        self.assertEqual(
            '/messages/1',
            route_path('special_message', testing.DummyRequest(), id=1))
예제 #6
0
    def test_basic_resources(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(self.config, DummyCrudView, 'message', 'messages')

        self.assertEqual(
            '/messages',
            route_path('messages', testing.DummyRequest())
        )
        self.assertEqual(
            '/messages/1',
            route_path('message', testing.DummyRequest(), id=1)
        )
예제 #7
0
    def test_resources_with_name_prefix_from_config(self):
        from nefertari.resource import add_resource_routes
        self.config.route_prefix = 'api'
        add_resource_routes(self.config,
                            DummyCrudView,
                            'message',
                            'messages',
                            name_prefix='foo_')

        self.assertEqual(
            '/api/messages/1',
            route_path('api_foo_message', testing.DummyRequest(), id=1))
예제 #8
0
    def test_resources_with_name_prefix(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(
            self.config,
            DummyCrudView,
            'message',
            'messages',
            name_prefix="special_"
        )

        self.assertEqual(
            '/messages/1',
            route_path('special_message', testing.DummyRequest(), id=1)
        )
예제 #9
0
 def setUp(self):
     from nefertari.resource import add_resource_routes
     self.config = _create_config()
     add_resource_routes(self.config,
                         DummyCrudRenderedView,
                         'message',
                         'messages',
                         renderer='string')
     self.config.begin()
     self.app = TestApp(self.config.make_wsgi_app())
     self.collection_path = '/messages'
     self.collection_name = 'messages'
     self.member_path = '/messages/{id}'
     self.member_name = 'message'
예제 #10
0
    def test_resources_with_path_prefix_with_trailing_slash(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(self.config,
                            DummyCrudView,
                            'message',
                            'messages',
                            path_prefix='/category/{category_id}/')

        self.assertEqual(
            '/category/2/messages',
            route_path('messages', testing.DummyRequest(), category_id=2))
        self.assertEqual(
            '/category/2/messages/1',
            route_path('message', testing.DummyRequest(), id=1, category_id=2))
예제 #11
0
    def test_resources_with_name_prefix_from_config(self):
        from nefertari.resource import add_resource_routes
        self.config.route_prefix = 'api'
        add_resource_routes(
            self.config,
            DummyCrudView,
            'message',
            'messages',
            name_prefix='foo_'
        )

        self.assertEqual(
            '/api/messages/1',
            route_path('api_foo_message', testing.DummyRequest(), id=1)
        )
예제 #12
0
 def setUp(self):
     from nefertari.resource import add_resource_routes
     self.config = _create_config()
     add_resource_routes(
         self.config,
         DummyCrudView,
         'message',
         'messages',
         renderer='string'
     )
     self.config.begin()
     self.app = TestApp(self.config.make_wsgi_app())
     self.collection_path = '/messages'
     self.collection_name = 'messages'
     self.member_path = '/messages/{id}'
     self.member_name = 'message'
예제 #13
0
    def test_resources_with_path_prefix_with_trailing_slash(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(
            self.config,
            DummyCrudView,
            'message',
            'messages',
            path_prefix='/category/{category_id}/'
        )

        self.assertEqual(
            '/category/2/messages',
            route_path('messages', testing.DummyRequest(), category_id=2)
        )
        self.assertEqual(
            '/category/2/messages/1',
            route_path('message', testing.DummyRequest(), id=1, category_id=2)
        )
예제 #14
0
 def test_get_collection_no_renderer(self):
     from nefertari.resource import add_resource_routes
     add_resource_routes(
         self.config, DummyCrudRenderedView, 'message', 'messages')
     self.assertRaises(ValueError, self.app.get, '/messages')
예제 #15
0
 def test_get_collection_no_renderer(self):
     from nefertari.resource import add_resource_routes
     add_resource_routes(self.config, DummyCrudView, 'message', 'messages')
     self.assertRaises(ValueError, self.app.get, '/messages')