Back to index

plone3  3.1.7
test_languages.py
Go to the documentation of this file.
00001 # -*- coding: UTF-8 -*-
00002 """
00003     Languages tests.
00004 """
00005 
00006 import unittest
00007 
00008 import plone.i18n.locales
00009 from plone.i18n.locales.interfaces import IContentLanguageAvailability
00010 from plone.i18n.locales.interfaces import IMetadataLanguageAvailability
00011 
00012 import zope.app.publisher.browser
00013 import zope.component
00014 from zope.component import queryUtility
00015 from zope.component.testing import setUp, tearDown
00016 from zope.configuration.xmlconfig import XMLConfig
00017 from zope.testing import doctest
00018 from zope.testing.doctestunit import DocTestSuite
00019 
00020 def configurationSetUp(self):
00021     setUp()
00022     XMLConfig('meta.zcml', zope.component)()
00023     XMLConfig('meta.zcml', zope.app.publisher.browser)()
00024     XMLConfig('configure.zcml', plone.i18n.locales)()
00025 
00026 def testContentLanguageAvailability():
00027     """
00028       >>> util = queryUtility(IContentLanguageAvailability)
00029       >>> util
00030       <plone.i18n.locales.languages.ContentLanguageAvailability object at ...>
00031 
00032       >>> languagecodes = util.getAvailableLanguages()
00033       >>> len(languagecodes)
00034       148
00035 
00036       >>> u'de' in languagecodes
00037       True
00038 
00039       >>> languagecodes = util.getAvailableLanguages(combined=True)
00040       >>> len(languagecodes)
00041       373
00042 
00043       >>> u'pt-br' in languagecodes
00044       True
00045 
00046       >>> languages = util.getLanguages()
00047       >>> len(languages)
00048       148
00049 
00050       >>> de = languages[u'de']
00051       >>> de[u'name']
00052       u'German'
00053 
00054       >>> de[u'native']
00055       u'Deutsch'
00056 
00057       >>> de[u'flag']
00058       u'/++resource++country-flags/de.gif'
00059 
00060       >>> languages = util.getLanguageListing()
00061       >>> len(languages)
00062       148
00063 
00064       >>> (u'de', u'German') in languages
00065       True
00066 
00067       >>> languages = util.getLanguages(combined=True)
00068       >>> len(languages)
00069       373
00070 
00071       >>> pt_BR = languages[u'pt-br']
00072       >>> pt_BR[u'name']
00073       u'Portuguese (Brazil)'
00074     """
00075 
00076 def testMetadataLanguageAvailability():
00077     """
00078       >>> util = queryUtility(IMetadataLanguageAvailability)
00079       >>> util
00080       <plone.i18n.locales.languages.MetadataLanguageAvailability object at ...>
00081 
00082       >>> languagecodes = util.getAvailableLanguages()
00083       >>> len(languagecodes)
00084       148
00085 
00086       >>> u'de' in languagecodes
00087       True
00088 
00089       >>> languagecodes = util.getAvailableLanguages(combined=True)
00090       >>> len(languagecodes)
00091       373
00092 
00093       >>> u'pt-br' in languagecodes
00094       True
00095 
00096       >>> languages = util.getLanguages()
00097       >>> len(languages)
00098       148
00099 
00100       >>> de = languages[u'de']
00101       >>> de[u'name']
00102       u'German'
00103 
00104       >>> de[u'native']
00105       u'Deutsch'
00106 
00107       >>> de[u'flag']
00108       u'/++resource++country-flags/de.gif'
00109 
00110       >>> languages = util.getLanguageListing()
00111       >>> len(languages)
00112       148
00113 
00114       >>> (u'de', u'German') in languages
00115       True
00116 
00117       >>> languages = util.getLanguageListing(combined=True)
00118       >>> len(languages)
00119       373
00120 
00121       >>> (u'pt-br', u'Portuguese (Brazil)') in languages
00122       True
00123 
00124       >>> languages = util.getLanguageListing(combined=True)
00125       >>> len(languages)
00126       373
00127 
00128       >>> (u'pt-br', u'Portuguese (Brazil)') in languages
00129       True
00130 
00131       >>> languages = util.getLanguages(combined=True)
00132       >>> len(languages)
00133       373
00134 
00135       >>> pt_BR = languages[u'pt-br']
00136       >>> pt_BR[u'name']
00137       u'Portuguese (Brazil)'
00138     """
00139 
00140 
00141 def test_suite():
00142     return unittest.TestSuite((
00143         DocTestSuite('plone.i18n.locales.languages'),
00144         DocTestSuite(setUp=configurationSetUp,
00145                      tearDown=tearDown,
00146                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00147         ))
00148 
00149 if __name__ == '__main__':
00150     unittest.main(defaultTest="test_suite")