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))
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"'))
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"')
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"'))
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))
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) )
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))
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) )
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'
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))
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) )
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'
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) )
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')
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')