Esempio n. 1
0
def test_set_get_theme(rf):
    with override_provides("xtheme", [
            "shuup_tests.xtheme.utils:FauxTheme",
            "shuup_tests.xtheme.utils:FauxTheme2"
    ]):
        shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
        shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

        assert get_current_theme(shop1) is None
        assert get_current_theme(shop2) is None

        set_current_theme(FauxTheme2.identifier, shop1)
        assert get_current_theme(shop1).identifier == FauxTheme2.identifier
        assert get_current_theme(shop1).settings_obj is not None

        set_current_theme(FauxTheme.identifier, shop2)
        assert get_current_theme(shop2).identifier == FauxTheme.identifier
Esempio n. 2
0
def test_set_get_theme(rf):
    with override_provides("xtheme", [
        "shuup_tests.xtheme.utils:FauxTheme",
        "shuup_tests.xtheme.utils:FauxTheme2"
    ]):
        shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
        shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

        assert get_current_theme(shop1) is None
        assert get_current_theme(shop2) is None

        set_current_theme(FauxTheme2.identifier, shop1)
        assert get_current_theme(shop1).identifier == FauxTheme2.identifier
        assert get_current_theme(shop1).settings_obj is not None

        set_current_theme(FauxTheme.identifier, shop2)
        assert get_current_theme(shop2).identifier == FauxTheme.identifier
Esempio n. 3
0
def test_theme_selection():
    """
    Test that a theme with a `template_dir` actually affects template directory selection.
    """
    with override_current_theme_class(), override_provides("xtheme", [
        "shuup_tests.xtheme.utils:FauxTheme",
        "shuup_tests.xtheme.utils:FauxTheme2",
        "shuup_tests.xtheme.utils:H2G2Theme",
    ]):
        ThemeSettings.objects.all().delete()
        for theme in get_provide_objects("xtheme"):
            set_current_theme(theme.identifier)
            je = get_jinja2_engine()
            wrapper = (noop() if theme.identifier == "h2g2" else pytest.raises(TemplateDoesNotExist))
            with wrapper:
                t = je.get_template("42.jinja")
                content = t.render().strip()
                assert "a slice of lemon wrapped around a large gold brick" in content.replace("\n", " ")
Esempio n. 4
0
    def run(self):
        for schema in self.schemata:
            self.objects[schema["model"]] = self.process_schema(schema)

        # Ensure default statuses are available
        print_("Creating order statuses...", end=" ")
        create_default_order_statuses()
        print_("done.")
        if not settings.DEBUG and is_telemetry_enabled():
            try:
                data = json.dumps({"key": get_installation_key()})
                resp = requests.get(url=settings.SHUUP_SUPPORT_ID_URL,
                                    data=data,
                                    timeout=5)
                if resp.json().get("support_id"):
                    configuration.set(None, "shuup_support_id",
                                      resp.json().get("support_id"))
            except Exception:
                print_("Failed to get support id.")

        set_current_theme("shuup.themes.classic_gray", Shop.objects.first())

        print_("Initialization done.")
Esempio n. 5
0
def test_theme_activation():
    cache.init_cache()
    shop = get_default_shop()

    with override_provides("xtheme", [
        "shuup_tests.xtheme.utils:FauxTheme",
        "shuup_tests.xtheme.utils:FauxTheme2"
    ]):
        set_current_theme(FauxTheme.identifier, shop)
        assert isinstance(get_current_theme(shop), FauxTheme)
        set_current_theme(FauxTheme2.identifier, shop)
        assert isinstance(get_current_theme(shop), FauxTheme2)
        with pytest.raises(ValueError):
            set_current_theme(printable_gibberish(), shop)
Esempio n. 6
0
def test_theme_activation():
    with override_current_theme_class():
        with override_provides("xtheme", [
            "shuup_tests.xtheme.utils:FauxTheme",
            "shuup_tests.xtheme.utils:FauxTheme2"
        ]):
            ThemeSettings.objects.all().delete()
            assert not get_current_theme()
            set_current_theme(FauxTheme.identifier)
            assert isinstance(get_current_theme(), FauxTheme)
            set_current_theme(FauxTheme2.identifier)
            assert isinstance(get_current_theme(), FauxTheme2)
            with pytest.raises(ValueError):
                set_current_theme(printable_gibberish())
