Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
001ac552
Commit
001ac552
authored
Apr 02, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix startup bug where five:register_class barfed due to missing Products.meta_types.
parent
f3bb2742
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
1 deletion
+152
-1
src/OFS/metaconfigure.py
src/OFS/metaconfigure.py
+3
-1
src/OFS/tests/test_metaconfigure.py
src/OFS/tests/test_metaconfigure.py
+149
-0
No files found.
src/OFS/metaconfigure.py
View file @
001ac552
...
...
@@ -124,7 +124,9 @@ def _registerClass(class_, meta_type, permission, addview, icon, global_):
'instance'
:
class_
,
'container_filter'
:
None
}
Products
.
meta_types
+=
(
info
,)
meta_types
=
getattr
(
Products
,
'meta_types'
,
())
meta_types
+=
(
info
,)
Products
.
meta_types
=
meta_types
_register_monkies
.
append
(
class_
)
_meta_type_regs
.
append
(
meta_type
)
...
...
src/OFS/tests/test_metaconfigure.py
0 → 100644
View file @
001ac552
import
unittest
_marker
=
object
()
class
Test__registerClass
(
unittest
.
TestCase
):
def
setUp
(
self
):
from
zope.component.testing
import
setUp
setUp
()
import
OFS.metaconfigure
import
Products
self
.
_old_metatypes
=
getattr
(
Products
,
'meta_types'
,
_marker
)
self
.
_old_monkies
=
OFS
.
metaconfigure
.
_register_monkies
[:]
self
.
_old_mt_regs
=
OFS
.
metaconfigure
.
_meta_type_regs
[:]
# clear out registrations
if
self
.
_old_metatypes
is
not
_marker
:
Products
.
meta_types
=
[]
OFS
.
metaconfigure
.
_register_monkies
[:]
=
[]
OFS
.
metaconfigure
.
_meta_type_regs
[:]
=
[]
def
tearDown
(
self
):
from
zope.component.testing
import
tearDown
import
OFS.metaconfigure
# restore registrations
OFS
.
metaconfigure
.
_meta_type_regs
[:]
=
self
.
_old_mt_regs
OFS
.
metaconfigure
.
_register_monkies
[:]
=
self
.
_old_monkies
if
self
.
_old_metatypes
is
not
_marker
:
import
Products
Products
.
meta_types
=
self
.
_old_metatypes
else
:
try
:
del
Products
.
meta_types
except
AttributeError
:
pass
tearDown
()
def
_callFUT
(
self
,
klass
,
meta_type
,
permission
,
addview
=
None
,
icon
=
None
,
global_
=
False
):
from
OFS.metaconfigure
import
_registerClass
_registerClass
(
klass
,
meta_type
,
permission
,
addview
,
icon
,
global_
)
def
_makeClass
(
self
,
ifaces
=
None
):
if
ifaces
is
None
:
class
Dummy
(
object
):
pass
else
:
from
zope.interface
import
implements
class
Dummy
(
object
):
implements
(
ifaces
)
return
Dummy
def
_registerPermission
(
self
,
name
,
title
=
None
):
from
zope.component
import
provideUtility
from
zope.interface
import
implements
from
zope.security.interfaces
import
IPermission
class
Perm
:
implements
(
IPermission
)
def
__init__
(
self
,
title
):
self
.
title
=
title
if
title
is
None
:
title
=
name
.
capitalize
()
provideUtility
(
Perm
(
title
),
name
=
name
)
def
_getRegistered
(
self
):
import
OFS.metaconfigure
import
Products
return
(
getattr
(
Products
,
'meta_types'
,
_marker
),
OFS
.
metaconfigure
.
_register_monkies
,
OFS
.
metaconfigure
.
_meta_type_regs
,
)
def
test_minimal
(
self
):
klass
=
self
.
_makeClass
()
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
)
self
.
assertEqual
(
klass
.
meta_type
,
'Dummy'
)
mt
,
monkies
,
mt_regs
=
self
.
_getRegistered
()
self
.
assertEqual
(
len
(
mt
),
1
)
self
.
assertEqual
(
mt
[
0
][
'name'
],
'Dummy'
)
self
.
assertEqual
(
mt
[
0
][
'action'
],
''
)
self
.
assertEqual
(
mt
[
0
][
'product'
],
'OFS'
)
# XXX why?
self
.
assertEqual
(
mt
[
0
][
'permission'
],
'Perm'
)
self
.
assertEqual
(
mt
[
0
][
'visibility'
],
None
)
self
.
assertEqual
(
mt
[
0
][
'interfaces'
],
())
self
.
assertEqual
(
mt
[
0
][
'instance'
],
klass
)
self
.
assertEqual
(
mt
[
0
][
'container_filter'
],
None
)
def
test_w_icon
(
self
):
klass
=
self
.
_makeClass
()
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
,
icon
=
'dummy.png'
)
self
.
assertEqual
(
klass
.
icon
,
'++resource++dummy.png'
)
def
test_w_global_
(
self
):
klass
=
self
.
_makeClass
()
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
,
global_
=
True
)
mt
,
monkies
,
mt_regs
=
self
.
_getRegistered
()
self
.
assertEqual
(
len
(
mt
),
1
)
self
.
assertEqual
(
mt
[
0
][
'visibility'
],
'Global'
)
def
test_w_addview
(
self
):
klass
=
self
.
_makeClass
()
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
,
'adddummy'
)
mt
,
monkies
,
mt_regs
=
self
.
_getRegistered
()
self
.
assertEqual
(
len
(
mt
),
1
)
self
.
assertEqual
(
mt
[
0
][
'action'
],
'+/adddummy'
)
def
test_w_interfaces
(
self
):
from
zope.interface
import
Interface
class
IDummy
(
Interface
):
pass
klass
=
self
.
_makeClass
((
IDummy
,))
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
)
mt
,
monkies
,
mt_regs
=
self
.
_getRegistered
()
self
.
assertEqual
(
len
(
mt
),
1
)
self
.
assertEqual
(
mt
[
0
][
'interfaces'
],
(
IDummy
,))
def
test_minimal_no_Products_metatypes
(
self
):
import
Products
try
:
del
Products
.
meta_types
except
AttributeError
:
pass
klass
=
self
.
_makeClass
()
self
.
_registerPermission
(
'perm'
)
self
.
_callFUT
(
klass
,
'Dummy'
,
'perm'
)
self
.
assertEqual
(
klass
.
meta_type
,
'Dummy'
)
mt
,
monkies
,
mt_regs
=
self
.
_getRegistered
()
self
.
assertEqual
(
len
(
mt
),
1
)
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
Test__registerClass
),
))
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