Back to index

plone3  3.1.7
Classes | Functions
plone.i18n.negotiator.tests.test_negotiator Namespace Reference

Classes

class  Env
class  TestRequest

Functions

def configurationSetUp
def testDefaultNegotiator
def testFallbackOnDefaultNegotiator
def testBrowserNegotiator
def testAvailableLanguagesBrowserNegotiator
def test_suite

Function Documentation

Definition at line 37 of file test_negotiator.py.

00037 
00038 def configurationSetUp(self):
00039     setUp()
00040     XMLConfig('meta.zcml', zope.component)()
00041     XMLConfig('configure.zcml', plone.i18n.negotiator)()

Here is the call graph for this function:

Definition at line 146 of file test_negotiator.py.

00146 
00147 def test_suite():
00148     return unittest.TestSuite((
00149         DocTestSuite(setUp=configurationSetUp,
00150                      tearDown=tearDown,
00151                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00152         ))

  >>> negotiator = Negotiator()
  >>> from zope.publisher.browser import BrowserLanguages
  >>> negotiator[0] = BrowserLanguages

  >>> from plone.i18n.locales.interfaces import IContentLanguageAvailability
  >>> from plone.i18n.locales.languages import LanguageAvailability

  >>> from zope.component import getSiteManager
  >>> lang_avail = LanguageAvailability()

  >>> sm = getSiteManager()
  >>> sm.registerUtility(lang_avail, provided=IContentLanguageAvailability)

  >>> data = [
  ...    (('xy', ),  ('da, en, pt')),
  ...    (('xy', ), ('da, en;q=.9, en-gb;q=1.0, en-us')),
  ...    (('xy', ), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
  ... ]

  >>> for langs, req in data:
  ...    request = TestRequest(req)
  ...    negotiator.getLanguage(langs, request)
  'da'
  'da'
  'en'

Definition at line 116 of file test_negotiator.py.

00116 
00117 def testAvailableLanguagesBrowserNegotiator():
00118     """
00119       >>> negotiator = Negotiator()
00120       >>> from zope.publisher.browser import BrowserLanguages
00121       >>> negotiator[0] = BrowserLanguages
00122 
00123       >>> from plone.i18n.locales.interfaces import IContentLanguageAvailability
00124       >>> from plone.i18n.locales.languages import LanguageAvailability
00125 
00126       >>> from zope.component import getSiteManager
00127       >>> lang_avail = LanguageAvailability()
00128 
00129       >>> sm = getSiteManager()
00130       >>> sm.registerUtility(lang_avail, provided=IContentLanguageAvailability)
00131 
00132       >>> data = [
00133       ...    (('xy', ),  ('da, en, pt')),
00134       ...    (('xy', ), ('da, en;q=.9, en-gb;q=1.0, en-us')),
00135       ...    (('xy', ), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
00136       ... ]
00137 
00138       >>> for langs, req in data:
00139       ...    request = TestRequest(req)
00140       ...    negotiator.getLanguage(langs, request)
00141       'da'
00142       'da'
00143       'en'
00144     """
00145 

  >>> negotiator = Negotiator()
  >>> from zope.publisher.browser import BrowserLanguages
  >>> negotiator[0] = BrowserLanguages

  >>> data = [
  ...    (('da', 'en'),  ('da, en, pt')),
  ...    (('en-us', 'da'), ('da, en;q=.9, en-gb;q=1.0, en-us')),
  ...    (('en', 'pt-br'), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
  ...    (('en-gb', 'en-us'), ('en-us, en_GB;q=0.9, en, pt_BR; q=1.0')),
  ...    (('ro', 'fr'), ('ro,en-us;q=0.8,es;q=0.5,fr;q=0.3')),
  ...    (('es', 'ro'), ('ro,en-us;q=0,es;q=0.5,fr;q=0,ru;q=1,it'))
  ...    ]

  >>> for langs, req in data:
  ...    request = TestRequest(req)
  ...    negotiator.getLanguage(langs, request)
  'da'
  'da'
  'en'
  'en-us'
  'ro'
  'ro'

Definition at line 89 of file test_negotiator.py.

00089 
00090 def testBrowserNegotiator():
00091     """
00092       >>> negotiator = Negotiator()
00093       >>> from zope.publisher.browser import BrowserLanguages
00094       >>> negotiator[0] = BrowserLanguages
00095 
00096       >>> data = [
00097       ...    (('da', 'en'),  ('da, en, pt')),
00098       ...    (('en-us', 'da'), ('da, en;q=.9, en-gb;q=1.0, en-us')),
00099       ...    (('en', 'pt-br'), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
00100       ...    (('en-gb', 'en-us'), ('en-us, en_GB;q=0.9, en, pt_BR; q=1.0')),
00101       ...    (('ro', 'fr'), ('ro,en-us;q=0.8,es;q=0.5,fr;q=0.3')),
00102       ...    (('es', 'ro'), ('ro,en-us;q=0,es;q=0.5,fr;q=0,ru;q=1,it'))
00103       ...    ]
00104 
00105       >>> for langs, req in data:
00106       ...    request = TestRequest(req)
00107       ...    negotiator.getLanguage(langs, request)
00108       'da'
00109       'da'
00110       'en'
00111       'en-us'
00112       'ro'
00113       'ro'
00114     """
00115 

  >>> negotiator = Negotiator()

  >>> _cases = (
  ...    (('ca-es',), ('ca_ES', ), 'ca_ES'),
  ...    (('en','de'), ('en','de','fr'),  'en'),
  ...    (('en'),      ('it','de','fr'),  None),
  ...    (('pt-br','de'), ('pt_BR','de','fr'),  'pt_BR'),
  ...    (('pt-br','en-us', 'de'), ('de', 'en', 'fr'),  'en'),
  ...    )

  >>> for user_pref_langs, obj_langs, expected in _cases:
  ...     env = Env(user_pref_langs)
  ...     negotiator.getLanguage(obj_langs, env) is None
  True
  True
  True
  True
  True

Definition at line 42 of file test_negotiator.py.

00042 
00043 def testDefaultNegotiator():
00044     """
00045       >>> negotiator = Negotiator()
00046 
00047       >>> _cases = (
00048       ...    (('ca-es',), ('ca_ES', ), 'ca_ES'),
00049       ...    (('en','de'), ('en','de','fr'),  'en'),
00050       ...    (('en'),      ('it','de','fr'),  None),
00051       ...    (('pt-br','de'), ('pt_BR','de','fr'),  'pt_BR'),
00052       ...    (('pt-br','en-us', 'de'), ('de', 'en', 'fr'),  'en'),
00053       ...    )
00054 
00055       >>> for user_pref_langs, obj_langs, expected in _cases:
00056       ...     env = Env(user_pref_langs)
00057       ...     negotiator.getLanguage(obj_langs, env) is None
00058       True
00059       True
00060       True
00061       True
00062       True
00063     """
00064 

  >>> negotiator = Negotiator()

  >>> from zope.publisher.browser import BrowserLanguages
  >>> negotiator[0] = BrowserLanguages

  >>> data = [
  ...    (('pt', 'en'),  ('pt_BR, en')),
  ...    (('en-us', 'da'), ('da, en;q=.9, en-gb;q=1.0, en-us')),
  ...    (('en', 'pt-br'), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
  ...    (('en-gb', 'en-us'), ('en-us, en_GB;q=0.9, en, pt_BR; q=1.0')),
  ...    ]

  >>> for langs, req in data:
  ...    request = TestRequest(req)
  ...    negotiator.getLanguage(langs, request)
  'en'
  'da'
  'en'
  'en-us'

Definition at line 65 of file test_negotiator.py.

00065 
00066 def testFallbackOnDefaultNegotiator():
00067     """
00068       >>> negotiator = Negotiator()
00069 
00070       >>> from zope.publisher.browser import BrowserLanguages
00071       >>> negotiator[0] = BrowserLanguages
00072 
00073       >>> data = [
00074       ...    (('pt', 'en'),  ('pt_BR, en')),
00075       ...    (('en-us', 'da'), ('da, en;q=.9, en-gb;q=1.0, en-us')),
00076       ...    (('en', 'pt-br'), ('pt_BR; q=0.6, pt_PT; q = .7, en-gb')),
00077       ...    (('en-gb', 'en-us'), ('en-us, en_GB;q=0.9, en, pt_BR; q=1.0')),
00078       ...    ]
00079 
00080       >>> for langs, req in data:
00081       ...    request = TestRequest(req)
00082       ...    negotiator.getLanguage(langs, request)
00083       'en'
00084       'da'
00085       'en'
00086       'en-us'
00087     """
00088