From f8611d7f3ee7baf906bc9dd3842404b84346d947 Mon Sep 17 00:00:00 2001 From: zmsdev Date: Fri, 7 Jun 2024 14:16:59 +0200 Subject: [PATCH] test portal --- tests/test_zms.py | 43 ++++++++++++++++++++++++++++++++ tests/test_zmscontainerobject.py | 11 +++----- tests/zms_test_util.py | 21 ++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 tests/test_zms.py diff --git a/tests/test_zms.py b/tests/test_zms.py new file mode 100644 index 000000000..f9a3b8c16 --- /dev/null +++ b/tests/test_zms.py @@ -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) diff --git a/tests/test_zmscontainerobject.py b/tests/test_zmscontainerobject.py index b78489775..8c628263e 100644 --- a/tests/test_zmscontainerobject.py +++ b/tests/test_zmscontainerobject.py @@ -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 @@ -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 diff --git a/tests/zms_test_util.py b/tests/zms_test_util.py index 895ae72b6..982e3bddd 100644 --- a/tests/zms_test_util.py +++ b/tests/zms_test_util.py @@ -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.