Back to index

plone3  3.1.7
test_tld.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     Negotiator tests.
00004 """
00005 
00006 import unittest
00007 
00008 import zope.component
00009 from zope.component.testing import setUp, tearDown
00010 from zope.configuration.xmlconfig import XMLConfig
00011 
00012 from zope.testing import doctest
00013 from zope.testing.doctestunit import DocTestSuite
00014 
00015 
00016 class TestRequest(dict):
00017 
00018     def __init__(self, host):
00019         self["HTTP_HOST"] = host
00020 
00021 
00022 def configurationSetUp(self):
00023     setUp()
00024     XMLConfig('meta.zcml', zope.component)()
00025 
00026 
00027 def testTldNegotiator():
00028     """
00029       >>> from plone.i18n.negotiator.negotiator import Negotiator
00030       >>> negotiator = Negotiator()
00031       >>> from plone.i18n.negotiator.tld import TldLanguage
00032       >>> negotiator[0] = TldLanguage
00033 
00034       >>> from plone.i18n.locales.interfaces import ICcTLDInformation
00035       >>> from plone.i18n.locales.interfaces import ILanguageAvailability
00036       >>> from plone.i18n.locales.cctld import CcTLDInformation
00037       >>> from plone.i18n.locales.languages import LanguageAvailability
00038 
00039       >>> request = TestRequest('www.plone.de')
00040       >>> negotiator.getLanguage(('de', ), request) is None
00041       True
00042 
00043       >>> from zope.component import getSiteManager
00044       >>> lang_avail = LanguageAvailability()
00045       >>> cctld = CcTLDInformation()
00046 
00047       >>> sm = getSiteManager()
00048       >>> sm.registerUtility(lang_avail, provided=ILanguageAvailability)
00049       >>> sm.registerUtility(cctld, provided=ICcTLDInformation)
00050 
00051       >>> data = [
00052       ...    (('de', 'en'),  'www.plone.org'),
00053       ...    (('en', 'fi'), 'www.plone.fi'),
00054       ...    (('ca', 'pt'), 'www.plone.pt'),
00055       ...    (('ca', 'pt'), 'www.plone.pt:8081'),
00056       ... ]
00057 
00058       >>> for langs, host in data:
00059       ...    request = TestRequest(host)
00060       ...    negotiator.getLanguage(langs, request)
00061       'fi'
00062       'pt'
00063       'pt'
00064     """
00065 
00066 
00067 def test_suite():
00068     return unittest.TestSuite((
00069         DocTestSuite(setUp=configurationSetUp,
00070                      tearDown=tearDown,
00071                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00072         ))
00073 
00074 if __name__ == '__main__':
00075     unittest.main(defaultTest="test_suite")