l.s.w.t.test_helpers : module documentation

Part of lp.services.worlddata.tests

No module docstring
Class DummyLanguage Undocumented
Class DummyLanguageSet Undocumented
Class DummyPerson Undocumented
Class DummyResponse Undocumented
Class DummyRequest Undocumented
Function adaptRequestToLanguages Undocumented
Class DummyRequestLanguages Undocumented
Class DummyLaunchBag Undocumented
Function test_preferred_or_request_languages
>>> from zope.app.testing.placelesssetup import setUp, tearDown
Function test_is_english_variant
>>> from lp.services.worlddata.helpers import is_english_variant
Function test_suite Undocumented
def adaptRequestToLanguages(request):
Undocumented
def test_preferred_or_request_languages():
>>> from zope.app.testing.placelesssetup import setUp, tearDown
>>> from zope.component import provideAdapter, provideUtility
>>> 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@canonical.com', dummyPerson), ILaunchBag)
>>> provideAdapter(
...     adaptRequestToLanguages, (IBrowserRequest,),
...     IRequestPreferredLanguages)
>>> provideAdapter(
...     adaptRequestToLanguages, (IBrowserRequest,),
...     IRequestLocalLanguages)
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
1
>>> languages[0].code
'es'
>>> tearDown()

Then test with a person who has no preferred language.

>>> setUp()
>>> provideUtility(DummyLanguageSet(), ILanguageSet)
>>> provideUtility(
...     DummyLaunchBag('foo.bar@canonical.com', dummyNoLanguagePerson),
...     ILaunchBag)
>>> provideAdapter(
...     adaptRequestToLanguages, (IBrowserRequest,),
...     IRequestPreferredLanguages)
>>> provideAdapter(
...     adaptRequestToLanguages, (IBrowserRequest,),
...     IRequestLocalLanguages)
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
6
>>> 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():
Undocumented
API Documentation for Launchpad, generated by pydoctor at 2018-10-17 00:00:11.