-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from NextThought/premature-optimization
Handle INamedExternalizedOFF being different from IInternalObjectUpdater
- Loading branch information
Showing
4 changed files
with
87 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/nti/externalization/internalization/tests/test_updater.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tests for updater.py | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
|
||
# disable: accessing protected members, too many methods | ||
# pylint: disable=W0212,R0904 | ||
|
||
import unittest | ||
|
||
from zope import interface | ||
from zope import component | ||
|
||
from zope.testing.cleanup import CleanUp | ||
|
||
from hamcrest import assert_that | ||
from hamcrest import has_property | ||
|
||
from nti.externalization import interfaces | ||
|
||
from nti.externalization.internalization import updater | ||
|
||
class TestUpdater(CleanUp, | ||
unittest.TestCase): | ||
|
||
def test_less_specific_named_externalizer_doesnt_trump_specific_updater(self): | ||
|
||
class CreateCount(object): | ||
created = 0 | ||
def __init__(self, context): | ||
type(self).created += 1 | ||
|
||
@interface.implementer(interfaces.IInternalObjectIOFinder) | ||
@component.adapter(object) | ||
class NEOFF(CreateCount): | ||
created = 0 | ||
found = 0 | ||
|
||
def find_factory_for_named_value(self, *args): | ||
NEOFF.found += 1 | ||
return None | ||
|
||
class DomainObject(object): | ||
pass | ||
|
||
@interface.implementer(interfaces.IInternalObjectUpdater) | ||
@component.adapter(DomainObject) | ||
class CorrectUpdater(CreateCount): | ||
created = 0 | ||
updated = 0 | ||
def updateFromExternalObject(self, *args): | ||
CorrectUpdater.updated += 1 | ||
|
||
component.provideAdapter(CorrectUpdater) | ||
component.provideAdapter(NEOFF) | ||
|
||
ext = {'a': object()} | ||
domain = DomainObject() | ||
updater.update_from_external_object(domain, ext, require_updater=True) | ||
|
||
assert_that(NEOFF, has_property('created', 1)) | ||
assert_that(NEOFF, has_property('found', 1)) | ||
assert_that(CorrectUpdater, has_property('created', 1)) | ||
assert_that(CorrectUpdater, has_property('updated', 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters