Exemplo n.º 1
0
def test_url_uniqueness(rf):
    page = create_page(url='bacon')
    with pytest.raises(ValidationError):
        page = create_page(url='bacon')

    with transaction.atomic():
        mpage = create_multilanguage_page(url="cheese")
        with pytest.raises(IntegrityError):
            mpage = create_multilanguage_page(url="cheese")
Exemplo n.º 2
0
def test_url_uniqueness(rf):
    page = create_page(url='bacon')
    with pytest.raises(ValidationError):
        page = create_page(url='bacon')

    with transaction.atomic():
        mpage = create_multilanguage_page(url="cheese")
        with pytest.raises(IntegrityError):
            mpage = create_multilanguage_page(url="cheese")
Exemplo n.º 3
0
def test_multilanguage_page_get_by_url(rf):
    page = create_multilanguage_page(eternal=True, url="ham")
    page_id = page.pk
    # Test that using `translations__url` will be able to retrieve pages
    # regardless of translation
    for lang in ("fi", "en"):
        for url in ("ham-fi", "ham-en"):
            page = Page.objects.language(lang).filter(translations__url=url).get(pk=page_id)
            assert page.get_current_language() == lang
Exemplo n.º 4
0
def test_multilanguage_page_get_by_url(rf):
    page = create_multilanguage_page(eternal=True, url="ham")
    page_id = page.pk
    # Test that using `translations__url` will be able to retrieve pages
    # regardless of translation
    for lang in ("fi", "en"):
        for url in ("ham-fi", "ham-en"):
            page = Page.objects.language(lang).filter(translations__url=url).get(pk=page_id)
            assert page.get_current_language() == lang
Exemplo n.º 5
0
def test_multilanguage_page_404_no_xlate(rf):
    # https://github.com/edoburu/django-parler/issues/50
    cache.clear()  # this is here, because parler cache is enabled and tests use same pk with page
    page = create_multilanguage_page(eternal=True, url="no_content",
                                     languages=("udm",))  # create page with udm language
    get_default_shop()
    request = apply_request_middleware(rf.get("/"))
    with translation.override("fi"):  # change language of the page to fi
        view_func = PageView.as_view()
        with pytest.raises(Http404):
            response = view_func(request, url="no_content-udm")  # Using Udmurt URL, but xlate is Finnish . . .
            assert response.status_code == 404  # ... should 404
Exemplo n.º 6
0
def test_multilanguage_page_404_no_xlate(rf):
    # https://github.com/edoburu/django-parler/issues/50
    cache.clear()  # this is here, because parler cache is enabled and tests use same pk with page
    page = create_multilanguage_page(eternal=True, url="no_content",
                                     languages=("udm",))  # create page with udm language
    get_default_shop()
    request = apply_request_middleware(rf.get("/"))
    with translation.override("fi"):  # change language of the page to fi
        view_func = PageView.as_view()
        with pytest.raises(Http404):
            response = view_func(request, url="no_content-udm")  # Using Udmurt URL, but xlate is Finnish . . .
            assert response.status_code == 404  # ... should 404
Exemplo n.º 7
0
def test_create_multilanguage_page():
    with translation.override("de"):
        page_id = create_multilanguage_page(url="multi").pk

        with translation.override("fi"):
            page = Page.objects.get(pk=page_id)
            assert page.title == "test, Finnisch"
            assert page.url == "multi-fi"

        with translation.override("en"):
            page = Page.objects.get(pk=page_id)
            assert page.title == "test, Englisch"
            assert page.url == "multi-en"
Exemplo n.º 8
0
def test_multilanguage_page_redirect(rf):
    page = create_multilanguage_page(eternal=True, url="redirector")
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    with translation.override("fi"):
        page.set_current_language("fi")
        finnish_url = page.url
        response = view_func(request, url=finnish_url)
        assert response.status_code == 200  # Using the Finnish URL works
        page.set_current_language("en")
        english_url = page.url
        response = view_func(request, url=english_url)
        assert response.status_code == 302  # Using the English URL - redirect to finnish
        assert finnish_url in response["location"]
Exemplo n.º 9
0
def test_multilanguage_page_redirect(rf):
    page = create_multilanguage_page(eternal=True, url="redirector")
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    with translation.override("fi"):
        page.set_current_language("fi")
        finnish_url = page.url
        response = view_func(request, url=finnish_url)
        assert response.status_code == 200  # Using the Finnish URL works
        page.set_current_language("en")
        english_url = page.url
        response = view_func(request, url=english_url)
        assert response.status_code == 302  # Using the English URL - redirect to finnish
        assert finnish_url in response["location"]