Skip to content

Commit

Permalink
Merge pull request #26 from NextThought/coverage
Browse files Browse the repository at this point in the history
Fix target site bug; 100% coverage
  • Loading branch information
jzuech3 committed May 6, 2019
2 parents c0f767a + 0f27fa5 commit 3136430
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/nti/site/site.py
Expand Up @@ -379,9 +379,10 @@ def get_target_site(self):
"""
Returns the target site as defined by this mapping.
"""
current_site = getSite()
site_names = (self.target_site_name,)
result = get_site_for_site_names(site_names, site=None)
if result is None:
result = get_site_for_site_names(site_names, site=current_site)
if result is current_site:
# Invalid mapping
raise SiteNotFoundError("No site found for %s" % self.target_site_name)
return result
Expand Down
38 changes: 29 additions & 9 deletions src/nti/site/tests/test_site.py
Expand Up @@ -46,11 +46,11 @@
from nti.site.interfaces import IHostPolicyFolder
from nti.site.subscribers import threadSiteSubscriber
from nti.site.transient import HostSiteManager as HSM
from ..transient import TrivialSite
from ..site import get_site_for_site_names
from ..site import find_site_components
from ..site import get_component_hierarchy
from ..site import get_component_hierarchy_names
from nti.site.transient import TrivialSite
from nti.site.site import get_site_for_site_names
from nti.site.site import find_site_components
from nti.site.site import get_component_hierarchy
from nti.site.site import get_component_hierarchy_names

from nti.site.tests import SharedConfiguringTestLayer

Expand Down Expand Up @@ -229,10 +229,9 @@ def __init__(self):
x = list(get_component_hierarchy_names(site, reverse=True))
assert_that(x, is_(['1', '2']))

from ..site import BTreeLocalSiteManager as BLSM
from ..site import _LocalAdapterRegistry
from ..site import BTreeLocalAdapterRegistry
from ..site import WrongRegistrationTypeError
from nti.site.site import BTreeLocalSiteManager as BLSM
from nti.site.site import _LocalAdapterRegistry
from nti.site.site import BTreeLocalAdapterRegistry

from ZODB import DB
from ZODB.DemoStorage import DemoStorage
Expand Down Expand Up @@ -586,6 +585,27 @@ def test_convert_with_adapter_registered_on_class(self):
x = comps.getMultiAdapter((object(), 'str'), IFoo)
assert_that(x, is_(1))

def test_convert_mark_self_changed(self):
comps = BLSM(None)

comps.btree_threshold = 0
comps.adapters.btree_map_threshold = 1
comps.adapters.btree_provided_threshold = 0
comps.utilities.btree_map_threshold = 0

comps.registerAdapter(
_foo_factory,
required=(object, type('str')),
provided=IFoo)

comps.registerAdapter(
_foo_factory2,
required=(object, type(0)),
provided=IFoo)

x = comps.getMultiAdapter((object(), 'str'), IFoo)
assert_that(x, is_(1))


def _foo_factory(*args):
return 1
Expand Down
9 changes: 9 additions & 0 deletions src/nti/site/tests/test_sync.py
Expand Up @@ -37,6 +37,7 @@
from zope.location.interfaces import LocationError

from nti.site.interfaces import ISiteMapping
from nti.site.interfaces import SiteNotFoundError
from nti.site.interfaces import IHostPolicyFolder

from nti.site.site import SiteMapping
Expand Down Expand Up @@ -371,11 +372,19 @@ def test_site_mapping(self):
BASE.registerUtility(site_mapping,
provided=ISiteMapping,
name=transient_site)
assert_that(site_mapping.get_target_site(),
is_(same_instance(sites[DEMOALPHA.__name__])))

for site_name in (transient_site, DEMOALPHA.__name__):
result = get_site_for_site_names((site_name,))
assert_that(result, is_(same_instance(sites[DEMOALPHA.__name__])))

# Invalid mapping raises
site_mapping = SiteMapping(source_site_name=transient_site,
target_site_name=u'nonexistent_site')
assert_that(calling(site_mapping.get_target_site),
raises(SiteNotFoundError))

# We can also map persistent sites.
site_mapping = SiteMapping(source_site_name=DEMOALPHA.__name__,
target_site_name=DEMO.__name__)
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Expand Up @@ -16,3 +16,14 @@ commands =
deps =
{[testenv]deps}
.[docs]

[testenv:coverage]
usedevelop = true
basepython =
python3.6
commands =
coverage run -m zope.testrunner --test-path=src []
coverage report --fail-under=100
deps =
{[testenv]deps}
coverage

0 comments on commit 3136430

Please sign in to comment.