Back to index

plone3  3.1.7
test_path.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, pathlist):
00019         self["TraversalRequestNameStack"] = pathlist
00020 
00021 
00022 def configurationSetUp(self):
00023     setUp()
00024     XMLConfig('meta.zcml', zope.component)()
00025 
00026 
00027 def testPathNegotiator():
00028     """
00029       >>> from plone.i18n.negotiator.negotiator import Negotiator
00030       >>> negotiator = Negotiator()
00031       >>> from plone.i18n.negotiator.path import PathLanguage
00032       >>> negotiator[0] = PathLanguage
00033 
00034       >>> from plone.i18n.locales.interfaces import ILanguageAvailability
00035       >>> from plone.i18n.locales.languages import LanguageAvailability
00036 
00037       >>> from zope.component import getSiteManager
00038       >>> lang_avail = LanguageAvailability()
00039 
00040       >>> sm = getSiteManager()
00041       >>> sm.registerUtility(lang_avail, provided=ILanguageAvailability)
00042 
00043       >>> data = [
00044       ...    (('de', 'en'),  ['portal', 'de', 'folder', 'object']),
00045       ...    (('en', 'fi'), ['portal', 'en-us', 'fi', 'folder', 'object']),
00046       ...    (('ca', 'pt'), ['portal', 'ca', 'folder', 'object']),
00047       ... ]
00048 
00049       >>> for langs, path in data:
00050       ...    request = TestRequest(path)
00051       ...    negotiator.getLanguage(langs, request)
00052       'de'
00053       'fi'
00054       'ca'
00055     """
00056 
00057 
00058 def test_suite():
00059     return unittest.TestSuite((
00060         DocTestSuite(setUp=configurationSetUp,
00061                      tearDown=tearDown,
00062                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00063         ))
00064 
00065 if __name__ == '__main__':
00066     unittest.main(defaultTest="test_suite")