Back to index

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

Classes

class  TestRequest

Functions

def configurationSetUp
def testTldNegotiator
def test_suite

Function Documentation

Definition at line 22 of file test_tld.py.

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

Here is the call graph for this function:

Definition at line 67 of file test_tld.py.

00067 
00068 def test_suite():
00069     return unittest.TestSuite((
00070         DocTestSuite(setUp=configurationSetUp,
00071                      tearDown=tearDown,
00072                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00073         ))

  >>> from plone.i18n.negotiator.negotiator import Negotiator
  >>> negotiator = Negotiator()
  >>> from plone.i18n.negotiator.tld import TldLanguage
  >>> negotiator[0] = TldLanguage

  >>> from plone.i18n.locales.interfaces import ICcTLDInformation
  >>> from plone.i18n.locales.interfaces import ILanguageAvailability
  >>> from plone.i18n.locales.cctld import CcTLDInformation
  >>> from plone.i18n.locales.languages import LanguageAvailability

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

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

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

  >>> data = [
  ...    (('de', 'en'),  'www.plone.org'),
  ...    (('en', 'fi'), 'www.plone.fi'),
  ...    (('ca', 'pt'), 'www.plone.pt'),
  ...    (('ca', 'pt'), 'www.plone.pt:8081'),
  ... ]

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

Definition at line 27 of file test_tld.py.

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