Back to index

plone3  3.1.7
test_subdomain.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 testSubdomainNegotiator():
00028     """
00029       >>> from plone.i18n.negotiator.negotiator import Negotiator
00030       >>> negotiator = Negotiator()
00031       >>> from plone.i18n.negotiator.subdomain import SubdomainLanguage
00032       >>> negotiator[0] = SubdomainLanguage
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('de.plone.org')
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, ILanguageAvailability)
00049       >>> sm.registerUtility(cctld, ICcTLDInformation)
00050 
00051       >>> data = [
00052       ...    (('de', 'en'), None),
00053       ...    (('de', 'en'), ''),
00054       ...    (('de', 'en'), 'www.plone.org'),
00055       ...    (('de', 'en'), 'de.plone.org'),
00056       ...    (('fi', 'en'), 'fi.plone.org'),
00057       ...    (('pt', 'en'), 'pt.plone.org:8081'),
00058       ... ]
00059 
00060       >>> for langs, host in data:
00061       ...    request = TestRequest(host)
00062       ...    print negotiator.getLanguage(langs, request)
00063       None
00064       None
00065       None
00066       de
00067       fi
00068       pt
00069     """
00070 
00071 
00072 def test_suite():
00073     return unittest.TestSuite((
00074         DocTestSuite(setUp=configurationSetUp,
00075                      tearDown=tearDown,
00076                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00077         ))
00078 
00079 if __name__ == '__main__':
00080     unittest.main(defaultTest="test_suite")