Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test portal #284

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Products/zms/zpt/ZMSRecordSet/input_fields.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
python:here.getObjAttrInput(fmName='form0',obj_attr=here.getObjAttr(elName),value=elValue,REQUEST=request)">
the control
</tal:block>
<tal:block tal:condition="python:metaObjAttr['type'] in ['image'] and elValue is not None and here.operator_gettype(elValue) is str">
<tal:block tal:condition="python:metaObjAttr['type'] in ['image'] and elValue is not None and standard.operator_gettype(elValue) is str">
<img src="data:image/png;base64," tal:attributes="data-previewbase64 elValue" width="32" height="32" />
<input type="hidden" tal:attributes="value elValue" />
</tal:block>
Expand Down
6 changes: 3 additions & 3 deletions Products/zms/zpt/ZMSRecordSet/main_grid.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@
><i class="fas fa-check-square" tal:attributes="class python:'far fa-%ssquare'%(elValue and 'check-' or '')"></i>
</tal:block
><tal:block tal:condition="python:elType in ['image']"
><tal:block tal:condition="python:elValue is not None and here.operator_gettype(elValue) is not str"
><tal:block tal:condition="python:elValue is not None and standard.operator_gettype(elValue) is not str"
><a tal:attributes="href python:elValue.getHref(request)" class="thumbnail" target="_blank"><img tal:attributes="src python:elValue.getHref(request)"/></a>
</tal:block
><tal:block tal:condition="python:elValue is not None and here.operator_gettype(elValue) is str">
><tal:block tal:condition="python:elValue is not None and standard.operator_gettype(elValue) is str">
<img src="data:image/png;base64," tal:attributes="data-previewbase64 elValue" width="32" height="32" />
</tal:block
></tal:block
><tal:block tal:condition="python:elType in ['file'] and elValue is not None"
><i class="fas fa-download"></i> <tal:block
tal:on-error="string:<!-- FILENAME-ERROR -->"
tal:content="structure python:(here.operator_gettype(elValue) is not str) and elValue.getFilename() or elValue">filename</tal:block
tal:content="structure python:(standard.operator_gettype(elValue) is not str) and elValue.getFilename() or elValue">filename</tal:block
></tal:block
><tal:block tal:condition="python:elType in ['date','datetime','time']"
><tal:block tal:content="python:here.getLangFmtDate(elValue,fmt_str=('%s_fmt'%elType).upper())">elValue</tal:block
Expand Down
2 changes: 1 addition & 1 deletion Products/zms/zpt/ZMSSqlDb/zmi_lazy_select_form.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
entity python:here.getEntity(request['qentity']);
encoding python:getattr(here,'charset','utf-8');
actions python:request.get('actions','select');
actions python:[actions,','.join(actions)][int(here.operator_gettype(actions) is list)];
actions python:[actions,','.join(actions)][int(standard.operator_gettype(actions) is list)];
dummy0 python:request.set('qsize',request.get('qsize',standard.get_session_value(here,'qsize_%s'%id,20)));
dummy0 python:request.set('qindex',request.get('qindex',standard.get_session_value(here,'qindex_%s'%id,-1)));
columns python:','.join(request['qcolumns']);
Expand Down
6 changes: 3 additions & 3 deletions Products/zms/zpt/objattrs/f_select_file.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script tal:condition="python:standard.once('zmiBlobJs',request)" type="text/javascript" charset="UTF-8" src="/++resource++zms_/objattrs/zmi.blob.js"></script>

<div class="zmi-file d-flex align-items-center row"
tal:define="has_file python:value is not None and here.operator_gettype(value) is not str;
tal:define="has_file python:value is not None and standard.operator_gettype(value) is not str;
allowed_ext python:request.set('ZMS_ALLOWED_EXTENSIONS',['jpg', 'jpeg', 'png', 'gif','svg']);
filename python:has_file and value.getFilename() or 'None';
href python:has_file and value.getHref(request) or 'None';
Expand All @@ -18,7 +18,7 @@
<input type="hidden" tal:attributes="name python:'exists_%s'%elName; value python:request.get('ZMS_INSERT',None) is None and value not in [None,'']" />
<input type="hidden" tal:attributes="name python:'del_%s'%elName" value="0" />

<div class="col-12" tal:attributes="class python:not(value is not None and here.operator_gettype(value) is not str) and 'col-9' or default">
<div class="col-12" tal:attributes="class python:not(value is not None and standard.operator_gettype(value) is not str) and 'col-9' or default">
<div class="zmi-input-file btn-group">

<div class="custom-file"
Expand Down Expand Up @@ -56,7 +56,7 @@
</div>
</div>

<div class="col-3" tal:condition="not:python:value is not None and here.operator_gettype(value) is not str">
<div class="col-3" tal:condition="not:python:value is not None and standard.operator_gettype(value) is not str">
<div class="zmi-file-info">
<a tal:attributes="id python:'filename_%s'%elName" target="_blank" tal:content="python:''">the filename</a>
<span class="size" tal:attributes="id python:'size_%s'%elName" tal:content="python:''">the size</span>
Expand Down
6 changes: 3 additions & 3 deletions Products/zms/zpt/objattrs/f_select_image.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<script defer type="text/javascript" tal:condition="python:standard.once('zmiBlobJs',request)" charset="UTF-8" src="/++resource++zms_/objattrs/zmi.blob.js"></script>

<div class="zmi-image d-flex align-items-center row"
tal:define="has_file python:value is not None and here.operator_gettype(value) is not str;
tal:define="has_file python:value is not None and standard.operator_gettype(value) is not str;
allowed_ext python:request.set('ZMS_ALLOWED_EXTENSIONS',['jpg', 'jpeg', 'png', 'gif','svg']);
filename python:has_file and value.getFilename() or 'None';
href python:has_file and value.getHref(request) or 'None';
Expand Down Expand Up @@ -150,7 +150,7 @@

<div class="col mx-3 p-0" tal:condition="has_file">

<tal:block tal:condition="python:value is not None and here.operator_gettype(value) is not str">
<tal:block tal:condition="python:value is not None and standard.operator_gettype(value) is not str">
<div class="zmi-image-preview" tal:attributes="id python:'ZMSGraphic_extEdit_preview_%s'%elName"
tal:condition="python:key.find('superres')<0 and value.getContentType().find('image')==0">
<input type="hidden" tal:attributes="id python:'width_%s'%elName; name python:'width_%s:int'%elName; value python:value.getWidth()"/>
Expand All @@ -171,7 +171,7 @@
</div>
</tal:block>

<tal:block tal:condition="not:python:value is not None and here.operator_gettype(value) is not str">
<tal:block tal:condition="not:python:value is not None and standard.operator_gettype(value) is not str">
<div class="zmi-image-info">
<a data-turbolinks="false" tal:attributes="id python:'filename_%s'%elName" target="_blank" tal:content="python:''">the filename</a>
<span class="dimensions" tal:attributes="id python:'dimensions_%s'%elName" tal:content="python:''">the dimensions</span>
Expand Down
34 changes: 34 additions & 0 deletions tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,37 @@ 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
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.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.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'))

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))
64 changes: 64 additions & 0 deletions tests/test_zms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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 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)
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
Loading