Back to index

plone3  3.1.7
test_adapters.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     Adapters tests.
00004 """
00005 
00006 import unittest
00007 
00008 from zope.component.testing import setUp, tearDown
00009 from zope.configuration.xmlconfig import XMLConfig
00010 from zope.publisher.browser import BrowserLanguages
00011 from zope.publisher.browser import TestRequest
00012 
00013 from zope.testing import doctest
00014 from zope.testing.doctestunit import DocTestSuite
00015 
00016 from plone.i18n.normalizer.adapters import UserPreferredFileNameNormalizer
00017 from plone.i18n.normalizer.adapters import UserPreferredURLNormalizer
00018 
00019 
00020 def configurationSetUp(self):
00021     import plone.i18n.normalizer
00022     import zope.component
00023     setUp()
00024     XMLConfig('meta.zcml', zope.component)()
00025     XMLConfig('configure.zcml', plone.i18n.normalizer)()
00026     zope.component.provideAdapter(BrowserLanguages)
00027 
00028 
00029 def testUserPreferredFileNameNormalizer():
00030     """
00031     Create a German and English request and filename normalizer:
00032 
00033       >>> de_request = TestRequest(environ=dict(HTTP_ACCEPT_LANGUAGE = 'de'))
00034       >>> de_filename = UserPreferredFileNameNormalizer(de_request)
00035 
00036       >>> en_request = TestRequest(environ=dict(HTTP_ACCEPT_LANGUAGE = 'en'))
00037       >>> en_filename = UserPreferredFileNameNormalizer(en_request)
00038 
00039     Test the German normalization:
00040 
00041       >>> de_filename.normalize(u'simpleandsafe')
00042       'simpleandsafe'
00043 
00044       >>> de_filename.normalize(unicode('text with umläut', 'utf-8'))
00045       'text with umlaeut'
00046 
00047     Test the English normalization:
00048 
00049       >>> en_filename.normalize(u'simpleandsafe')
00050       'simpleandsafe'
00051 
00052       >>> en_filename.normalize(unicode('text with umläut', 'utf-8'))
00053       'text with umlaeut'
00054     """
00055 
00056 
00057 def testUserPreferredURLNormalizer():
00058     """
00059     Create a German and English request and url normalizer:
00060 
00061       >>> de_request = TestRequest(environ=dict(HTTP_ACCEPT_LANGUAGE = 'de'))
00062       >>> de_url = UserPreferredURLNormalizer(de_request)
00063 
00064       >>> en_request = TestRequest(environ=dict(HTTP_ACCEPT_LANGUAGE = 'en'))
00065       >>> en_url = UserPreferredURLNormalizer(en_request)
00066 
00067     Test the German normalization:
00068 
00069       >>> de_url.normalize(u'simpleandsafe')
00070       'simpleandsafe'
00071 
00072       >>> de_url.normalize(unicode('text with umläut', 'utf-8'))
00073       'text-with-umlaeut'
00074 
00075     Test the English normalization:
00076 
00077       >>> en_url.normalize(u'simpleandsafe')
00078       'simpleandsafe'
00079 
00080       >>> en_url.normalize(unicode('text with umläut', 'utf-8'))
00081       'text-with-umlaeut'
00082     """
00083 
00084 
00085 def test_suite():
00086     return unittest.TestSuite((
00087         DocTestSuite(setUp=configurationSetUp,
00088                      tearDown=tearDown,
00089                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00090         ))
00091 
00092 if __name__ == '__main__':
00093     unittest.main(defaultTest="test_suite")