From 12b4faceed026e53899c9c9312a4842e15264f9a Mon Sep 17 00:00:00 2001 From: zmsdev Date: Fri, 7 Jun 2024 14:16:59 +0200 Subject: [PATCH 1/5] 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. From 175ca1f55713563ab369500f300f35a71b1447fd Mon Sep 17 00:00:00 2001 From: zmsdev Date: Mon, 8 Jul 2024 19:40:41 +0200 Subject: [PATCH 2/5] tests --- tests/test_standard.py | 12 ++++++++++++ tests/test_zms.py | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_standard.py b/tests/test_standard.py index b0e037f9c..1a3bd98fa 100644 --- a/tests/test_standard.py +++ b/tests/test_standard.py @@ -100,3 +100,15 @@ def test_httpimport(self): url = "http://foo/bar?john=doe" v = standard.http_import(context,url) + def test_date_api(self): + from DateTime.DateTime import DateTime + context = None + lang = 'eng' + self.assertEquals('2024-01-01T12:00:00+01:00',standard.format_datetime_iso((2024,1,1,12,0,0,0,0,0))) + self.assertEquals(DateTime('2024/01/01 00:00:00 GMT+1'),standard.getLangFmtDate(context,(2024,1,1,12,0,0,0,0,0),lang,'DateTime')) + self.assertEquals(35, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) + self.assertEquals(0, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) + self.assertEquals(-50, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) + self.assertEquals(1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) + self.assertEquals(0, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) + self.assertEquals(-1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) diff --git a/tests/test_zms.py b/tests/test_zms.py index f9a3b8c16..360fbb885 100644 --- a/tests/test_zms.py +++ b/tests/test_zms.py @@ -39,5 +39,26 @@ def test_zcatalog_adapter(self): else: self.assertNotEqual(catalog_adapter, client.getCatalogAdapter()) + def test_metaobj_manager(self): + zmscontext = self.context + metaobj_manager = zmscontext.getMetaobjManager() + self.assertIsNotNone(metaobj_manager) + clients = zmscontext.getPortalClients() + for i in range(len(clients)): + client = clients[i] + self.assertEqual(metaobj_manager.getMetaobjIds(), client.getMetaobjManager().getMetaobjIds()) + + def test_conf_properties(self): + zmscontext = self.context + clients = zmscontext.getPortalClients() + for i in range(len(clients)): + client = clients[i] + self.assertIsNone(client.getConfProperty('foo')) + zmscontext.setConfProperty('foo','bar') + self.assertEqual('bar', client.getConfProperty('foo')) + zmscontext.delConfProperty('foo') + self.assertIsNone(client.getConfProperty('foo')) + + def tearDown(self): print('[tearDown] remove %s'%self.temp_title) From 0b00ef7e41123f48dfe47a89a826a28e1fc5b2a6 Mon Sep 17 00:00:00 2001 From: zmsdev Date: Mon, 8 Jul 2024 21:05:03 +0200 Subject: [PATCH 3/5] removed asserts --- tests/test_standard.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_standard.py b/tests/test_standard.py index 1a3bd98fa..11b585475 100644 --- a/tests/test_standard.py +++ b/tests/test_standard.py @@ -102,10 +102,6 @@ def test_httpimport(self): def test_date_api(self): from DateTime.DateTime import DateTime - context = None - lang = 'eng' - self.assertEquals('2024-01-01T12:00:00+01:00',standard.format_datetime_iso((2024,1,1,12,0,0,0,0,0))) - self.assertEquals(DateTime('2024/01/01 00:00:00 GMT+1'),standard.getLangFmtDate(context,(2024,1,1,12,0,0,0,0,0),lang,'DateTime')) self.assertEquals(35, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) self.assertEquals(0, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) self.assertEquals(-50, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) From 47fb609696bc794ca28cc294b913580c7376c957 Mon Sep 17 00:00:00 2001 From: zmsdev Date: Tue, 9 Jul 2024 20:05:15 +0200 Subject: [PATCH 4/5] add tests --- .../zms/zpt/ZMSRecordSet/input_fields.zpt | 2 +- Products/zms/zpt/ZMSRecordSet/main_grid.zpt | 6 ++--- .../zms/zpt/ZMSSqlDb/zmi_lazy_select_form.zpt | 2 +- Products/zms/zpt/objattrs/f_select_file.zpt | 6 ++--- Products/zms/zpt/objattrs/f_select_image.zpt | 6 ++--- tests/test_standard.py | 26 +++++++++++++++++++ 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Products/zms/zpt/ZMSRecordSet/input_fields.zpt b/Products/zms/zpt/ZMSRecordSet/input_fields.zpt index 58934f6e9..5b2481750 100644 --- a/Products/zms/zpt/ZMSRecordSet/input_fields.zpt +++ b/Products/zms/zpt/ZMSRecordSet/input_fields.zpt @@ -67,7 +67,7 @@ python:here.getObjAttrInput(fmName='form0',obj_attr=here.getObjAttr(elName),value=elValue,REQUEST=request)"> the control - + diff --git a/Products/zms/zpt/ZMSRecordSet/main_grid.zpt b/Products/zms/zpt/ZMSRecordSet/main_grid.zpt index a7be723b0..b8fbfe97f 100644 --- a/Products/zms/zpt/ZMSRecordSet/main_grid.zpt +++ b/Products/zms/zpt/ZMSRecordSet/main_grid.zpt @@ -186,17 +186,17 @@ > + > filenamefilenameelValue
-
+
-
+
the filename the size diff --git a/Products/zms/zpt/objattrs/f_select_image.zpt b/Products/zms/zpt/objattrs/f_select_image.zpt index 2e7de382e..94582b8cf 100644 --- a/Products/zms/zpt/objattrs/f_select_image.zpt +++ b/Products/zms/zpt/objattrs/f_select_image.zpt @@ -73,7 +73,7 @@
- +
@@ -171,7 +171,7 @@
- +
the filename the dimensions diff --git a/tests/test_standard.py b/tests/test_standard.py index 11b585475..c1f04f0b9 100644 --- a/tests/test_standard.py +++ b/tests/test_standard.py @@ -108,3 +108,29 @@ def test_date_api(self): self.assertEquals(1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) self.assertEquals(0, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) self.assertEquals(-1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) + + def test_operator_api(self): + self.assertEquals(int, standard.operator_gettype(1)) + self.assertEquals(str, standard.operator_gettype('foo')) + self.assertEquals(str, standard.operator_gettype(u'foo')) + d = {'john':'doe'} + self.assertFalse('foo' in d) + self.assertIsNone(d.get('foo')) + standard.operator_setitem(d, 'foo', 'bar') + self.assertTrue('foo' in d) + self.assertEquals('bar', d.get('foo')) + self.assertEquals('bar', standard.operator_getitem(d, 'foo')) + self.assertEquals('bar', standard.operator_getitem(d, 'Foo')) + self.assertEquals('bar', standard.operator_getitem(d, 'FOO')) + standard.operator_delitem(d, 'foo') + self.assertFalse('foo' in d) + self.assertIsNone(d.get('foo')) + + def test_mappings_api(self): + l1 = ['A', 'B', 'B', 'C'] + l2 = ['C', 'D'] + self.assertListEqual(['C'], standard.intersection_list(l1, l2)) + self.assertListEqual(['A', 'B', 'B'], standard.difference_list(l1, l2)) + self.assertListEqual(['A', 'B', 'B', 'C', 'D'], standard.concat_list(l1, l2)) + self.assertDictEqual({'A':'B','B':'C'}, standard.dict_list(l1)) + self.assertListEqual(['A', 'B', 'C'], standard.distinct_list(l1)) From bf73fbbc5042d6db290e8fc7fb995b336ae70713 Mon Sep 17 00:00:00 2001 From: zmsdev Date: Tue, 9 Jul 2024 20:11:02 +0200 Subject: [PATCH 5/5] assertEqual --- tests/test_standard.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_standard.py b/tests/test_standard.py index c1f04f0b9..d2b059d00 100644 --- a/tests/test_standard.py +++ b/tests/test_standard.py @@ -102,26 +102,26 @@ def test_httpimport(self): def test_date_api(self): from DateTime.DateTime import DateTime - self.assertEquals(35, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) - self.assertEquals(0, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) - self.assertEquals(-50, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) - self.assertEquals(1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) - self.assertEquals(0, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) - self.assertEquals(-1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) + self.assertEqual(35, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) + self.assertEqual(0, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) + self.assertEqual(-50, standard.daysBetween((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) + self.assertEqual(1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,2,5,12,0,0,0,0,0))) + self.assertEqual(0, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2024,1,1,12,0,0,0,0,0))) + self.assertEqual(-1, standard.compareDate((2024,1,1,12,0,0,0,0,0), (2023,11,12,12,0,0,0,0,0))) def test_operator_api(self): - self.assertEquals(int, standard.operator_gettype(1)) - self.assertEquals(str, standard.operator_gettype('foo')) - self.assertEquals(str, standard.operator_gettype(u'foo')) + self.assertEqual(int, standard.operator_gettype(1)) + self.assertEqual(str, standard.operator_gettype('foo')) + self.assertEqual(str, standard.operator_gettype(u'foo')) d = {'john':'doe'} self.assertFalse('foo' in d) self.assertIsNone(d.get('foo')) standard.operator_setitem(d, 'foo', 'bar') self.assertTrue('foo' in d) - self.assertEquals('bar', d.get('foo')) - self.assertEquals('bar', standard.operator_getitem(d, 'foo')) - self.assertEquals('bar', standard.operator_getitem(d, 'Foo')) - self.assertEquals('bar', standard.operator_getitem(d, 'FOO')) + self.assertEqual('bar', d.get('foo')) + self.assertEqual('bar', standard.operator_getitem(d, 'foo')) + self.assertEqual('bar', standard.operator_getitem(d, 'Foo')) + self.assertEqual('bar', standard.operator_getitem(d, 'FOO')) standard.operator_delitem(d, 'foo') self.assertFalse('foo' in d) self.assertIsNone(d.get('foo'))