def test_get_language_using_another_default_language(self):
     language_middleware = LanguageMiddleware(self.app,
                                              default_language='fr',
                                              valid_languages=('en', 'es',
                                                               'fr'))
     environ = {}
     language_middleware.__call__(environ, None)
     self.assertEquals('fr', environ['HTTP_ACTIVE_LANGUAGE'])
 def test_script_name_setting(self):
     language_middleware = LanguageMiddleware(
         self.app,
         set_script_name = True)
     environ = {}
     language_middleware.__call__(environ, None)
     self.assertEquals('en', environ['HTTP_ACTIVE_LANGUAGE'])
     self.assertEquals('/en', environ['SCRIPT_NAME'])
 def test_get_language_from_headers_with_force_lang(self):
     language_middleware = LanguageMiddleware(self.app, force_lang=True)
     environ = {
         'PATH_INFO': '/documents/1',
         'HTTP_ACCEPT_LANGUAGE': 'es-cl,es;q=0.5'
     }
     language_middleware.__call__(environ, None)
     self.assertEquals('en', environ['HTTP_ACTIVE_LANGUAGE'])
 def test_get_language_using_another_default_language(self):
     language_middleware = LanguageMiddleware(
         self.app,
         default_language = 'fr',
         valid_languages = ('en', 'es', 'fr')
     )
     environ = {}
     language_middleware.__call__(environ, None)
     self.assertEquals('fr', environ['HTTP_ACTIVE_LANGUAGE'])
 def test_get_language_but_do_not_remove_language_part_from_url(self):
     language_middleware = LanguageMiddleware(self.app,
                                              default_language='fr',
                                              valid_languages=('en', 'es',
                                                               'fr'),
                                              clean_url=False)
     environ = {'PATH_INFO': '/es/documents'}
     language_middleware.__call__(environ, None)
     self.assertEquals('es', environ['HTTP_ACTIVE_LANGUAGE'])
     self.assertEquals('/es/documents', environ['PATH_INFO'])
 def test_get_language_but_do_not_remove_language_part_from_url(self):
     language_middleware = LanguageMiddleware(
         self.app,
         default_language = 'fr',
         valid_languages = ('en', 'es', 'fr'),
         clean_url = False
     )
     environ = {'PATH_INFO': '/es/documents'}
     language_middleware.__call__(environ, None)
     self.assertEquals('es', environ['HTTP_ACTIVE_LANGUAGE'])
     self.assertEquals('/es/documents', environ['PATH_INFO'])
 def test_use_correct_locale(self):
     def html(environ, start_response):
         from mako.template import Template
         return Template("${_('Hello World')}").render()
     locale_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fixtures/locale')
     language_middleware = LanguageMiddleware(
         html,
         default_language = 'fr',
         valid_languages = ('en', 'es', 'fr'),
         clean_url = False,
         locale_path = locale_path,
         locale_name = 'hello'
     )
     spanish_response = language_middleware.__call__({'PATH_INFO': '/es/documents'}, None)
     english_response = language_middleware.__call__({'PATH_INFO': '/en/documents'}, None)
     self.assertEquals('Hola Mundo', spanish_response)
     self.assertEquals('Hello World', english_response)
    def test_use_correct_locale(self):
        def html(environ, start_response):
            from mako.template import Template
            return Template("${_('Hello World')}").render()

        locale_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                   'fixtures/locale')
        language_middleware = LanguageMiddleware(html,
                                                 default_language='fr',
                                                 valid_languages=('en', 'es',
                                                                  'fr'),
                                                 clean_url=False,
                                                 locale_path=locale_path,
                                                 locale_name='hello')
        spanish_response = language_middleware.__call__(
            {'PATH_INFO': '/es/documents'}, None)
        english_response = language_middleware.__call__(
            {'PATH_INFO': '/en/documents'}, None)
        self.assertEquals('Hola Mundo', spanish_response)
        self.assertEquals('Hello World', english_response)
 def test_get_language_from_url_without_language(self):
     language_middleware = LanguageMiddleware(self.app)
     environ = {'PATH_INFO': '/documents/1'}
     language_middleware.__call__(environ, None)
     self.assertEquals('en', environ['HTTP_ACTIVE_LANGUAGE'])
     self.assertEquals('/documents/1', environ['PATH_INFO'])
 def test_get_language_from_headers_with_force_lang(self):
     language_middleware = LanguageMiddleware(self.app, force_lang=True)
     environ = {'PATH_INFO': '/documents/1', 'HTTP_ACCEPT_LANGUAGE': 'es-cl,es;q=0.5'}
     language_middleware.__call__(environ, None)
     self.assertEquals('en', environ['HTTP_ACTIVE_LANGUAGE'])
 def test_get_language_from_url_without_language(self):
     language_middleware = LanguageMiddleware(self.app)
     environ = {'PATH_INFO': '/documents/1'}
     language_middleware.__call__(environ, None)
     self.assertEquals('en', environ['HTTP_ACTIVE_LANGUAGE'])
     self.assertEquals('/documents/1', environ['PATH_INFO'])
Beispiel #12
0
# bottle.install(exception_handler)

# solr = SolrPlugin(solr_config)
# bottle.install(solr)

process_routes(ROUTES)

application = default_app.pop()
application.catchall = False

if not production:
    bottle.debug(True)

# application = ErrorHandler(
application = PostgresPlugin(
    LanguageMiddleware(StripPathMiddleware(application, production),
                       default_language='en',
                       valid_languages=map(lambda x: x[0], LANGUAGES),
                       clean_url=True
                       # ),
                       ),
    **postgres_config)

#    production = production,
#    email_config = email_config
# )

# if production:
#     import newrelic.agent
#     newrelic.agent.initialize('/home/production/configs/new_relic.ini', 'production')
#     application = newrelic.agent.wsgi_application()(application)