Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev committed Jul 20, 2023
1 parent 5fe8237 commit 3318f01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_attrs(node, langs, monolang, REQUEST):
data['is_page'] = node.isPage()
data['is_page_element'] = node.isPageElement()
data['index_html'] = node.getHref2IndexHtmlInContext(node,REQUEST=REQUEST)
data['parent_uid'] = node.breadcrumbs_obj_path()[-2] if len(node.breadcrumbs_obj_path()) > 1 else None
data['parent_uid'] = node.breadcrumbs_obj_path()[-2].get_uid() if len(node.breadcrumbs_obj_path()) > 1 else None
data['home_id'] = node.getHome().id
data['level'] = node.getLevel()
data['restricted'] = node.hasRestrictedAccess()
Expand Down Expand Up @@ -135,13 +135,21 @@ def __call__(self, REQUEST=None, **kw):
langs = context.getLangIds()
monolang = self.ids and self.ids[0] in langs
langs = self.ids if monolang else langs
if self.ids == ['list_child_nodes']:
if self.ids == ['list_parent_nodes']:
id_prefix = REQUEST.get('id_prefix','e')
nodes = context.breadcrumbs_obj_path()
data = [get_meta_data(x) for x in nodes]
elif self.ids == ['list_child_nodes']:
id_prefix = REQUEST.get('id_prefix','e')
nodes = context.getObjChildren(id_prefix,REQUEST)
data = [get_meta_data(x) for x in nodes]
elif self.ids == ['list_tree_nodes']:
nodes = context.getTreeNodes(REQUEST)
data = [get_meta_data(x) for x in nodes]
elif self.ids == ['get_parent_nodes']:
id_prefix = REQUEST.get('id_prefix','e')
nodes = context.breadcrumbs_obj_path()
data = [get_attrs(x, langs, monolang, REQUEST) for x in nodes]
elif self.ids == ['get_child_nodes']:
id_prefix = REQUEST.get('id_prefix','e')
nodes = context.getObjChildren(id_prefix,REQUEST)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def test_get(self):
self.assertEqual( actual['meta_id'], 'ZMSDocument')
self.assertTrue( 'title' in actual)
self.assertFalse( 'title_%s'%self.lang in actual)
# list_parent_nodes
request = MockHTTPRequest({'REQUEST_METHOD':'GET','TraversalRequestNameStack':path_to_handle+['list_child_nodes'],'path_to_handle':path_to_handle+['list_parent_nodes']})
print("path_to_handle", request.get('path_to_handle'))
actual = json.loads( self.context.__bobo_traverse__(request, name)(request))
print(json.dumps(actual))
self.assertEqual( len(actual), len(document.breadcrumbs_obj_path()))
# list_child_nodes
request = MockHTTPRequest({'REQUEST_METHOD':'GET','TraversalRequestNameStack':path_to_handle+['list_child_nodes'],'path_to_handle':path_to_handle+['list_child_nodes']})
print("path_to_handle", request.get('path_to_handle'))
Expand Down

0 comments on commit 3318f01

Please sign in to comment.