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
141
Merge Requests
141
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
2b65ad60
Commit
2b65ad60
authored
Oct 05, 2020
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZODB Components: testAssignToPortalTypeClass: Refactor.
parent
beb7c272
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
103 deletions
+103
-103
product/ERP5Type/tests/testDynamicClassGeneration.py
product/ERP5Type/tests/testDynamicClassGeneration.py
+103
-103
No files found.
product/ERP5Type/tests/testDynamicClassGeneration.py
View file @
2b65ad60
...
...
@@ -2681,109 +2681,6 @@ class DifferentFromReference(Person):
self
.
assertEqual
(
component
.
getTextContentErrorMessageList
(),
[])
self
.
assertEqual
(
component
.
getTextContentWarningMessageList
(),
[])
def
testAssignToPortalTypeClass
(
self
):
"""
Create a new Document Component inheriting from Person Document and try to
assign it to Person Portal Type, then create a new Person and check
whether it has been successfully added to its Portal Type class bases and
that the newly-defined function on ZODB Component can be called as well as
methods from Person Document
"""
## Create an Interface assigned to the test ZODB Component to check that
## only resetting Portal Type classes do not have any side-effect on
## Interfaces defined on ZODB Components
from
zope.interface
import
Interface
class
ITestPortalType
(
Interface
):
"""Anything"""
def
foo
():
"""Anything"""
from
types
import
ModuleType
interface_module
=
ModuleType
(
'ITestPortalType'
)
interface_module
.
ITestPortalType
=
ITestPortalType
sys
.
modules
[
'ITestPortalType'
]
=
interface_module
self
.
failIfModuleImportable
(
'TestPortalType'
)
# Create a new Document Component inheriting from Person Document which
# defines only one additional method (meaningful to make sure that the
# class (and not the module) has been added to the class when the
# TypeClass is changed)
test_component
=
self
.
_newComponent
(
'TestPortalType'
,
"""
from erp5.component.document.Person import Person
from ITestPortalType import ITestPortalType
import zope.interface
class TestPortalType(Person):
def test42(self):
return 42
zope.interface.implements(ITestPortalType)
def foo(self):
pass
"""
)
test_component
.
validate
()
self
.
tic
()
# As TestPortalType Document Component has been validated, it should now
# be available
self
.
assertModuleImportable
(
'TestPortalType'
,
reset
=
False
)
self
.
assertTrue
(
ITestPortalType
.
implementedBy
(
self
.
_module
.
TestPortalType
.
TestPortalType
))
self
.
_component_tool
.
reset
(
force
=
True
,
reset_portal_type_at_transaction_boundary
=
True
)
person_type
=
self
.
portal
.
portal_types
.
Person
person_type_class
=
person_type
.
getTypeClass
()
self
.
assertEqual
(
person_type_class
,
'Person'
)
# Create a new Person
person_module
=
self
.
portal
.
person_module
person
=
person_module
.
newContent
(
id
=
'Foo Bar'
,
portal_type
=
'Person'
)
from
erp5.component.document.Person
import
Person
as
PersonDocument
self
.
assertTrue
(
PersonDocument
in
person
.
__class__
.
mro
())
# There is no reason that TestPortalType Document Component has been
# assigned to a Person
self
.
failIfHasAttribute
(
person
,
'test42'
)
self
.
failIfHasAttribute
(
self
.
_module
,
'TestPortalType'
)
self
.
assertFalse
(
ITestPortalType
.
providedBy
(
person
))
self
.
assertFalse
(
ITestPortalType
.
implementedBy
(
person
.
__class__
))
for
klass
in
person
.
__class__
.
mro
():
self
.
assertNotEqual
(
klass
.
__name__
,
'TestPortalType'
)
def
_check
():
self
.
assertHasAttribute
(
person
,
'test42'
)
self
.
assertEqual
(
person
.
test42
(),
42
)
# The Portal Type class should not be in ghost state by now as we tried
# to access test42() defined in TestPortalType Document Component
self
.
assertHasAttribute
(
self
.
_module
,
'TestPortalType'
)
self
.
assertTrue
(
self
.
_module
.
TestPortalType
.
TestPortalType
in
person
.
__class__
.
mro
())
from
erp5.component.document.Person
import
Person
as
PersonDocument
self
.
assertTrue
(
PersonDocument
in
person
.
__class__
.
mro
())
self
.
assertTrue
(
ITestPortalType
.
providedBy
(
person
))
self
.
assertTrue
(
ITestPortalType
.
implementedBy
(
person
.
__class__
))
# Reset Portal Type classes to ghost to make sure that everything is reset
self
.
_component_tool
.
reset
(
force
=
True
,
reset_portal_type_at_transaction_boundary
=
False
)
# TestPortalType must be available in type class list
self
.
assertTrue
(
'TestPortalType'
in
person_type
.
getDocumentTypeList
())
try
:
person_type
.
setTypeClass
(
'TestPortalType'
)
self
.
commit
()
_check
()
self
.
portal
.
portal_types
.
resetDynamicDocuments
()
_check
()
finally
:
person_type
.
setTypeClass
(
'Person'
)
self
.
commit
()
def
testImportFromAnotherComponent
(
self
):
"""
Create two new Components and check whether one can import the other one
...
...
@@ -2926,6 +2823,109 @@ class %s(Person):
pass
'''
%
(
class_name
,
class_name
)
def
testAssignToPortalTypeClass
(
self
):
"""
Create a new Document Component inheriting from Person Document and try to
assign it to Person Portal Type, then create a new Person and check
whether it has been successfully added to its Portal Type class bases and
that the newly-defined function on ZODB Component can be called as well as
methods from Person Document
"""
## Create an Interface assigned to the test ZODB Component to check that
## only resetting Portal Type classes do not have any side-effect on
## Interfaces defined on ZODB Components
from
zope.interface
import
Interface
class
ITestPortalType
(
Interface
):
"""Anything"""
def
foo
():
"""Anything"""
from
types
import
ModuleType
interface_module
=
ModuleType
(
'ITestPortalType'
)
interface_module
.
ITestPortalType
=
ITestPortalType
sys
.
modules
[
'ITestPortalType'
]
=
interface_module
self
.
failIfModuleImportable
(
'TestPortalType'
)
# Create a new Document Component inheriting from Person Document which
# defines only one additional method (meaningful to make sure that the
# class (and not the module) has been added to the class when the
# TypeClass is changed)
test_component
=
self
.
_newComponent
(
'TestPortalType'
,
"""
from erp5.component.document.Person import Person
from ITestPortalType import ITestPortalType
import zope.interface
class TestPortalType(Person):
def test42(self):
return 42
zope.interface.implements(ITestPortalType)
def foo(self):
pass
"""
)
test_component
.
validate
()
self
.
tic
()
# As TestPortalType Document Component has been validated, it should now
# be available
self
.
assertModuleImportable
(
'TestPortalType'
,
reset
=
False
)
self
.
assertTrue
(
ITestPortalType
.
implementedBy
(
self
.
_module
.
TestPortalType
.
TestPortalType
))
self
.
_component_tool
.
reset
(
force
=
True
,
reset_portal_type_at_transaction_boundary
=
True
)
person_type
=
self
.
portal
.
portal_types
.
Person
person_type_class
=
person_type
.
getTypeClass
()
self
.
assertEqual
(
person_type_class
,
'Person'
)
# Create a new Person
person_module
=
self
.
portal
.
person_module
person
=
person_module
.
newContent
(
id
=
'Foo Bar'
,
portal_type
=
'Person'
)
from
erp5.component.document.Person
import
Person
as
PersonDocument
self
.
assertTrue
(
PersonDocument
in
person
.
__class__
.
mro
())
# There is no reason that TestPortalType Document Component has been
# assigned to a Person
self
.
failIfHasAttribute
(
person
,
'test42'
)
self
.
failIfHasAttribute
(
self
.
_module
,
'TestPortalType'
)
self
.
assertFalse
(
ITestPortalType
.
providedBy
(
person
))
self
.
assertFalse
(
ITestPortalType
.
implementedBy
(
person
.
__class__
))
for
klass
in
person
.
__class__
.
mro
():
self
.
assertNotEqual
(
klass
.
__name__
,
'TestPortalType'
)
def
_check
():
self
.
assertHasAttribute
(
person
,
'test42'
)
self
.
assertEqual
(
person
.
test42
(),
42
)
# The Portal Type class should not be in ghost state by now as we tried
# to access test42() defined in TestPortalType Document Component
self
.
assertHasAttribute
(
self
.
_module
,
'TestPortalType'
)
self
.
assertTrue
(
self
.
_module
.
TestPortalType
.
TestPortalType
in
person
.
__class__
.
mro
())
from
erp5.component.document.Person
import
Person
as
PersonDocument
self
.
assertTrue
(
PersonDocument
in
person
.
__class__
.
mro
())
self
.
assertTrue
(
ITestPortalType
.
providedBy
(
person
))
self
.
assertTrue
(
ITestPortalType
.
implementedBy
(
person
.
__class__
))
# Reset Portal Type classes to ghost to make sure that everything is reset
self
.
_component_tool
.
reset
(
force
=
True
,
reset_portal_type_at_transaction_boundary
=
False
)
# TestPortalType must be available in type class list
self
.
assertTrue
(
'TestPortalType'
in
person_type
.
getDocumentTypeList
())
try
:
person_type
.
setTypeClass
(
'TestPortalType'
)
self
.
commit
()
_check
()
self
.
portal
.
portal_types
.
resetDynamicDocuments
()
_check
()
finally
:
person_type
.
setTypeClass
(
'Person'
)
self
.
commit
()
def
testProductsERP5DocumentCompatibility
(
self
):
"""Check that document class also exist in its original namespace (source_reference)
...
...
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