Commit 7cebcfeb authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: erp5_ui_test: Migrate Unit Tests.

parent a0d19fdd
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from test import pystone from test import pystone
from time import time from time import time
pystone.clock = time pystone.clock = time
from Products.ERP5Type.tests.testPerformance import TestPerformanceMixin from erp5.component.test.testPerformance import TestPerformanceMixin
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Testing import ZopeTestCase from Testing import ZopeTestCase
......
...@@ -43,9 +43,9 @@ class TestGUISecurity(ERP5TypeTestCase): ...@@ -43,9 +43,9 @@ class TestGUISecurity(ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
return "Security Issues in GUI" return "Security Issues in GUI"
def loginAs(self, id='user'): def loginAs(self, username='user'):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
user = uf.getUser(id).__of__(uf) user = uf.getUser(username).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def stepCreateObjects(self, sequence = None, sequence_list = None, **kw): def stepCreateObjects(self, sequence = None, sequence_list = None, **kw):
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testGUIwithSecurity</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Form.tests.testGUIwithSecurity</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testGUIwithSecurity</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -72,7 +72,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -72,7 +72,7 @@ class TestListBox(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
def login(self): def login(self, *args, **kw):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], []) uf._doAddUser('seb', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf) user = uf.getUserById('seb').__of__(uf)
...@@ -296,13 +296,13 @@ class TestListBox(ERP5TypeTestCase): ...@@ -296,13 +296,13 @@ class TestListBox(ERP5TypeTestCase):
],) ],)
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa') foo_module.newContent(title=u'\xe9lisa')
self.tic() self.tic()
request = get_request() request = get_request()
request['here'] = portal.foo_module request['here'] = portal.foo_module
try: try:
rendered = listbox.get_value('default', render_format='list', REQUEST=request) listbox.get_value('default', render_format='list', REQUEST=request)
except UnicodeError, e: except UnicodeError, e:
self.fail('Rendering failed: %s' % e) self.fail('Rendering failed: %s' % e)
self.assertIn(u"http://example.com/?\xe9lisa", listbox.render(REQUEST=request)) self.assertIn(u"http://example.com/?\xe9lisa", listbox.render(REQUEST=request))
...@@ -330,13 +330,13 @@ class TestListBox(ERP5TypeTestCase): ...@@ -330,13 +330,13 @@ class TestListBox(ERP5TypeTestCase):
],) ],)
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa') foo_module.newContent(title=u'\xe9lisa')
self.tic() self.tic()
request = get_request() request = get_request()
request['here'] = portal.foo_module request['here'] = portal.foo_module
try: try:
rendered = listbox.get_value('default', render_format='list', REQUEST=request) listbox.get_value('default', render_format='list', REQUEST=request)
except UnicodeError, e: except UnicodeError, e:
self.fail('Rendering failed: %s' % e) self.fail('Rendering failed: %s' % e)
self.assertIn(u"http://example.com/?\xe9lisa", listbox.render(REQUEST=request)) self.assertIn(u"http://example.com/?\xe9lisa", listbox.render(REQUEST=request))
...@@ -481,7 +481,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -481,7 +481,7 @@ class TestListBox(ERP5TypeTestCase):
# Create an new empty object with a list property # Create an new empty object with a list property
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent() foo_module.newContent()
# Reindex # Reindex
self.tic() self.tic()
...@@ -566,7 +566,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -566,7 +566,7 @@ class TestListBox(ERP5TypeTestCase):
# Create an new empty object with a list property # Create an new empty object with a list property
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent() foo_module.newContent()
# Reindex # Reindex
self.tic() self.tic()
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testListBox</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Form.tests.testListBox</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testListBox</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
# #
############################################################################## ##############################################################################
import unittest
from time import time from time import time
import gc import gc
import subprocess import subprocess
...@@ -120,174 +119,185 @@ PROFILER = 'pprofile' ...@@ -120,174 +119,185 @@ PROFILER = 'pprofile'
class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor): class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor):
def getBusinessTemplateList(self):
def getBusinessTemplateList(self): """
"""
Return the list of business templates. Return the list of business templates.
""" """
return ('erp5_base', return ('erp5_base',
'erp5_ui_test',) 'erp5_ui_test',)
def afterSetUp(self): def afterSetUp(self):
""" """
Executed before each test_*. Executed before each test_*.
""" """
# We don't want cpu time to be spent by random external sources: # We don't want cpu time to be spent by random external sources:
# - Bot should have its SQL database in a tmpfs storage. # - Bot should have its SQL database in a tmpfs storage.
# - As bot delete all '*.pyc' files before updating the working copy, # - As bot delete all '*.pyc' files before updating the working copy,
# all '*.pyc' files have just been recreated. They should be synced: # all '*.pyc' files have just been recreated. They should be synced:
subprocess.call('sync') subprocess.call('sync')
# - Prevent GC from happening. # - Prevent GC from happening.
# It would increase the "crosstalk" between using more ram and using more cpu. # It would increase the "crosstalk" between using more ram and using more cpu.
# Another problem is that it makes result even less reproductible on another # Another problem is that it makes result even less reproductible on another
# machine where memory use does not evolve identicaly (ie. x86_64 arch, # machine where memory use does not evolve identicaly (ie. x86_64 arch,
# because of 64bits pointers). # because of 64bits pointers).
gc.disable() gc.disable()
self.login() self.login()
self.bar_module = self.getBarModule() self.bar_module = self.getBarModule()
self.foo_module = self.portal.foo_module self.foo_module = self.portal.foo_module
def getBarModule(self): def getBarModule(self):
""" """
Return the bar module Return the bar module
""" """
return self.portal['bar_module'] return self.portal['bar_module']
def profile(self, func, suffix='', args=(), kw=None): def profile(self, func, suffix='', args=(), kw=None):
"""Profile `func(*args, **kw)` with selected profiler, """Profile `func(*args, **kw)` with selected profiler,
and dump output in a file called `func.__name__ + suffix` and dump output in a file called `func.__name__ + suffix`
""" """
if not kw: if not kw:
kw = {} kw = {}
if PROFILER == 'pprofile': if PROFILER == 'pprofile':
import pprofile import pprofile
prof = pprofile.Profile() prof = pprofile.Profile()
else: else:
from cProfile import Profile from cProfile import Profile
prof = Profile() prof = Profile()
prof_file = '%s%s' % (func.__name__, suffix) prof_file = '%s%s' % (func.__name__, suffix)
try: try:
os.unlink(prof_file) os.unlink(prof_file)
except OSError: except OSError:
pass pass
prof.runcall(func, *args, **kw) prof.runcall(func, *args, **kw)
prof.dump_stats(prof_file) prof.dump_stats(prof_file)
def beforeTearDown(self): def beforeTearDown(self):
# Re-enable gc at teardown. # Re-enable gc at teardown.
gc.enable() gc.enable()
self.abort() self.abort()
class TestPerformance(TestPerformanceMixin): class TestPerformance(TestPerformanceMixin):
def getTitle(self):
return "Performance"
def beforeTearDown(self):
super(TestPerformance, self).beforeTearDown()
self.bar_module.manage_delObjects(list(self.bar_module.objectIds()))
self.foo_module.manage_delObjects(list(self.foo_module.objectIds()))
gender = self.portal.portal_categories['gender']
gender.manage_delObjects(list(gender.objectIds()))
gender = self.portal.portal_caches.clearAllCache()
self.tic()
def getTitle(self): def checkViewBarObject(self, min_, max_, prefix=None):
return "Performance" # Some init to display form with some value
if prefix is None:
def beforeTearDown(self): prefix = ''
super(TestPerformance, self).beforeTearDown() gender = self.portal.portal_categories['gender']
self.bar_module.manage_delObjects(list(self.bar_module.objectIds())) if 'male' not in gender.objectIds():
self.foo_module.manage_delObjects(list(self.foo_module.objectIds())) gender.newContent(id='male', title='Male', portal_type='Category')
gender = self.portal.portal_categories['gender'] if 'female' not in gender.objectIds():
gender.manage_delObjects(list(gender.objectIds())) gender.newContent(id='female', title='Female', portal_type='Category')
gender = self.portal.portal_caches.clearAllCache()
self.tic() bar = self.bar_module.newContent(id='bar',
portal_type='Bar',
def checkViewBarObject(self, min, max, prefix=None): title='Bar Test',
# Some init to display form with some value quantity=10000,)
if prefix is None: bar.setReference(bar.getRelativeUrl())
prefix = '' self.tic()
gender = self.portal.portal_categories['gender'] # Check performance
if 'male' not in gender.objectIds(): before_view = time()
gender.newContent(id='male', title='Male', portal_type='Category') for _ in xrange(100):
if 'female' not in gender.objectIds(): # XXX: Note that we don't clean TransactionVariable cache and REQUEST
gender.newContent(id='female', title='Female', portal_type='Category') # before each call to 'view' requests. In reality, they would be
# always empty at the beginning of such requests.
bar = self.bar_module.newContent(id='bar', # If you work to improve performance of 'view' requests using this
portal_type='Bar', # kind of cache, make sure it is actually useful outside
title='Bar Test', # testPerformance.
quantity=10000,) bar.Bar_viewPerformance()
bar.setReference(bar.getRelativeUrl()) after_view = time()
self.tic() req_time = (after_view - before_view)/100.
# Check performance print "%s time to view object form %.4f < %.4f < %.4f\n" % \
before_view = time() (prefix, min_, req_time, max_)
for x in xrange(100): if PROFILE:
# XXX: Note that we don't clean TransactionVariable cache and REQUEST self.profile(bar.Bar_viewPerformance)
# before each call to 'view' requests. In reality, they would be if DO_TEST:
# always empty at the beginning of such requests. self.assertTrue(min_ < req_time < max_,
# If you work to improve performance of 'view' requests using this '%.4f < %.4f < %.4f' % (min_, req_time, max_))
# kind of cache, make sure it is actually useful outside
# testPerformance. def test_00_viewBarObject(self, min_=None, max_=None):
bar.Bar_viewPerformance() """
after_view = time() Estimate average time to render object view
req_time = (after_view - before_view)/100. """
print "%s time to view object form %.4f < %.4f < %.4f\n" % \ message = 'Test form to view Bar object'
(prefix, min, req_time, max) LOG('Testing... ', 0, message)
self.checkViewBarObject(MIN_OBJECT_VIEW, MAX_OBJECT_VIEW,
prefix='objective')
def test_01_viewBarModule(self):
"""
Estimate average time to render module view
"""
message = 'Test form to view Bar module'
LOG('Testing... ', 0, message)
self.tic()
view_result = {}
tic_result = {}
add_result = {}
# call view once to fill caches
self.bar_module.BarModule_viewBarList()
# add object in bar module
for i in xrange(10):
def add():
for x in xrange(100):
self.bar_module.newContent(portal_type='Bar',
title='Bar Test',
quantity="%4d" %(x,))
before_add = time()
if PROFILE: if PROFILE:
self.profile(bar.Bar_viewPerformance) self.profile(add, i)
if DO_TEST: else:
self.assertTrue(min < req_time < max, add()
'%.4f < %.4f < %.4f' % (min, req_time, max)) after_add = time()
self.commit()
def test_00_viewBarObject(self, min=None, max=None): before_tic = time()
""" if PROFILE:
Estimate average time to render object view self.profile(self.tic, i)
""" else:
message = 'Test form to view Bar object' self.tic()
LOG('Testing... ', 0, message) after_tic = time()
self.checkViewBarObject(MIN_OBJECT_VIEW, MAX_OBJECT_VIEW, gc.collect()
prefix='objective') before_form = time()
for _ in xrange(100):
def test_01_viewBarModule(self): self.bar_module.BarModule_viewBarList()
""" after_form = time()
Estimate average time to render module view # store result
""" key = "%06d" %(100*i+100,)
message = 'Test form to view Bar module' view_result[key] = (after_form - before_form)/100.
LOG('Testing... ', 0, message) tic_result[key] = (after_tic - before_tic)/100.
self.tic() add_result[key] = (after_add - before_add)/100.
view_result = {}
tic_result = {} if PROFILE:
add_result = {} self.profile(self.bar_module.BarModule_viewBarList, i)
# call view once to fill caches keys = view_result.keys()
self.bar_module.BarModule_viewBarList() keys.sort()
# add object in bar module # first display results
for i in xrange(10): i = 0
def add(): for key in keys:
for x in xrange(100): module_value = view_result[key]
p = self.bar_module.newContent(portal_type='Bar', tic_value = tic_result[key]
title='Bar Test', add_value = add_result[key]
quantity="%4d" %(x,)) min_view = MIN_MODULE_VIEW + LISTBOX_COEF * i
before_add = time() max_view = MAX_MODULE_VIEW + LISTBOX_COEF * i
if PROFILE: print "nb objects = %s\n\tadd = %.4f < %.4f < %.4f" %(key, MIN_OBJECT_CREATION, add_value, MAX_OBJECT_CREATION)
self.profile(add, i) print "\ttic = %.4f < %.4f < %.4f" %(MIN_TIC, tic_value, MAX_TIC)
else: print "\tview = %.4f < %.4f < %.4f" %(min_view, module_value, max_view)
add() print
after_add = time() i += 1
self.commit() # then check results
before_tic = time() if DO_TEST:
if PROFILE:
self.profile(self.tic, i)
else:
self.tic()
after_tic = time()
gc.collect()
before_form = time()
for x in xrange(100):
self.bar_module.BarModule_viewBarList()
after_form = time()
# store result
key = "%06d" %(100*i+100,)
view_result[key] = (after_form - before_form)/100.
tic_result[key] = (after_tic - before_tic)/100.
add_result[key] = (after_add - before_add)/100.
if PROFILE:
self.profile(self.bar_module.BarModule_viewBarList, i)
keys = view_result.keys()
keys.sort()
# first display results
i = 0 i = 0
for key in keys: for key in keys:
module_value = view_result[key] module_value = view_result[key]
...@@ -295,102 +305,86 @@ class TestPerformance(TestPerformanceMixin): ...@@ -295,102 +305,86 @@ class TestPerformance(TestPerformanceMixin):
add_value = add_result[key] add_value = add_result[key]
min_view = MIN_MODULE_VIEW + LISTBOX_COEF * i min_view = MIN_MODULE_VIEW + LISTBOX_COEF * i
max_view = MAX_MODULE_VIEW + LISTBOX_COEF * i max_view = MAX_MODULE_VIEW + LISTBOX_COEF * i
print "nb objects = %s\n\tadd = %.4f < %.4f < %.4f" %(key, MIN_OBJECT_CREATION, add_value, MAX_OBJECT_CREATION) self.assertTrue(min_view < module_value < max_view,
print "\ttic = %.4f < %.4f < %.4f" %(MIN_TIC, tic_value, MAX_TIC) 'View: %.4f < %.4f < %.4f' % (
print "\tview = %.4f < %.4f < %.4f" %(min_view, module_value, max_view) min_view, module_value, max_view))
print self.assertTrue(
MIN_OBJECT_CREATION < add_value < MAX_OBJECT_CREATION,
'Create: %.4f < %.4f < %.4f' % (
MIN_OBJECT_CREATION, add_value, MAX_OBJECT_CREATION))
self.assertTrue(MIN_TIC < tic_value < MAX_TIC,
'Tic: %.4f < %.4f < %.4f' % (
MIN_TIC, tic_value, MAX_TIC))
i += 1 i += 1
# then check results
if DO_TEST: def test_viewProxyField(self):
i = 0 # render a form with proxy fields: Foo_viewProxyField
for key in keys: foo = self.foo_module.newContent(
module_value = view_result[key]
tic_value = tic_result[key]
add_value = add_result[key]
min_view = MIN_MODULE_VIEW + LISTBOX_COEF * i
max_view = MAX_MODULE_VIEW + LISTBOX_COEF * i
self.assertTrue(min_view < module_value < max_view,
'View: %.4f < %.4f < %.4f' % (
min_view, module_value, max_view))
self.assertTrue(
MIN_OBJECT_CREATION < add_value < MAX_OBJECT_CREATION,
'Create: %.4f < %.4f < %.4f' % (
MIN_OBJECT_CREATION, add_value, MAX_OBJECT_CREATION))
self.assertTrue(MIN_TIC < tic_value < MAX_TIC,
'Tic: %.4f < %.4f < %.4f' % (
MIN_TIC, tic_value, MAX_TIC))
i += 1
def test_viewProxyField(self):
# render a form with proxy fields: Foo_viewProxyField
foo = self.foo_module.newContent(
portal_type='Foo', portal_type='Foo',
title='Bar Test', title='Bar Test',
quantity=10000, quantity=10000,
price=32, price=32,
start_date=DateTime(2008,1,1)) start_date=DateTime(2008,1,1))
foo.newContent(portal_type='Foo Line', foo.newContent(portal_type='Foo Line',
title='Line 1') title='Line 1')
foo.newContent(portal_type='Foo Line', foo.newContent(portal_type='Foo Line',
title='Line 2') title='Line 2')
self.tic() self.tic()
# Check performance # Check performance
before_view = time() before_view = time()
for x in xrange(100): for _ in xrange(100):
foo.Foo_viewProxyField() foo.Foo_viewProxyField()
after_view = time() after_view = time()
req_time = (after_view - before_view)/100. req_time = (after_view - before_view)/100.
print "time to view proxyfield form %.4f < %.4f < %.4f\n" % \ print "time to view proxyfield form %.4f < %.4f < %.4f\n" % \
( MIN_OBJECT_PROXYFIELD_VIEW, ( MIN_OBJECT_PROXYFIELD_VIEW,
req_time, req_time,
MAX_OBJECT_PROXYFIELD_VIEW ) MAX_OBJECT_PROXYFIELD_VIEW )
if PROFILE: if PROFILE:
self.profile(foo.Foo_viewProxyField) self.profile(foo.Foo_viewProxyField)
if DO_TEST: if DO_TEST:
self.assertTrue( MIN_OBJECT_PROXYFIELD_VIEW < req_time self.assertTrue( MIN_OBJECT_PROXYFIELD_VIEW < req_time
< MAX_OBJECT_PROXYFIELD_VIEW, < MAX_OBJECT_PROXYFIELD_VIEW,
'%.4f < %.4f < %.4f' % ( '%.4f < %.4f < %.4f' % (
MIN_OBJECT_PROXYFIELD_VIEW, MIN_OBJECT_PROXYFIELD_VIEW,
req_time, req_time,
MAX_OBJECT_PROXYFIELD_VIEW)) MAX_OBJECT_PROXYFIELD_VIEW))
def test_02_viewFooObjectWithManyLines(self): def test_02_viewFooObjectWithManyLines(self):
""" """
Estimate average time to render object view with many lines Estimate average time to render object view with many lines
""" """
foo = self.foo_module.newContent(portal_type='Foo', foo = self.foo_module.newContent(portal_type='Foo',
title='Foo Test') title='Foo Test')
for i in xrange(100): for i in xrange(100):
foo.newContent(portal_type='Foo Line', foo.newContent(portal_type='Foo Line',
title='Line %s' % i) title='Line %s' % i)
self.tic() self.tic()
# Check performance # Check performance
before_view = time() before_view = time()
for x in xrange(100): for _ in xrange(100):
foo.Foo_viewPerformance() foo.Foo_viewPerformance()
after_view = time() after_view = time()
req_time = (after_view - before_view)/100. req_time = (after_view - before_view)/100.
print "time to view object form with many lines %.4f < %.4f < %.4f\n" % \ print "time to view object form with many lines %.4f < %.4f < %.4f\n" % \
( MIN_OBJECT_MANY_LINES_VIEW, ( MIN_OBJECT_MANY_LINES_VIEW,
req_time, req_time,
MAX_OBJECT_MANY_LINES_VIEW ) MAX_OBJECT_MANY_LINES_VIEW )
if PROFILE: if PROFILE:
self.profile(foo.Foo_viewPerformance) self.profile(foo.Foo_viewPerformance)
if DO_TEST: if DO_TEST:
self.assertTrue( MIN_OBJECT_MANY_LINES_VIEW < req_time self.assertTrue( MIN_OBJECT_MANY_LINES_VIEW < req_time
< MAX_OBJECT_MANY_LINES_VIEW, < MAX_OBJECT_MANY_LINES_VIEW,
'%.4f < %.4f < %.4f' % ( '%.4f < %.4f < %.4f' % (
MIN_OBJECT_MANY_LINES_VIEW, MIN_OBJECT_MANY_LINES_VIEW,
req_time, req_time,
MAX_OBJECT_MANY_LINES_VIEW)) MAX_OBJECT_MANY_LINES_VIEW))
class TestPropertyPerformance(TestPerformanceMixin): class TestPropertyPerformance(TestPerformanceMixin):
def afterSetUp(self): def afterSetUp(self):
super(TestPerformanceMixin, self).afterSetUp() super(TestPerformanceMixin, self).afterSetUp() # pylint: disable=bad-super-call
self.foo = self.portal.foo_module.newContent( self.foo = self.portal.foo_module.newContent(
portal_type='Foo', portal_type='Foo',
title='Foo Test', title='Foo Test',
...@@ -433,27 +427,27 @@ class TestPropertyPerformance(TestPerformanceMixin): ...@@ -433,27 +427,27 @@ class TestPropertyPerformance(TestPerformanceMixin):
self.assertRaises(Unauthorized, getProperty, 'protected_property') self.assertRaises(Unauthorized, getProperty, 'protected_property')
@self._benchmark(100000, 0.0001, 1) @self._benchmark(100000, 0.0001, 1)
def getPropertyWithRestrictedPropertyRefused(_): def getPropertyWithRestrictedPropertyRefused(_): # pylint: disable=unused-variable
getProperty('protected_property', checked_permission='Access contents information') getProperty('protected_property', checked_permission='Access contents information')
def test_getProperty_protected_property_allowed(self): def test_getProperty_protected_property_allowed(self):
getProperty = self.foo.getProperty getProperty = self.foo.getProperty
self.login() self.login()
@self._benchmark(100000, 0.0001, 1) @self._benchmark(100000, 0.0001, 1)
def getPropertyWithRestrictedPropertyAllowed(_): def getPropertyWithRestrictedPropertyAllowed(_): # pylint: disable=unused-variable
getProperty('protected_property', checked_permission='Access contents information') getProperty('protected_property', checked_permission='Access contents information')
def test_getProperty_simple_property(self): def test_getProperty_simple_property(self):
getProperty = self.foo.getProperty getProperty = self.foo.getProperty
@self._benchmark(100000, 0.0001, 1) @self._benchmark(100000, 0.0001, 1)
def getPropertyWithSimpleProperty(_): def getPropertyWithSimpleProperty(_): # pylint: disable=unused-variable
getProperty('title', checked_permission='Access contents information') getProperty('title', checked_permission='Access contents information')
def test_edit_restricted_properties(self): def test_edit_restricted_properties(self):
_edit = self.foo.edit _edit = self.foo.edit
self.login() self.login()
@self._benchmark(10000, 0.0001, 1) @self._benchmark(10000, 0.0001, 1)
def edit(i): def edit(i): # pylint: disable=unused-variable
_edit( _edit(
title=str(i), title=str(i),
protected_property=str(i) protected_property=str(i)
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testPerformance</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Type.tests.testPerformance</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testPerformance</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -52,15 +52,15 @@ class TestPlanningBox(ERP5TypeTestCase): ...@@ -52,15 +52,15 @@ class TestPlanningBox(ERP5TypeTestCase):
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
# Use the same framework as the functional testing for convenience. # Use the same framework as the functional testing for convenience.
# This adds some specific portal types and skins. # This adds some specific portal types and skins.
return ('erp5_ui_test',) return ('erp5_ui_test',)
def getTitle(self): def getTitle(self):
return "PlanningBox" return "PlanningBox"
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
def login(self): def login(self, *args, **kw):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], []) uf._doAddUser('seb', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf) user = uf.getUserById('seb').__of__(uf)
...@@ -125,7 +125,7 @@ class TestPlanningBox(ERP5TypeTestCase): ...@@ -125,7 +125,7 @@ class TestPlanningBox(ERP5TypeTestCase):
self.assertEqual(sec_axis_info['bound_start'], today) self.assertEqual(sec_axis_info['bound_start'], today)
self.assertEqual(sec_axis_info['bound_stop'], today+1) self.assertEqual(sec_axis_info['bound_stop'], today+1)
for tree_list, activity_list,stat in basic.report_group_list: for _, activity_list, _ in basic.report_group_list:
self.assertEqual(len(activity_list), 1) self.assertEqual(len(activity_list), 1)
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testPlanningBox</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Form.tests.testPlanningBox</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testPlanningBox</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
test.erp5.testGUIwithSecurity
test.erp5.testListBox
test.erp5.testPerformance
test.erp5.testPlanningBox
test.erp5.testRelationField test.erp5.testRelationField
\ No newline at end of file
erp5_full_text_mroonga_catalog
erp5_core_proxy_field_legacy
erp5_base
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment