launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28766
[Merge] ~cjwatson/launchpad:remove-zope.container into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:remove-zope.container into launchpad:master.
Commit message:
Remove direct uses of zope.container
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/426613
Launchpad used `zope.container.testing` without a direct dependency on `zope.container`, which is clearly wrong. The point of this seems to have been to run some tests with the Zope component architecture set up; a clearer and more efficient way to do this is to put the relevant tests in `FunctionalLayer`.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-zope.container into launchpad:master.
diff --git a/lib/lp/services/webapp/tests/test_authutility.py b/lib/lp/services/webapp/tests/test_authutility.py
index 0ef13ae..9a4a0af 100644
--- a/lib/lp/services/webapp/tests/test_authutility.py
+++ b/lib/lp/services/webapp/tests/test_authutility.py
@@ -3,16 +3,13 @@
import base64
-import testtools
from zope.authentication.interfaces import ILoginPassword
from zope.component import getUtility
-from zope.container.testing import ContainerPlacelessSetup
from zope.interface import implementer
from zope.principalregistry.principalregistry import UnauthenticatedPrincipal
from zope.publisher.browser import TestRequest
from zope.publisher.http import BasicAuthAdapter
from zope.publisher.interfaces.http import IHTTPCredentials
-from zope.security.management import newInteraction
from zope.security.testing import addCheckerPublic
from lp.registry.interfaces.person import IPerson
@@ -26,10 +23,12 @@ from lp.services.webapp.interfaces import (
IPlacelessAuthUtility,
IPlacelessLoginSource,
)
+from lp.testing import TestCase
from lp.testing.fixture import (
ZopeAdapterFixture,
ZopeUtilityFixture,
)
+from lp.testing.layers import FunctionalLayer
@implementer(IPerson)
@@ -58,13 +57,13 @@ class DummyPlacelessLoginSource:
return [Bruce]
-class TestPlacelessAuth(ContainerPlacelessSetup, testtools.TestCase):
+class TestPlacelessAuth(TestCase):
+
+ layer = FunctionalLayer
def setUp(self):
- testtools.TestCase.setUp(self)
- ContainerPlacelessSetup.setUp(self)
+ super().setUp()
addCheckerPublic()
- newInteraction()
self.useFixture(ZopeUtilityFixture(
DummyPlacelessLoginSource(), IPlacelessLoginSource))
self.useFixture(ZopeUtilityFixture(
@@ -72,10 +71,6 @@ class TestPlacelessAuth(ContainerPlacelessSetup, testtools.TestCase):
self.useFixture(ZopeAdapterFixture(
BasicAuthAdapter, (IHTTPCredentials,), ILoginPassword))
- def tearDown(self):
- ContainerPlacelessSetup.tearDown(self)
- testtools.TestCase.tearDown(self)
-
def _make(self, login, pwd):
auth = base64.b64encode(
('%s:%s' % (login, pwd)).encode('ASCII')).decode('ASCII')
diff --git a/lib/lp/services/webapp/tests/test_doc.py b/lib/lp/services/webapp/tests/test_doc.py
index 654e063..fa82b88 100644
--- a/lib/lp/services/webapp/tests/test_doc.py
+++ b/lib/lp/services/webapp/tests/test_doc.py
@@ -32,8 +32,7 @@ special = {
'notification-text-escape.rst': LayeredDocFileSuite(
'../doc/notification-text-escape.rst',
setUp=test_notifications.setUp,
- tearDown=test_notifications.tearDown,
- stdout_logging=False, layer=None),
+ stdout_logging=False, layer=FunctionalLayer),
'test_adapter.rst': LayeredDocFileSuite(
'../doc/test_adapter.rst',
setUp=setGlobs,
diff --git a/lib/lp/services/webapp/tests/test_notifications.py b/lib/lp/services/webapp/tests/test_notifications.py
index 7ee572e..fda9346 100644
--- a/lib/lp/services/webapp/tests/test_notifications.py
+++ b/lib/lp/services/webapp/tests/test_notifications.py
@@ -7,10 +7,6 @@ from doctest import DocTestSuite
import unittest
from zope.component import provideAdapter
-from zope.container.testing import (
- setUp as containerSetUp,
- tearDown as containerTearDown,
- )
from zope.interface import implementer
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserRequest
@@ -26,6 +22,7 @@ from lp.services.webapp.interfaces import (
INotificationResponse,
)
from lp.services.webapp.notifications import NotificationResponse
+from lp.testing.layers import FunctionalLayer
@implementer(ISession)
@@ -69,7 +66,6 @@ def adaptNotificationRequestToResponse(request):
def setUp(test):
- containerSetUp()
mock_session = MockSession()
provideAdapter(lambda x: mock_session, (INotificationRequest,), ISession)
provideAdapter(lambda x: mock_session, (INotificationResponse,), ISession)
@@ -86,16 +82,14 @@ def setUp(test):
test.globs['structured'] = structured
-def tearDown(test):
- containerTearDown()
-
-
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(DocTestSuite(
+ doctest_suite = DocTestSuite(
'lp.services.webapp.notifications',
- setUp=setUp, tearDown=tearDown,
- ))
+ setUp=setUp,
+ )
+ doctest_suite.layer = FunctionalLayer
+ suite.addTest(doctest_suite)
return suite
diff --git a/lib/lp/services/worlddata/tests/test_helpers.py b/lib/lp/services/worlddata/tests/test_helpers.py
index d5e1580..f432a8b 100644
--- a/lib/lp/services/worlddata/tests/test_helpers.py
+++ b/lib/lp/services/worlddata/tests/test_helpers.py
@@ -1,15 +1,29 @@
# Copyright 2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-from doctest import DocTestSuite
-import unittest
-
from zope.interface import implementer
from zope.publisher.interfaces.browser import IBrowserRequest
from lp.registry.interfaces.person import IPerson
+from lp.services.geoip.interfaces import (
+ IRequestLocalLanguages,
+ IRequestPreferredLanguages,
+ )
from lp.services.webapp.interfaces import ILaunchBag
+from lp.services.worlddata.helpers import (
+ is_english_variant,
+ preferred_or_request_languages,
+ )
from lp.services.worlddata.interfaces.language import ILanguageSet
+from lp.testing import TestCase
+from lp.testing.fixture import (
+ ZopeAdapterFixture,
+ ZopeUtilityFixture,
+ )
+from lp.testing.layers import (
+ BaseLayer,
+ FunctionalLayer,
+ )
class DummyLanguage:
@@ -93,79 +107,56 @@ class DummyLaunchBag:
self.user = user
-def test_preferred_or_request_languages():
- '''
- >>> from zope.component import provideAdapter, provideUtility
- >>> from zope.container.testing import setUp, tearDown
- >>> from zope.i18n.interfaces import IUserPreferredLanguages
- >>> from lp.services.geoip.interfaces import IRequestPreferredLanguages
- >>> from lp.services.geoip.interfaces import IRequestLocalLanguages
- >>> from lp.services.worlddata.helpers import (
- ... preferred_or_request_languages)
-
- First, test with a person who has a single preferred language.
-
- >>> setUp()
- >>> provideUtility(DummyLanguageSet(), ILanguageSet)
- >>> provideUtility(
- ... DummyLaunchBag('foo.bar@xxxxxxxxxxxxx', dummyPerson), ILaunchBag)
- >>> provideAdapter(
- ... adaptRequestToLanguages, (IBrowserRequest,),
- ... IRequestPreferredLanguages)
- >>> provideAdapter(
- ... adaptRequestToLanguages, (IBrowserRequest,),
- ... IRequestLocalLanguages)
-
- >>> languages = preferred_or_request_languages(DummyRequest())
- >>> len(languages)
- 1
- >>> print(languages[0].code)
- es
-
- >>> tearDown()
-
- Then test with a person who has no preferred language.
-
- >>> setUp()
- >>> provideUtility(DummyLanguageSet(), ILanguageSet)
- >>> provideUtility(
- ... DummyLaunchBag('foo.bar@xxxxxxxxxxxxx', dummyNoLanguagePerson),
- ... ILaunchBag)
- >>> provideAdapter(
- ... adaptRequestToLanguages, (IBrowserRequest,),
- ... IRequestPreferredLanguages)
- >>> provideAdapter(
- ... adaptRequestToLanguages, (IBrowserRequest,),
- ... IRequestLocalLanguages)
-
- >>> languages = preferred_or_request_languages(DummyRequest())
- >>> len(languages)
- 6
- >>> print(languages[0].code)
- ja
-
- >>> tearDown()
- '''
-
-
-def test_is_english_variant():
- """
- >>> from lp.services.worlddata.helpers import is_english_variant
- >>> class Language:
- ... def __init__(self, code):
- ... self.code = code
- >>> is_english_variant(Language('fr'))
- False
- >>> is_english_variant(Language('en'))
- False
- >>> is_english_variant(Language('en_CA'))
- True
- >>> is_english_variant(Language('enm'))
- False
- """
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(DocTestSuite())
- return suite
+class TestPreferredOrRequestLanguages(TestCase):
+
+ layer = FunctionalLayer
+
+ def test_single_preferred_language(self):
+ # Test with a person who has a single preferred language.
+ self.useFixture(ZopeUtilityFixture(DummyLanguageSet(), ILanguageSet))
+ self.useFixture(ZopeUtilityFixture(
+ DummyLaunchBag("foo.bar@xxxxxxxxxxxxx", dummyPerson), ILaunchBag))
+ self.useFixture(ZopeAdapterFixture(
+ adaptRequestToLanguages, (IBrowserRequest,),
+ IRequestPreferredLanguages))
+ self.useFixture(ZopeAdapterFixture(
+ adaptRequestToLanguages, (IBrowserRequest,),
+ IRequestLocalLanguages))
+
+ languages = preferred_or_request_languages(DummyRequest())
+ self.assertEqual(1, len(languages))
+ self.assertEqual("es", languages[0].code)
+
+ def test_no_preferred_language(self):
+ # Test with a person who has no preferred language.
+ self.useFixture(ZopeUtilityFixture(DummyLanguageSet(), ILanguageSet))
+ self.useFixture(ZopeUtilityFixture(
+ DummyLaunchBag("foo.bar@xxxxxxxxxxxxx", dummyNoLanguagePerson),
+ ILaunchBag))
+ self.useFixture(ZopeAdapterFixture(
+ adaptRequestToLanguages, (IBrowserRequest,),
+ IRequestPreferredLanguages))
+ self.useFixture(ZopeAdapterFixture(
+ adaptRequestToLanguages, (IBrowserRequest,),
+ IRequestLocalLanguages))
+
+ languages = preferred_or_request_languages(DummyRequest())
+ self.assertEqual(6, len(languages))
+ self.assertEqual("ja", languages[0].code)
+
+
+class TestIsEnglishVariant(TestCase):
+
+ layer = BaseLayer
+
+ def test_fr(self):
+ self.assertFalse(is_english_variant(DummyLanguage("fr", 1)))
+
+ def test_en(self):
+ self.assertFalse(is_english_variant(DummyLanguage("en", 1)))
+
+ def test_en_CA(self):
+ self.assertTrue(is_english_variant(DummyLanguage("en_CA", 1)))
+
+ def test_enm(self):
+ self.assertFalse(is_english_variant(DummyLanguage("enm", 1)))