Esempio n. 1
0
    def test_request_default_language(self, rf):
        LanguageFactory(code='en', is_default=True, live=True)
        LanguageFactory(code='fr', is_default=False, live=True)

        request = rf.get('/home/')
        TranslationMiddleware().process_request(request)
        assert request.LANGUAGE_CODE == 'en'
Esempio n. 2
0
    def test_request_language_from_header_partial_match(self, rf):
        Language.objects.all().delete()
        LanguageFactory(code='nl', is_default=True, live=True)
        LanguageFactory(code='en', is_default=False, live=True)

        request = rf.get('/', HTTP_ACCEPT_LANGUAGE='en-GB')
        TranslationMiddleware().process_request(request)

        assert request.LANGUAGE_CODE == 'en'
Esempio n. 3
0
    def test_request_language_from_header_multiple_first_unavailable(self, rf):
        Language.objects.all().delete()
        LanguageFactory(code='fr', is_default=True, live=True)
        LanguageFactory(code='es', is_default=False, live=True)
        languages = 'nl,en-GB;q=0.8,en;q=0.6,es-419;q=0.4,es;q=0.2'

        request = rf.get('/', HTTP_ACCEPT_LANGUAGE=languages)
        TranslationMiddleware().process_request(request)

        assert request.LANGUAGE_CODE == 'es'
Esempio n. 4
0
    def test_prefer_cookie_over_default_and_accept_header_in_request(self, rf):
        Language.objects.all().delete()
        LanguageFactory(code='en', is_default=True, live=True)
        LanguageFactory(code='fr', is_default=False, live=True)
        LanguageFactory(code='nl', is_default=False, live=True)

        request = rf.get('/', HTTP_ACCEPT_LANGUAGE='fr')
        request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = 'nl'
        TranslationMiddleware().process_request(request)
        assert request.LANGUAGE_CODE == 'nl'
Esempio n. 5
0
    def test_switch_language(self):
        LanguageFactory(is_default=True)
        new_default = LanguageFactory(code='nl', is_default=False)
        form = self.form_class(instance=new_default, data={
            'code': new_default.code,
            'position': new_default.position,
            'is_default': True,
        })

        assert form.is_valid()
        new_default = form.save()
        assert new_default.is_default
Esempio n. 6
0
    def test_has_pages_in_site(self):
        language = LanguageFactory()

        site_one = SiteFactory(hostname='remotehost', site_name='RemoteSite', root_page__title='site_1')
        site_two = SiteFactory(hostname='losthost', site_name='LostSite', root_page__title='site_2')

        create_site_tree(language, site=site_one, subtitle='hophop flepflep')
        create_site_tree(language, site=site_two, subtitle='hophop flepflep')

        language.refresh_from_db()

        assert language.has_pages_in_site(site_one)
        assert language.has_pages_in_site(site_two)
Esempio n. 7
0
    def test_clean_is_default(self):
        language = LanguageFactory(is_default=True)
        form = self.form_class(instance=language, data={
            'code': language.code,
            'position': language.position,
            'is_default': True,
        })

        assert form.is_valid()
Esempio n. 8
0
    def test_remove_is_default(self):
        language = LanguageFactory(is_default=True)
        form = self.form_class(instance=language, data={
            'code': language.code,
            'position': language.position,
            'is_default': False,
        })

        assert not form.is_valid()
        assert 'is_default' in form.errors
Esempio n. 9
0
 def test_str(self):
     language = LanguageFactory()
     assert six.text_type(language) == 'British English'