Skip to content

Commit

Permalink
implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev committed Jul 10, 2023
1 parent 9c2395a commit dca2b1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def equals(o, d):
return True

request = zmscontext.REQUEST
lang = request['lang']
lang = request.get('lang')
if request.get('btn') == 'BTN_SAVE':
align = zmscontext.attr('align')
# Save.
Expand Down
6 changes: 3 additions & 3 deletions Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def initZMS(self, id, titlealt, title, lang, manage_lang, REQUEST):

##### Add ZMS ####
from Products.zms import zms
zms.initZMS(homeElmnt, 'content', titlealt, title, lang, manage_lang, REQUEST)
zms.initContent(homeElmnt.content, 'content.default.zip', REQUEST)
content = zms.initZMS(homeElmnt, 'content', titlealt, title, lang, manage_lang, REQUEST)
zms.initContent(content, 'content.default.zip', REQUEST)

return "initZMS"
return content

security.declarePublic('getPRODUCT_HOME')
def getPRODUCT_HOME():
Expand Down
13 changes: 6 additions & 7 deletions tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

# /Products/zms> python -m unittest discover -s unit_tests
# /Products/zms> python -m unittest tests.test_rest_api.RestAPITest
Expand All @@ -18,14 +18,13 @@ class RestAPITest(ZMSTestCase):
def setUp(self):
folder = Folder('myzmsx')
folder.REQUEST = MockHTTPRequest({'lang':'eng','preview':'preview'})
zmscontext = zms.initZMS(folder, 'content', 'titlealt', 'title', 'eng', 'eng', folder.REQUEST)
self.context = zmscontext
self.context = standard.initZMS(folder, 'content', 'titlealt', 'title', 'eng', 'eng', folder.REQUEST)
print('[setUp] create %s'%self.temp_title)
self.folder = zmscontext.manage_addZMSCustom('ZMSFolder',{'title':self.temp_title,'titlealt':self.temp_title},zmscontext.REQUEST)

def test_tree(self):
request = MockHTTPRequest({'REQUEST_METHOD':'GET','TraversalRequestNameStack':[self.folder.id]})
folder = self.context.getChildNodes(MockHTTPRequest(),'ZMSFolder')[0]
request = MockHTTPRequest({'REQUEST_METHOD':'GET','TraversalRequestNameStack':[folder.id]})
name = '++rest_api'
actual = self.context.__bobo_traverse__(request, name)(request)
self.assertTrue(actual.find('"id": "e1"') > 0)
self.assertTrue(actual.find('"meta_id": "ZMSFolder"') > 0)
self.assertTrue(actual.find('"id": "%s"'%folder.id) > 0)
self.assertTrue(actual.find('"meta_id": "%s"'%folder.meta_id) > 0)
11 changes: 11 additions & 0 deletions tests/zms_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def writeInfo(self, s):
def writeError(self, s):
self.context.write(logging.ERROR,s)

class MockUser:

def __init__(self, id):
self.id = id

def getId(self):
return self.id

class MockHTTPResponse:

def __init__(self):
Expand All @@ -43,11 +51,14 @@ class MockHTTPRequest:
def __init__(self, d={}, other={}):
self.d = d
self.other = other
self.set('AUTHENTICATED_USER',MockUser("test"))
self.RESPONSE = MockHTTPResponse()

__getitem____roles = None
def __getitem__(self, k, v=None):
return self.get(k)

__setitem____roles = None
def __setitem__(self, k, v):
self.set(k,v)

Expand Down

0 comments on commit dca2b1b

Please sign in to comment.