Back to index

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

Classes

class  TestRequest

Functions

def configurationSetUp
def testCookieNegotiator
def test_suite

Function Documentation

Definition at line 23 of file test_cookie.py.

00023 
00024 def configurationSetUp(self):
00025     setUp()
00026     XMLConfig('meta.zcml', zope.component)()
00027 

Here is the call graph for this function:

Definition at line 62 of file test_cookie.py.

00062 
00063 def test_suite():
00064     return unittest.TestSuite((
00065         DocTestSuite(setUp=configurationSetUp,
00066                      tearDown=tearDown,
00067                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00068         ))

  >>> from plone.i18n.negotiator.negotiator import Negotiator
  >>> negotiator = Negotiator()
  >>> from plone.i18n.negotiator.cookie import CookieLanguage
  >>> negotiator[0] = CookieLanguage

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

  >>> request = TestRequest('de')
  >>> negotiator.getLanguage(('de', ), request) is None
  True

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

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

  >>> data = [
  ...    (('de', 'en'),  'de'),
  ...    (('en', 'fi'), 'fi'),
  ...    (('ca', 'pt'), 'pt_BR'),
  ... ]

  >>> for langs, cookie in data:
  ...    request = TestRequest(cookie)
  ...    negotiator.getLanguage(langs, request)
  'de'
  'fi'

Definition at line 28 of file test_cookie.py.

00028 
00029 def testCookieNegotiator():
00030     """
00031       >>> from plone.i18n.negotiator.negotiator import Negotiator
00032       >>> negotiator = Negotiator()
00033       >>> from plone.i18n.negotiator.cookie import CookieLanguage
00034       >>> negotiator[0] = CookieLanguage
00035 
00036       >>> from plone.i18n.locales.interfaces import ILanguageAvailability
00037       >>> from plone.i18n.locales.languages import LanguageAvailability
00038 
00039       >>> request = TestRequest('de')
00040       >>> negotiator.getLanguage(('de', ), request) is None
00041       True
00042 
00043       >>> from zope.component import getSiteManager
00044       >>> lang_avail = LanguageAvailability()
00045 
00046       >>> sm = getSiteManager()
00047       >>> sm.registerUtility(lang_avail, provided=ILanguageAvailability)
00048 
00049       >>> data = [
00050       ...    (('de', 'en'),  'de'),
00051       ...    (('en', 'fi'), 'fi'),
00052       ...    (('ca', 'pt'), 'pt_BR'),
00053       ... ]
00054 
00055       >>> for langs, cookie in data:
00056       ...    request = TestRequest(cookie)
00057       ...    negotiator.getLanguage(langs, request)
00058       'de'
00059       'fi'
00060     """
00061