Esempio n. 7
0
def test_theme_activation():
    with override_current_theme_class():
        with override_provides("xtheme", [
                "shuup_tests.xtheme.utils:FauxTheme",
                "shuup_tests.xtheme.utils:FauxTheme2"
        ]):
            ThemeSettings.objects.all().delete()
            assert not get_current_theme()
            set_current_theme(FauxTheme.identifier)
            assert isinstance(get_current_theme(), FauxTheme)
            set_current_theme(FauxTheme2.identifier)
            assert isinstance(get_current_theme(), FauxTheme2)
            with pytest.raises(ValueError):
                set_current_theme(printable_gibberish())
Esempio n. 8
0
def test_theme_activation():
    shop = get_default_shop()
    with override_current_theme_class():
        with override_provides("xtheme", [
                "shuup_tests.xtheme.utils:FauxTheme",
                "shuup_tests.xtheme.utils:FauxTheme2"
        ]):
            ThemeSettings.objects.all().delete()
            # ThemeSettings will be created on the fly
            theme = get_current_theme(shop)
            assert theme
            assert theme.settings_obj
            set_current_theme(FauxTheme.identifier, shop)
            assert isinstance(get_current_theme(shop), FauxTheme)
            set_current_theme(FauxTheme2.identifier, shop)
            assert isinstance(get_current_theme(shop), FauxTheme2)
            with pytest.raises(ValueError):
                set_current_theme(printable_gibberish(), shop)
