Skip to content

Commit

Permalink
super // test_zcatalog_adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
zmsdev committed Jun 10, 2024
1 parent 90c9049 commit 7f186f3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
53 changes: 23 additions & 30 deletions tests/test_zms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,40 @@

# 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_zms.ZMSTest
class ZMSTest(ZMSTestCase):
class ZMSTest(ZMSPortalTestCase):

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(ZMSTest, 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
clients = zmscontext.getPortalClients()
clients[0].manage_delObjects([clients[0].getCatalogAdapter().id])


def test_portal(self):
context = self.context
request = context.REQUEST

home = context.aq_parent
ids = []
clients = []
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)
zmscontext = zms.initZMS(client, 'content', id, id, 'eng', 'eng', request)
zmscontext.setConfProperty('Portal.Master',home.id)
ids.append(id)
clients.append(zmscontext)
context.setConfProperty('Portal.Clients',ids)
self.assertEqual(n,len(context.getPortalClients()))
zmscontext = self.context
clients = zmscontext.getPortalClients()
self.assertEqual(3, len(clients))
for client in clients:
self.assertIsNotNone(client.getPortalMaster())
def tearDown(self):

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)
zmscontext.manage_delObjects([self.folder.id])
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 7f186f3

Please sign in to comment.