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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
25042ac5
Commit
25042ac5
authored
Sep 25, 2019
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qa: speed up and clean up testTransactionalVariable
parent
e559ecd5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
39 deletions
+16
-39
product/ERP5Type/tests/testTransactionalVariable.py
product/ERP5Type/tests/testTransactionalVariable.py
+16
-39
No files found.
product/ERP5Type/tests/testTransactionalVariable.py
View file @
25042ac5
...
...
@@ -26,51 +26,37 @@
#
##############################################################################
import
unittest
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.utils
import
LogInterceptor
from
Testing.ZopeTestCase
import
TestCase
from
Products.ERP5Type.TransactionalVariable
import
getTransactionalVariable
class
TestTransactionalVariable
(
ERP5TypeTestCase
,
LogInterceptor
):
# Some helper methods
def
getTitle
(
self
):
return
"Transactional Variable"
def
getBusinessTemplateList
(
self
):
"""
Return the list of business templates.
"""
return
()
class
TestTransactionalVariable
(
TestCase
):
def
afterSetUp
(
self
):
self
.
login
()
from
transaction
import
abort
,
commit
def
test_01_DictInterface
(
self
):
"""Check if a transaction variable behaves in the same way as a dict. """
tv
=
getTransactionalVariable
()
self
.
assertNotEqual
(
tv
,
None
)
# Test frequently used dict methods. This does not cover everything,
# but should be enough.
tv
.
clear
()
self
.
assertEqual
(
len
(
tv
),
0
)
self
.
assertRaises
(
KeyError
,
tv
.
__getitem__
,
'toto'
)
with
self
.
assertRaises
(
KeyError
):
tv
[
'toto'
]
tv
[
'toto'
]
=
'titi'
self
.
assertEqual
(
len
(
tv
),
1
)
self
.
assertEqual
(
tv
[
'toto'
],
'titi'
)
self
.
assert
Equal
(
tv
.
get
(
'foo'
),
None
)
self
.
assert
IsNone
(
tv
.
get
(
'foo'
)
)
tv
.
setdefault
(
'foo'
,
'bar'
)
self
.
assertEqual
(
len
(
tv
),
2
)
self
.
assertEqual
(
tv
[
'foo'
],
'bar'
)
self
.
assert
True
(
'foo'
in
tv
)
self
.
assert
In
(
'foo'
,
tv
)
del
tv
[
'foo'
]
self
.
assert
False
(
'foo'
in
tv
)
self
.
assert
NotIn
(
'foo'
,
tv
)
self
.
assertEqual
(
len
(
tv
),
1
)
def
test_02_Expiration
(
self
):
...
...
@@ -78,8 +64,6 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
transactions.
"""
tv
=
getTransactionalVariable
()
self
.
assertNotEqual
(
tv
,
None
)
tv
.
clear
()
self
.
assertEqual
(
len
(
tv
),
0
)
...
...
@@ -87,21 +71,19 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
tv
[
'toto'
]
=
'titi'
self
.
assertEqual
(
tv
[
'toto'
],
'titi'
)
self
.
commit
()
self
.
assert
False
(
'toto'
in
tv
)
self
.
assert
NotIn
(
'toto'
,
tv
)
# Abort and check.
tv
[
'toto'
]
=
'titi'
self
.
assertEqual
(
tv
[
'toto'
],
'titi'
)
self
.
abort
()
self
.
assert
False
(
'toto'
in
tv
)
self
.
assert
NotIn
(
'toto'
,
tv
)
def
test_03_Durability
(
self
):
"""Check if a transaction variable does not disappear within the same
transaction.
"""
tv
=
getTransactionalVariable
()
self
.
assertNotEqual
(
tv
,
None
)
tv
.
clear
()
self
.
assertEqual
(
len
(
tv
),
0
)
...
...
@@ -109,19 +91,14 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
# in order to detect the difference between their behaviors.
tv
[
'toto'
]
=
'titi'
self
.
assertEqual
(
tv
[
'toto'
],
'titi'
)
portal
=
self
.
portal
app
=
self
.
app
vattr
=
'_v_erp5type_test_durability'
setattr
(
portal
,
vattr
,
'dummy'
)
self
.
assertEqual
(
getattr
(
portal
,
vattr
),
'dummy'
)
setattr
(
app
,
vattr
,
'dummy'
)
self
.
assertEqual
(
getattr
(
app
,
vattr
),
'dummy'
)
# Force to minimize the connection cache so that volatile attributes
# and unghostified objects are discarded.
portal
.
_p_jar
.
cacheMinimize
()
self
.
assert
True
(
'toto'
in
tv
)
app
.
_p_jar
.
cacheMinimize
()
self
.
assert
In
(
'toto'
,
tv
)
self
.
assertEqual
(
tv
[
'toto'
],
'titi'
)
self
.
assertEqual
(
getattr
(
portal
,
vattr
,
None
),
None
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestTransactionalVariable
))
return
suite
self
.
assertIsNone
(
getattr
(
app
,
vattr
,
None
))
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