Esempio n. 9
0
def test_plugin():
    shop = factories.get_default_shop()
    set_current_theme(ClassicGrayTheme.identifier, shop)

    blog_one_page = Page.objects.create(
        shop=shop,
        title="Blog One",
        url="blog_one",
        available_from=(now() - timedelta(days=10)),
        available_to=(now() + timedelta(days=10)),
        content="")

    blog_two_page = Page.objects.create(
        shop=shop,
        title="Blog Two",
        url="blog_two",
        available_from=(now() - timedelta(days=10)),
        available_to=(now() + timedelta(days=10)),
        content="")
    # create 10 blog pages
    for page in [blog_one_page, blog_two_page]:
        for i in range(10):
            article = Page.objects.create(
                shop=shop,
                title="Article %d %s" % (i, page.title),
                url="blog-%d-%s" % (i, page.url),
                available_from=(now() - timedelta(days=10)),
                available_to=(now() + timedelta(days=10)),
                content="Content %d" % i,
                template_name="shuup_cms_blog/blog_page.jinja",
                parent=page)
            BlogArticle.objects.create(
                page=article,
                is_blog_article=True,
                image=factories.get_random_filer_image(),
                small_description="description %d" % i)

    # create 3 non blog post pages
    for i in range(3):
        article = Page.objects.create(
            shop=shop,
            title="Nothing %d" % i,
            url="non-%d" % i,
            available_from=(now() - timedelta(days=10)),
            available_to=(now() + timedelta(days=10)),
            content="content %i" % i)

    theme = get_current_theme(shop)
    view_config = ViewConfig(theme=theme,
                             shop=shop,
                             view_name="PageView",
                             draft=True)

    placeholder_name = "cms_page"
    context_one = {"page": blog_one_page}
    context_two = {"page": blog_two_page}

    layout_one = view_config.get_placeholder_layout(PageLayout,
                                                    placeholder_name,
                                                    context=context_one)
    layout_two = view_config.get_placeholder_layout(PageLayout,
                                                    placeholder_name,
                                                    context=context_two)

    assert isinstance(layout_one, PageLayout)
    assert isinstance(layout_two, PageLayout)

    assert layout_one.get_help_text({}) == ""
    assert layout_two.get_help_text({}) == ""

    assert blog_one_page.title in layout_two.get_help_text(context_one)
    assert blog_two_page.title in layout_two.get_help_text(context_two)

    serialized_one = layout_one.serialize()
    serialized_two = layout_two.serialize()

    assert len(serialized_one["rows"]) == 0
    assert len(serialized_two["rows"]) == 0

    assert serialized_one["name"] == placeholder_name
    assert serialized_two["name"] == placeholder_name

    layout_one.begin_column({"sm": 12})
    layout_two.begin_column({"sm": 12})

    layout_one.add_plugin(ShuupCMSBlogArticleListPlugin.identifier,
                          {"blog_page": blog_one_page.pk})
    layout_two.add_plugin(ShuupCMSBlogArticleListPlugin.identifier,
                          {"blog_page": blog_two_page.pk})

    view_config.save_placeholder_layout(
        get_layout_data_key(placeholder_name, layout_one, context_one),
        layout_one)
    view_config.save_placeholder_layout(
        get_layout_data_key(placeholder_name, layout_two, context_two),
        layout_two)
    view_config.publish()

    client = SmartClient()
    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": blog_one_page.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 10

    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": blog_two_page.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 10

    article_one = Page.objects.create(
        shop=shop,
        title="Article test",
        url="blog-test",
        available_from=(now() - timedelta(days=10)),
        available_to=(now() + timedelta(days=10)),
        content="Content test",
        template_name=
        "shuup_cms_blog/blog_page.jinja",  # Add an article without a parent
    )
    BlogArticle.objects.create(page=article_one,
                               is_blog_article=True,
                               image=factories.get_random_filer_image(),
                               small_description="description test")
    article_two = Page.objects.create(
        shop=shop,
        title="Article test 2",
        url="blog-test-2",
        available_from=(now() - timedelta(days=10)),
        available_to=(now() + timedelta(days=10)),
        content="Content test 2",
        template_name=
        "shuup_cms_blog/blog_page.jinja",  # Add an article without a parent
    )
    BlogArticle.objects.create(page=article_two,
                               is_blog_article=True,
                               image=factories.get_random_filer_image(),
                               small_description="description test 2")
    view_config = ViewConfig(theme=theme,
                             shop=shop,
                             view_name="PageView",
                             draft=True)

    # No blog page set means that only articles with no parent will be shown
    layout_two.add_plugin(ShuupCMSBlogArticleListPlugin.identifier, {})
    view_config.save_placeholder_layout(
        get_layout_data_key(placeholder_name, layout_two, context_two),
        layout_two)
    view_config.publish()

    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": blog_two_page.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 2

    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": article_one.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 1
    assert soup.find("div", {
        "class": "article-title"
    }).text == article_two.title

    article_one.soft_delete()  # Delete the article that has no parent
    article_two.soft_delete()  # Delete the article that has no parent

    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": blog_two_page.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 0

    article_with_parent = Page.objects.filter(parent=blog_one_page).first()
    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": article_with_parent.url}))
    assert response.status_code == 200
    assert len(soup.find_all(
        "a",
        {"class": "article-card"})) == 9  # Assert there are 9 articles shown
    article_card_titles = soup.find_all("div", {"class": "article-title"})
    article_card_titles = [title.text for title in article_card_titles]
    # Assert that the current visited article (article_with_parent) is not visible in Related articles
    assert article_with_parent.title not in article_card_titles
