def test_get_ancestors(self, *args): from nefertari.resource import Resource m = Resource(self.config) self.assertEqual([], m.ancestors) gr = m.add('grandpa', 'grandpas', view=get_test_view_class()) pa = m.add('parent', 'parents', parent=gr, view=get_test_view_class()) ch = m.add('child', 'children', parent=pa, view=get_test_view_class()) self.assertListEqual([gr, pa], ch.ancestors)
def test_get_ancestors(self, *args): from nefertari.resource import Resource m = Resource(self.config) self.assertEqual([], m.ancestors) gr = m.add('grandpa', 'grandpas', view=get_test_view_class()) pa = m.add('parent', 'parents', parent=gr, view=get_test_view_class()) ch = m.add('child', 'children', parent=pa, view=get_test_view_class()) self.assertListEqual([gr, pa], ch.ancestors)
def test_add_resource_routes_with_parent_param(self, *arg): from nefertari.resource import Resource View = get_test_view_class() m_add_resource_routes = arg[0] m = Resource(self.config) g = m.add('grandpa', 'grandpas', view=View) m.add('parent', 'parents', parent='grandpa', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'parent', 'parents', factory=None, auth=False, http_cache=0, path_prefix='grandpas/{grandpa_id}', name_prefix='grandpa:', renderer='nefertari_json', ) gm = m.add('grandma', 'grandmas', view=View) pa = m.add('parent', 'parents', parent=gm, view=View) m_add_resource_routes.assert_called_with( self.config, View, 'parent', 'parents', factory=None, auth=False, http_cache=0, path_prefix='grandmas/{grandma_id}', name_prefix='grandma:', renderer=View._default_renderer, ) pa.add('child', 'children', parent='grandpa:parent', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'child', 'children', factory=None, auth=False, http_cache=0, path_prefix='grandpas/{grandpa_id}/parents/{parent_id}', name_prefix='grandpa_parent:', renderer=View._default_renderer )
def test_resource_uid(self, *arg): from nefertari.resource import Resource m = Resource(self.config) self.assertEqual(m.uid, '') a = m.add('a', 'aa', view=get_test_view_class()) self.assertEqual('a', a.uid) c = a.add('b', 'bb', view=get_test_view_class()).add( 'c', 'cc', view=get_test_view_class()) self.assertEqual('a:b:c', c.uid)
def test_resource_uid(self, *arg): from nefertari.resource import Resource m = Resource(self.config) self.assertEqual(m.uid, '') a = m.add('a', 'aa', view=get_test_view_class()) self.assertEqual('a', a.uid) c = a.add('b', 'bb', view=get_test_view_class()).add( 'c', 'cc', view=get_test_view_class()) self.assertEqual('a:b:c', c.uid)
def test_add_resource_routes(self, *arg): from nefertari.resource import Resource View = get_test_view_class() m_add_resource_routes = arg[0] m = Resource(self.config) g = m.add('grandpa', 'grandpas', view=View) m_add_resource_routes.assert_called_once_with( self.config, View, 'grandpa', 'grandpas', factory=None, http_cache=0, auth=False, renderer=View._default_renderer, path_prefix='' ) pr = g.add('parent', 'parents', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'parent', 'parents', factory=None, http_cache=0, auth=False, path_prefix='grandpas/{grandpa_id}', name_prefix='grandpa:', renderer=View._default_renderer ) ch = pr.add('child', 'children', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'child', 'children', factory=None, http_cache=0, auth=False, path_prefix='grandpas/{grandpa_id}/parents/{parent_id}', name_prefix='grandpa_parent:', renderer=View._default_renderer ) self.assertEqual(ch.uid, 'grandpa:parent:child')
def test_add_resource_routes(self, *arg): from nefertari.resource import Resource View = get_test_view_class() m_add_resource_routes = arg[0] m = Resource(self.config) g = m.add('grandpa', 'grandpas', view=View) m_add_resource_routes.assert_called_once_with( self.config, View, 'grandpa', 'grandpas', factory=None, http_cache=0, auth=False, renderer=View._default_renderer, path_prefix='' ) pr = g.add('parent', 'parents', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'parent', 'parents', factory=None, http_cache=0, auth=False, path_prefix='grandpas/{grandpa_id}', name_prefix='grandpa:', renderer=View._default_renderer ) ch = pr.add('child', 'children', view=View) m_add_resource_routes.assert_called_with( self.config, View, 'child', 'children', factory=None, http_cache=0, auth=False, path_prefix='grandpas/{grandpa_id}/parents/{parent_id}', name_prefix='grandpa_parent:', renderer=View._default_renderer ) self.assertEqual(ch.uid, 'grandpa:parent:child')