Skip to content

Commit

Permalink
test_rest_api
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev committed Jul 17, 2023
1 parent 5260ad6 commit d5c575a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ initAttrRef = function() {
var $select = $("select#attr_type");
$("option",$select).each(function() {
$(this).prop("disabled","");
if (v.indexOf("{$")!=0 && $.inArray($(this).prop("value"),["embed","recursive","remote"])>=0) {
if (v.indexOf("{$")!=0 && $.inArray($(this).prop("value"),["embed","recursive"])>=0) {
$(this).prop("disabled","disable");
}
});
Expand Down
12 changes: 10 additions & 2 deletions Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def get_meta_data(node):
data['getPath'] = '/'.join(node.getPhysicalPath())
return data


def get_rest_api_url(url):
if '/content' in url:
i = url.find('/content')+len('/content')
elif '://' in url:
i = url.find('://')+len('://')
i = i+url[i:].find('/')
return '%s/++rest_api%s'%(url[:i],url[i:])


class RestApiController(object):
"""
RestApiController
Expand All @@ -38,15 +48,13 @@ def __init__(self, context, TraversalRequest):
self.context = context
self.method = TraversalRequest['REQUEST_METHOD']
self.ids = copy.copy(TraversalRequest['path_to_handle'][1:])
print(self.ids)
while self.ids:
id = self.ids[0]
if id.startswith('uid:'):
context = context.getLinkObj('{$%s}'%id)
elif id not in context.getPhysicalPath():
context = getattr(self.context, id, None)
if context is None:
print(id,self.context)
break
self.context = context
self.ids.remove(id)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Product imports.
from tests.zms_test_util import *
from Products.zms import rest_api
from Products.zms import standard

# /Products/zms> python -m unittest discover -s unit_tests
Expand All @@ -20,6 +21,10 @@ def setUp(self):
self.context = standard.initZMS(folder, 'myzmsx', 'titlealt', 'title', self.lang, self.lang, folder.REQUEST)
print('[setUp] create %s'%self.temp_title)

def test_get_rest_api_url(self):
self.assertEqual("http://foo/++rest_api/bar",rest_api.get_rest_api_url("http://foo/bar"))
self.assertEqual("http://foo/content/++rest_api/bar",rest_api.get_rest_api_url("http://foo/content/bar"))

def test_zmsindex(self):
name = '++rest_api'
path_to_handle = [name, 'zmsindex']
Expand All @@ -37,7 +42,6 @@ def test_zmsindex(self):
self.assertTrue(isinstance(actual, list))
self.assertEqual( len(actual), 15)


def test_metaobj_manager(self):
name = '++rest_api'
path_to_handle = [name, 'metaobj_manager']
Expand All @@ -48,12 +52,11 @@ def test_metaobj_manager(self):
self.assertTrue(isinstance(actual, dict))
self.assertEqual( len(actual), 38)


def test_get(self):
count = 0
for document in self.context.getTreeNodes(MockHTTPRequest(), 'ZMSDocument'):
name = '++rest_api'
for path_to_handle in [list(document.getPhysicalPath()), [document.get_uid()]]:
for path_to_handle in [list(document.getPhysicalPath()), [name, document.get_uid()]]:
# multilingual
request = MockHTTPRequest({'REQUEST_METHOD':'GET','TraversalRequestNameStack':path_to_handle,'path_to_handle':path_to_handle})
print("path_to_handle", request.get('path_to_handle'))
Expand Down

0 comments on commit d5c575a

Please sign in to comment.