def test_page_anonymous_layout():
    if "shuup.simple_cms" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.simple_cms in INSTALLED_APPS")

    if "shuup.xtheme" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.xtheme in INSTALLED_APPS")

    shop = factories.get_default_shop()
    theme = set_current_theme("shuup.themes.classic_gray", shop)
    view_config = ViewConfig(theme=theme,
                             shop=shop,
                             view_name="PageView",
                             draft=True)
    page1_content = printable_gibberish()
    page1 = create_page(available_from=datetime.date(1917, 12, 6),
                        content=page1_content,
                        shop=shop,
                        url="test1")
    page2_content = printable_gibberish()
    page2 = create_page(available_from=datetime.date(1917, 12, 6),
                        content=page2_content,
                        shop=shop,
                        url="test2")

    person = factories.create_random_person(shop=shop)
    person.user = factories.create_random_user()
    password = "******"
    person.user.set_password(password)
    person.user.save()
    person.save()

    placeholder_name = "cms_page"
    request = get_request()
    context = {"page": page1, "request": request}
    layout = view_config.get_placeholder_layout(PageAnonymousLayout,
                                                placeholder_name,
                                                context=context)
    assert isinstance(layout, PageAnonymousLayout)
    assert layout.get_help_text({}) == ""  # Invalid context for help text
    assert page1.title in layout.get_help_text(context)

    # Make sure layout is empty
    serialized = layout.serialize()
    assert len(serialized["rows"]) == 0
    assert serialized["name"] == placeholder_name

    # Add custom plugin to page
    layout.begin_column({"md": 8})
    plugin_text = printable_gibberish()
    layout.add_plugin("text", {"text": plugin_text})
    view_config.save_placeholder_layout(
        get_layout_data_key(placeholder_name, layout, context), layout)
    view_config.publish()

    c = SmartClient()
    soup = c.soup(reverse("shuup:cms_page", kwargs={"url": page1.url}))
    page_content = soup.find("div", {"class": "page-content"})
    assert page1_content in page_content.text
    assert plugin_text in page_content.text

    # Make sure content not available for page2
    c = SmartClient()
    soup = c.soup(reverse("shuup:cms_page", kwargs={"url": page2.url}))
    page_content = soup.find("div", {"class": "page-content"})
    assert page2_content in page_content.text
    assert plugin_text not in page_content.text

    # Make sure content not available for logged in users
    c = SmartClient()
    c.login(username=person.user.username, password=password)
    soup = c.soup(reverse("shuup:cms_page", kwargs={"url": page1.url}))
    page_content = soup.find("div", {"class": "page-content"})
    assert page1_content in page_content.text
    assert plugin_text not in page_content.text
Esempio n. 11
0
def test_plugin():
    shop = factories.get_default_shop()
    set_current_theme(ClassicGrayTheme.identifier, shop)

    blog_page = Page.objects.create(shop=shop,
                                    title="Blog",
                                    url="blog",
                                    available_from=(now() -
                                                    timedelta(days=10)),
                                    available_to=(now() + timedelta(days=10)),
                                    content="")

    # create 10 blog pages
    for i in range(10):
        article = Page.objects.create(
            shop=shop,
            title="Article %d" % i,
            url="blog-%d" % i,
            available_from=(now() - timedelta(days=10)),
            available_to=(now() + timedelta(days=10)),
            content="Content %d" % i,
            template_name="shuup_cms_blog/blog_page.jinja")
        BlogArticle.objects.create(page=article,
                                   is_blog_article=True,
                                   image=factories.get_random_filer_image(),
                                   small_description="description %d" % i)

    # create 3 non blog post pages
    for i in range(3):
        article = Page.objects.create(
            shop=shop,
            title="Nothing %d" % i,
            url="non-%d" % i,
            available_from=(now() - timedelta(days=10)),
            available_to=(now() + timedelta(days=10)),
            content="content %i" % i)

    theme = get_current_theme(shop)
    view_config = ViewConfig(theme=theme,
                             shop=shop,
                             view_name="PageView",
                             draft=True)

    placeholder_name = "cms_page"
    context = {"page": blog_page}
    layout = view_config.get_placeholder_layout(PageLayout,
                                                placeholder_name,
                                                context=context)
    assert isinstance(layout, PageLayout)
    assert layout.get_help_text({}) == ""
    assert blog_page.title in layout.get_help_text(context)
    serialized = layout.serialize()
    assert len(serialized["rows"]) == 0
    assert serialized["name"] == placeholder_name

    layout.begin_column({"sm": 12})
    layout.add_plugin(ShuupCMSBlogArticleListPlugin.identifier, {})
    view_config.save_placeholder_layout(
        get_layout_data_key(placeholder_name, layout, context), layout)
    view_config.publish()

    client = SmartClient()
    response, soup = client.response_and_soup(
        reverse("shuup:cms_page", kwargs={"url": blog_page.url}))
    assert response.status_code == 200
    assert len(soup.find_all("a", {"class": "article-card"})) == 10