Skip to content

Commit

Permalink
Merge pull request #135 from plone/fix-tests-ziface
Browse files Browse the repository at this point in the history
fix to use with fixed zope.interface
  • Loading branch information
jensens authored Sep 30, 2020
2 parents 8d8b49c + 03da1ef commit b9385b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 5 additions & 0 deletions news/135.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixes test to work clean with zope.interface.
Interfaces are hashed based on just their name and module.
So every one of these local `IBlank` interfaces will hash the same way, and be treated the same for purposes of zope.interface's `_dependents`.
Thus in tests mock interfaces must not be used under the same name in the same module.
[jensens]
31 changes: 17 additions & 14 deletions plone/dexterity/tests/test_fti.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,12 @@ class INew(Interface):
)
self.mock_utility(site_dummy, ISiteRoot)

class IBlank(Interface):
class IBlank1(Interface):
pass

# Set source interface
schemaName = portalTypeToSchemaName(fti.getId())
setattr(plone.dexterity.schema.generated, schemaName, IBlank)
setattr(plone.dexterity.schema.generated, schemaName, IBlank1)

# Sync this with schema
ftiModified(
Expand All @@ -666,8 +666,8 @@ class IBlank(Interface):
)
)

self.assertTrue('title' in IBlank)
self.assertTrue(IBlank['title'].title == u"title")
self.assertTrue('title' in IBlank1)
self.assertTrue(IBlank1['title'].title == u"title")

def test_dynamic_schema_refreshed_on_modify_model_source(self):
portal_type = u"testtype"
Expand All @@ -686,12 +686,15 @@ class INew(Interface):
)
self.mock_utility(site_dummy, ISiteRoot)

class IBlank(Interface):
# b/c of zope.interface does not support hashing of the same class multiple times
# we need to postfix with a unique number
# see https://github.com/zopefoundation/zope.interface/issues/216#issuecomment-701332380
class IBlank2(Interface):
pass

# Set source interface
schemaName = portalTypeToSchemaName(fti.getId())
setattr(plone.dexterity.schema.generated, schemaName, IBlank)
setattr(plone.dexterity.schema.generated, schemaName, IBlank2)

# Sync this with schema
ftiModified(
Expand All @@ -702,8 +705,8 @@ class IBlank(Interface):
)
)

self.assertTrue('title' in IBlank)
self.assertTrue(IBlank['title'].title == u"title")
self.assertTrue('title' in IBlank2)
self.assertTrue(IBlank2['title'].title == u"title")

def test_dynamic_schema_refreshed_on_modify_schema_policy(self):
portal_type = u"testtype"
Expand All @@ -712,7 +715,7 @@ def test_dynamic_schema_refreshed_on_modify_schema_policy(self):
class INew(Interface):
title = zope.schema.TextLine(title=u"title")

class IBlank(Interface):
class IBlank3(Interface):
pass

class TestSchemaPolicy(DexteritySchemaPolicy):
Expand All @@ -734,7 +737,7 @@ def bases(self, schemaName, tree):

# Set source interface
schemaName = portalTypeToSchemaName(fti.getId())
setattr(plone.dexterity.schema.generated, schemaName, IBlank)
setattr(plone.dexterity.schema.generated, schemaName, IBlank3)
original = getattr(plone.dexterity.schema.generated, schemaName)
self.assertNotIn(INew, original.__bases__)
self.assertNotIn('title', original)
Expand All @@ -758,7 +761,7 @@ def test_concrete_schema_not_refreshed_on_modify_schema(self):
portal_type = u"testtype"
fti = DexterityFTI(portal_type)

class IBlank(Interface):
class IBlank4(Interface):
pass

class INew(Interface):
Expand All @@ -773,12 +776,12 @@ class INew(Interface):
self.mock_utility(site_dummy, ISiteRoot)

# Set schema to something so that hasDynamicSchema is false
fti.schema = IBlank.__identifier__
fti.schema = IBlank4.__identifier__
assert not fti.hasDynamicSchema

# Set source for dynamic FTI - should not be used
schemaName = portalTypeToSchemaName(fti.getId())
setattr(plone.dexterity.schema.generated, schemaName, IBlank)
setattr(plone.dexterity.schema.generated, schemaName, IBlank4)

# Sync should not happen now

Expand All @@ -790,7 +793,7 @@ class INew(Interface):
)
)

self.assertFalse('title' in IBlank)
self.assertFalse('title' in IBlank4)

def test_old_factory_unregistered_after_name_changed_if_dynamic(self):
portal_type = u"testtype"
Expand Down

0 comments on commit b9385b7

Please sign in to comment.