Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_request_site_language(self, rf):
        SiteLanguagesFactory(default_language__code='fr')

        request = rf.get('/random/page/')
        request.site = SiteFactory()
        with override_settings(WAGTAILTRANS_LANGUAGES_PER_SITE=True):
            TranslationMiddleware().process_request(request)

        assert request.LANGUAGE_CODE == 'fr'
Exemplo n.º 3
0
def test_get_languages_for_site(languages):
    site = SiteFactory()
    languages = sites.get_languages_for_site(site)

    language_codes = [l.code for l in languages]
    assert language_codes == ['en', 'es', 'fr', 'de', 'nl']

    site_lang = SiteLanguagesFactory(site=site, default_language=languages[0])
    site_lang.other_languages.add(languages[1], languages[2])

    with override_settings(WAGTAILTRANS_LANGUAGES_PER_SITE=True):
        language_codes = [l.code for l in sites.get_languages_for_site(site)]
        assert language_codes == ['en', 'es', 'fr']
Exemplo n.º 4
0
    def test_request_site_language(self, rf):
        SiteLanguagesFactory(default_language__code='fr')

        request = rf.get('/random/page/')

        # Backwards-compatible lookup for the deprecation of Wagtails SiteMiddleware per 2.9
        if 'wagtail.core.middleware.SiteMiddleware' in settings.MIDDLEWARE:
            request.site = SiteFactory()
        
        with override_settings(WAGTAILTRANS_LANGUAGES_PER_SITE=True):
            TranslationMiddleware().process_request(request)

        assert request.LANGUAGE_CODE == 'fr'
Exemplo n.º 5
0
    def test_get_translations(self, languages):
        site = SiteFactory()
        pages = create_site_tree(languages[0], site=site)
        for language in languages[1:]:
            create_site_tree(language, site=site)

        assert not hasattr(pages[0], 'language')
        translations = wagtailtrans_tags._get_translations(pages[0])

        language_codes = [l.code for l in translations.keys()]
        assert language_codes[0] == 'en'
        assert language_codes[1] == 'es'
        assert language_codes[2] == 'fr'
        assert language_codes[3] == 'de'
        assert language_codes[4] == 'nl'
Exemplo n.º 6
0
 def test_serve(self, rf):
     request = rf.get('/home/')
     request.site = SiteFactory()
     response = request.site.root_page.serve(request)
     assert response.status_code == 200