Skip to content

Commit

Permalink
test portal
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev committed Jul 8, 2024
1 parent bd7caf4 commit f8611d7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
43 changes: 43 additions & 0 deletions tests/test_zms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# encoding: utf-8

from OFS.Folder import Folder

# Product imports.
from tests.zms_test_util import *

# /Products/zms> python -m unittest discover -s unit_tests
# /Products/zms> python -m unittest test_zms.ZMSTest
class ZMSTest(ZMSPortalTestCase):

temp_title = 'temp-test'

def setUp(self):
super(ZMSTest, self).setUp()
print('[setUp] create %s'%self.temp_title)
zmscontext = self.context
clients = zmscontext.getPortalClients()
clients[0].manage_delObjects([clients[0].getCatalogAdapter().id])


def test_portal(self):
zmscontext = self.context
clients = zmscontext.getPortalClients()
self.assertEqual(3, len(clients))
for client in clients:
self.assertIsNotNone(client.getPortalMaster())

def test_zcatalog_adapter(self):
zmscontext = self.context
catalog_adapter = zmscontext.getCatalogAdapter()
self.assertIsNotNone(catalog_adapter)
# Clients have parent catalog-adapter.
clients = zmscontext.getPortalClients()
for i in range(len(clients)):
client = clients[i]
if i == 0:
self.assertEqual(catalog_adapter, client.getCatalogAdapter())
else:
self.assertNotEqual(catalog_adapter, client.getCatalogAdapter())

def tearDown(self):
print('[tearDown] remove %s'%self.temp_title)
11 changes: 4 additions & 7 deletions tests/test_zmscontainerobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

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

# /Products/zms> python -m unittest discover -s unit_tests
# /Products/zms> python -m unittest test_zmscontainerobject.ZMSContainerObjectTest
Expand All @@ -17,12 +15,11 @@ class ZMSContainerObjectTest(ZMSTestCase):
temp_title = 'temp-test'

def setUp(self):
folder = Folder('myzmsx')
folder.REQUEST = mock_http.MockHTTPRequest({'lang':'eng','preview':'preview'})
zmscontext = zms.initZMS(folder, 'content', 'titlealt', 'title', 'eng', 'eng', folder.REQUEST)
self.context = zmscontext
super(ZMSContainerObjectTest, self).setUp()
print('[setUp] create %s'%self.temp_title)
self.folder = zmscontext.manage_addZMSCustom('ZMSFolder',{'title':self.temp_title,'titlealt':self.temp_title},zmscontext.REQUEST)
zmscontext = self.context
request = zmscontext.REQUEST
self.folder = zmscontext.manage_addZMSCustom('ZMSFolder',{'title':self.temp_title,'titlealt':self.temp_title},request)

def test_tree(self):
context = self.context
Expand Down
21 changes: 21 additions & 0 deletions tests/zms_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ def writeInfo(self, s):
def writeError(self, s):
self.context.write(logging.ERROR,s)


class ZMSPortalTestCase(ZMSTestCase):

def setUp(self):
super(ZMSPortalTestCase, self).setUp()
zmscontext = self.context
request = zmscontext.REQUEST
home = zmscontext.aq_parent
ids = []
n = 3
for i in range(n):
id = 'client%i'%i
client = Folder(id)
setattr(client, home.id, home)
home._setObject(client.id, client)
client = getattr(home, client.id)
zmsclient = zms.initZMS(client, 'content', id, id, 'eng', 'eng', request)
zmsclient.setConfProperty('Portal.Master',home.id)
ids.append(id)
zmscontext.setConfProperty('Portal.Clients',ids)

def addClient(zmscontext, id):
"""
Add ZMS client.
Expand Down

0 comments on commit f8611d7

Please sign in to comment.