Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
137
Merge Requests
137
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
ccc09bf8
Commit
ccc09bf8
authored
Jul 09, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testPerformance: add benchmarks for getProperty and edit
parent
7672d3d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
product/ERP5Type/tests/testPerformance.py
product/ERP5Type/tests/testPerformance.py
+73
-0
No files found.
product/ERP5Type/tests/testPerformance.py
View file @
ccc09bf8
...
...
@@ -31,6 +31,7 @@ from time import time
import
gc
import
subprocess
from
zExceptions
import
Unauthorized
from
DateTime
import
DateTime
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
zLOG
import
LOG
...
...
@@ -385,3 +386,75 @@ class TestPerformance(TestPerformanceMixin):
MIN_OBJECT_MANY_LINES_VIEW
,
req_time
,
MAX_OBJECT_MANY_LINES_VIEW
))
class
TestPropertyPerformance
(
TestPerformanceMixin
):
def
afterSetUp
(
self
):
super
(
TestPerformanceMixin
,
self
).
afterSetUp
()
self
.
foo
=
self
.
portal
.
foo_module
.
newContent
(
portal_type
=
'Foo'
,
title
=
'Foo Test'
,
protected_property
=
'Restricted Property'
,
)
# we will run the test as anonymous user. Setup permissions so that anymous can
# get and set all properties, except `protected_property` (unless test change to another user)
for
permission
in
(
'View'
,
'Access contents information'
,
'Modify portal content'
):
self
.
foo
.
manage_permission
(
permission
,
[
'Anonymous'
],
1
)
self
.
tic
()
self
.
logout
()
def
_benchmark
(
self
,
nb_iterations
,
min_time
,
max_time
):
def
decorated
(
f
):
before
=
time
()
for
i
in
xrange
(
nb_iterations
):
f
(
i
)
after
=
time
()
total_time
=
(
after
-
before
)
/
100.
print
(
"time %s.%s %.4f < %.4f < %.4f
\
n
"
%
\
(
self
.
id
(),
f
.
__doc__
or
f
.
__name__
,
min_time
,
total_time
,
max_time
))
if
PROFILE
:
self
.
profile
(
f
,
args
=
(
i
,
))
if
DO_TEST
:
self
.
assertTrue
(
min_time
<
total_time
<
max_time
,
'%.4f < %.4f < %.4f'
%
(
min_time
,
total_time
,
max_time
))
return
decorated
def
test_getProperty_protected_property_refused
(
self
):
getProperty
=
self
.
foo
.
getProperty
self
.
assertRaises
(
Unauthorized
,
getProperty
,
'protected_property'
)
@
self
.
_benchmark
(
100000
,
0.0001
,
1
)
def
getPropertyWithRestrictedPropertyRefused
(
_
):
getProperty
(
'protected_property'
,
checked_permission
=
'Access contents information'
)
def
test_getProperty_protected_property_allowed
(
self
):
getProperty
=
self
.
foo
.
getProperty
self
.
login
()
@
self
.
_benchmark
(
100000
,
0.0001
,
1
)
def
getPropertyWithRestrictedPropertyAllowed
(
_
):
getProperty
(
'protected_property'
,
checked_permission
=
'Access contents information'
)
def
test_getProperty_simple_property
(
self
):
getProperty
=
self
.
foo
.
getProperty
@
self
.
_benchmark
(
100000
,
0.0001
,
1
)
def
getPropertyWithSimpleProperty
(
_
):
getProperty
(
'title'
,
checked_permission
=
'Access contents information'
)
def
test_edit_restricted_properties
(
self
):
_edit
=
self
.
foo
.
edit
self
.
login
()
@
self
.
_benchmark
(
10000
,
0.0001
,
1
)
def
edit
(
i
):
_edit
(
title
=
str
(
i
),
protected_property
=
str
(
i
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment