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_invisible_children(rf):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"))

    parent_content = "Parent content"
    page = create_page(available_from=datetime.date(1988, 1, 1), content=parent_content)
    children_content = "Children content"
    create_page(content=children_content, parent=page)  # Create invisible children

    assert page.list_children_on_page == False
    check_children_content(request, page, children_content, False)

    page.list_children_on_page = True
    page.save()
    check_children_content(request, page, children_content, False)
Exemplo n.º 4
0
def test_invisible_children(rf):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"))

    parent_content = "Parent content"
    page = create_page(available_from=datetime.date(1988, 1, 1),
                       content=parent_content)
    children_content = "Children content"
    create_page(content=children_content,
                parent=page)  # Create invisible children

    assert page.list_children_on_page == False
    check_children_content(request, page, children_content, False)

    page.list_children_on_page = True
    page.save()
    check_children_content(request, page, children_content, False)
Exemplo n.º 5
0
def test_future_page_not_visible():
    today = now()
    page = create_page(
        available_from=(today + datetime.timedelta(days=1)),
        available_to=(today + datetime.timedelta(days=2)),
    )
    assert not Page.objects.visible().filter(pk=page.pk).exists()
    assert not page.is_visible()
Exemplo n.º 6
0
def test_anon_cant_see_invisible_page(rf):
    page = create_page()
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    assert request.user.is_anonymous()
    with pytest.raises(Http404):
        response = view_func(request, url=page.url)
Exemplo n.º 7
0
def test_superuser_can_see_invisible_page(rf, admin_user):
    page = create_page()
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = view_func(request, url=page.url)
    response.render()
    assert "<h1>Bacon ipsum" in response.rendered_content
Exemplo n.º 8
0
def test_anon_cant_see_invisible_page(rf):
    page = create_page()
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    assert request.user.is_anonymous()
    with pytest.raises(Http404):
        response = view_func(request, url=page.url)
Exemplo n.º 9
0
def test_superuser_can_see_invisible_page(rf, admin_user):
    page = create_page()
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = view_func(request, url=page.url)
    response.render()
    assert "<h1>Bacon ipsum" in response.rendered_content
Exemplo n.º 10
0
def test_visible_page_has_right_content(rf):
    page = create_page(available_from=datetime.date(1988, 1, 1))
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    assert request.user.is_anonymous()
    response = view_func(request, url=page.url)
    response.render()
    assert "<h1>Bacon ipsum" in response.rendered_content
Exemplo n.º 11
0
def test_visible_page_has_right_content(rf):
    page = create_page(available_from=datetime.date(1988, 1, 1))
    get_default_shop()
    view_func = PageView.as_view()
    request = apply_request_middleware(rf.get("/"))
    assert request.user.is_anonymous()
    response = view_func(request, url=page.url)
    response.render()
    assert "<h1>Bacon ipsum" in response.rendered_content
Exemplo n.º 12
0
def test_slide_links():
    test_carousel = Carousel.objects.create(name="test")
    test_image_1 = Image.objects.create(original_filename="slide1.jpg")
    with translation.override("en"):
        test_slide = Slide.objects.create(carousel=test_carousel, name="test", image=test_image_1)

    # Test external link
    assert len(test_carousel.slides.all()) == 1
    test_link = "http://example.com"
    test_slide.external_link = test_link
    test_slide.save()
    assert test_slide.get_translated_field("external_link") == test_link
    assert test_slide.get_link_url() == test_link

    # Test Product url and link priorities
    test_product = get_default_product()
    test_slide.product_link = test_product
    test_slide.save()
    assert test_slide.get_link_url() == test_link
    test_slide.external_link = None
    test_slide.save()
    assert test_slide.get_link_url().startswith("/p/")  # Close enough...

    # Test Category url and link priorities
    test_category = get_default_category()
    test_slide.category_link = test_category
    test_slide.save()
    assert test_slide.get_link_url().startswith("/p/")  # Close enough...
    test_slide.product_link = None
    test_slide.save()
    assert test_slide.get_link_url().startswith("/c/")  # Close enough...

    # Test CMS page url and link priorities
    attrs = {"url": "test"}
    test_page = create_page(**attrs)
    test_slide.cms_page_link = test_page
    test_slide.save()
    assert test_slide.get_link_url().startswith("/c/")  # Close enough...
    test_slide.category_link = None
    test_slide.save()
    assert test_slide.get_link_url().startswith("/test/")

    # Check that external link overrides everything
    test_slide.external_link = test_link
    test_slide.save()
    assert test_slide.get_link_url() == test_link
Exemplo n.º 13
0
def test_page_without_visibility_end_is_visible():
    today = now()
    page = create_page(available_from=today, available_to=None)

    assert Page.objects.visible(today).filter(pk=page.pk).exists()
    assert page.is_visible(today)
Exemplo n.º 14
0
def test_current_page_is_visible():
    today = now()
    page = create_page(available_from=today, available_to=today)

    assert Page.objects.visible(today).filter(pk=page.pk).exists()
    assert page.is_visible(today)
Exemplo n.º 15
0
def test_none_dates_page_not_visible():
    # create page that is not anymore visible
    page = create_page()

    assert not Page.objects.visible().filter(pk=page.pk).exists()
    assert not page.is_visible()
Exemplo n.º 16
0
def test_page_form(rf):
    view = PageEditView(request=rf.get("/"))
    form_class = view.get_form_class()
    form_kwargs = view.get_form_kwargs()
    form = form_class(**form_kwargs)
    assert not form.is_bound

    data = get_form_data(form)
    data.update({
        "available_from": "",
        "available_to": "",
        "content__en": "",
        "content__fi": "suomi",
        "content__ja": "",
        "identifier": "",
        "title__en": "",
        "title__fi": "",
        "title__ja": "",
        "url__en": "",
        "url__fi": "suomi",
        "url__ja": "",
    })

    form = form_class(**dict(form_kwargs, data=data))
    form.full_clean()
    assert "title__fi" in form.errors  # We get an error because all of a given language's fields must be filled if any are
    data["title__fi"] = "suomi"
    form = form_class(**dict(form_kwargs, data=data))
    form.full_clean()
    assert not form.errors
    page = form.save()
    assert set(page.get_available_languages()) == {
        "fi"
    }  # The page should be only in Finnish
    # Let's edit that page
    original_url = "errrnglish"
    data.update({
        "title__en": "englaish",
        "url__en": original_url,
        "content__en": "ennnn ennnn ennnnnnn-nn-n-n"
    })
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert not form.errors
    page = form.save()
    assert set(page.get_available_languages()) == {"fi", "en"}  # English GET

    # add dummy page with simple url, page is in english
    dummy = create_page(url="test")

    # edit page again and try to set duplicate url
    data.update({
        "title__en": "englaish",
        "url__en": "test",
        "content__en": "ennnn ennnn ennnnnnn-nn-n-n"
    })
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()

    assert len(form.errors) == 1
    assert "url__en" in form.errors
    assert form.errors["url__en"].as_data()[0].code == "invalid_url"

    # it should be possible to change back to the original url
    data.update({
        "title__en": "englaish",
        "url__en": original_url,
        "content__en": "ennnn ennnn ennnnnnn-nn-n-n"
    })
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert not form.errors
    page = form.save()

    # add finnish urls, it should not be possible to enter original url
    data.update({
        "title__fi": "englaish",
        "url__fi": original_url,
        "content__fi": "ennnn ennnn ennnnnnn-nn-n-n"
    })
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert len(form.errors) == 1
    assert "url__fi" in form.errors
    assert form.errors["url__fi"].as_data()[0].code == "invalid_url"
Exemplo n.º 17
0
def test_page_form(rf):
    view = PageEditView(request=rf.get("/"))
    form_class = view.get_form_class()
    form_kwargs = view.get_form_kwargs()
    form = form_class(**form_kwargs)
    assert not form.is_bound

    data = get_form_data(form)
    data.update({
        "available_from": "",
        "available_to": "",
        "content__en": "",
        "content__fi": "suomi",
        "content__ja": "",
        "identifier": "",
        "title__en": "",
        "title__fi": "",
        "title__ja": "",
        "url__en": "",
        "url__fi": "suomi",
        "url__ja": "",
    })

    form = form_class(**dict(form_kwargs, data=data))
    form.full_clean()
    assert "title__fi" in form.errors  # We get an error because all of a given language's fields must be filled if any are
    data["title__fi"] = "suomi"
    form = form_class(**dict(form_kwargs, data=data))
    form.full_clean()
    assert not form.errors
    page = form.save()
    assert set(page.get_available_languages()) == {"fi"}  # The page should be only in Finnish
    # Let's edit that page
    original_url = "errrnglish"
    data.update({"title__en": "englaish", "url__en": original_url, "content__en": "ennnn ennnn ennnnnnn-nn-n-n"})
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert not form.errors
    page = form.save()
    assert set(page.get_available_languages()) == {"fi", "en"}  # English GET

    # add dummy page with simple url, page is in english
    dummy = create_page(url="test")

    # edit page again and try to set duplicate url
    data.update({"title__en": "englaish", "url__en": "test", "content__en": "ennnn ennnn ennnnnnn-nn-n-n"})
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()

    assert len(form.errors) == 1
    assert "url__en" in form.errors
    assert form.errors["url__en"].as_data()[0].code == "invalid_url"

    # it should be possible to change back to the original url
    data.update({"title__en": "englaish", "url__en": original_url, "content__en": "ennnn ennnn ennnnnnn-nn-n-n"})
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert not form.errors
    page = form.save()

    # add finnish urls, it should not be possible to enter original url
    data.update({"title__fi": "englaish", "url__fi": original_url, "content__fi": "ennnn ennnn ennnnnnn-nn-n-n"})
    form = form_class(**dict(form_kwargs, data=data, instance=page))
    form.full_clean()
    assert len(form.errors) == 1
    assert "url__fi" in form.errors
    assert form.errors["url__fi"].as_data()[0].code == "invalid_url"