コード例 #1
0
def test_ratings_plugin(show_recommenders, title):
    shop = factories.get_default_shop()
    product = factories.create_product("product", shop=shop, supplier=factories.get_default_supplier())

    # create 15 reviews for the product
    [create_random_review_for_product(shop, product) for _ in range(15)]

    set_current_theme(ClassicGrayTheme.identifier, shop)
    svc = SavedViewConfig(
        theme_identifier=ClassicGrayTheme.identifier,
        shop=shop,
        view_name="ProductDetailView",
        status=SavedViewConfigStatus.CURRENT_DRAFT
    )
    layout = Layout(get_current_theme(shop), "product_extra_2")
    layout.add_plugin(ProductReviewStarRatingsPlugin.identifier, {
        "customer_ratings_title": {
            "en": title
        },
        "show_recommenders": show_recommenders
    })
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    svc.publish()

    client = Client()
    response = client.get(reverse("shuup:product", kwargs=dict(pk=product.pk, slug=product.slug)))
    assert response.status_code == 200
    response.render()
    content = response.content.decode("utf-8")

    assert "product-reviews-rating-star" in content
    assert 'class="rating"' in content
    assert ('class="recommend"' in content) == show_recommenders
    assert title in content
コード例 #2
0
def test_comments_plugin(title):
    shop = factories.get_default_shop()
    product = factories.create_product(
        "product", shop=shop, supplier=factories.get_default_supplier())

    # create 15 reviews for the product
    [create_random_review_for_product(shop, product) for _ in range(15)]

    set_current_theme(ClassicGrayTheme.identifier, shop)
    svc = SavedViewConfig(theme_identifier=ClassicGrayTheme.identifier,
                          shop=shop,
                          view_name="ProductDetailView",
                          status=SavedViewConfigStatus.CURRENT_DRAFT)
    layout = Layout(get_current_theme(shop), "product_bottom")
    layout.add_plugin(ProductReviewCommentsPlugin.identifier,
                      {"title": {
                          "en": title
                      }})
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    svc.publish()

    client = Client()
    response = client.get(
        reverse("shuup:product", kwargs=dict(pk=product.pk,
                                             slug=product.slug)))
    assert response.status_code == 200
    response.render()
    content = response.content.decode("utf-8")

    assert "product-review-comments" in content
    assert 'data-url="%s"' % reverse('shuup:product_review_comments',
                                     kwargs=dict(pk=product.pk)) in content
    assert 'data-title="%s"' % title in content
コード例 #3
0
    def _handle_xtheme_save(self):
        svc_pk = config.get(self.shop, CONTENT_FOOTER_KEY)
        svc = SavedViewConfig.objects.filter(pk=svc_pk).first()
        theme = get_current_theme(self.shop)

        if not svc and theme:
            context = {"shop": self.shop}
            rendered_content = template_loader.render_to_string(
                content_data.FOOTER_TEMPLATE, context).strip()
            layout = Layout(theme, "footer-bottom")
            # adds the footer template
            layout.begin_row()
            layout.begin_column({"md": 12})
            layout.add_plugin(SnippetsPlugin.identifier,
                              {"in_place": rendered_content})

            svc = SavedViewConfig(theme_identifier=theme.identifier,
                                  shop=self.shop,
                                  view_name=XTHEME_GLOBAL_VIEW_NAME,
                                  status=SavedViewConfigStatus.CURRENT_DRAFT)
            svc.set_layout_data(layout.placeholder_name, layout)
            svc.save()
            svc.publish()

            config.set(self.shop, CONTENT_FOOTER_KEY, svc.pk)
コード例 #4
0
ファイル: forms.py プロジェクト: ruqaiya/shuup
    def _handle_xtheme_save(self):
        svc_pk = config.get(self.shop, CONTENT_FOOTER_KEY)
        svc = SavedViewConfig.objects.filter(pk=svc_pk).first()
        theme = get_current_theme(self.shop)

        if not svc and theme:
            context = {"shop": self.shop}
            rendered_content = template_loader.render_to_string(content_data.FOOTER_TEMPLATE, context).strip()
            layout = Layout(theme, "footer-bottom")
            # adds the footer template
            layout.begin_row()
            layout.begin_column({"md": 12})
            layout.add_plugin(SnippetsPlugin.identifier, {"in_place": rendered_content})

            svc = SavedViewConfig(
                theme_identifier=theme.identifier,
                shop=self.shop,
                view_name=XTHEME_GLOBAL_VIEW_NAME,
                status=SavedViewConfigStatus.CURRENT_DRAFT
            )
            svc.set_layout_data(layout.placeholder_name, layout)
            svc.save()
            svc.publish()

            config.set(self.shop, CONTENT_FOOTER_KEY, svc.pk)
コード例 #5
0
ファイル: test_editor_view.py プロジェクト: dragonsg/shuup-1
def get_test_layout_and_svc():
    svc = SavedViewConfig(theme_identifier=FauxTheme.identifier,
                          view_name=printable_gibberish(),
                          status=SavedViewConfigStatus.CURRENT_DRAFT)
    layout = Layout("ph")
    layout.add_plugin("text", {"text": "hello"})
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    return layout, svc
コード例 #6
0
ファイル: test_editor_view.py プロジェクト: gurch101/shuup
def get_test_layout_and_svc():
    svc = SavedViewConfig(
        theme_identifier=FauxTheme.identifier,
        view_name=printable_gibberish(),
        status=SavedViewConfigStatus.CURRENT_DRAFT
    )
    layout = Layout(FauxTheme, "ph")
    layout.add_plugin("text", {"text_*": "hello"})
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    return layout, svc
コード例 #7
0
    def _create_sample_carousel(cls, shop, business_segment):
        """
        Create the sample carousel for the given business_segment
        and also injects it to the default theme currently being used in front
        """
        if business_segment not in BUSINESS_SEGMENTS:
            return None

        carousel_data = BUSINESS_SEGMENTS[business_segment]["carousel"]
        carousel = create_sample_carousel(carousel_data, business_segment,
                                          shop)

        # injects the carousel plugin with in the front_content placeholder
        # this will only works if the theme have this placeholder, we expect so
        if 'shuup.xtheme' in settings.INSTALLED_APPS:
            from shuup.front.apps.carousel.plugins import CarouselPlugin
            from shuup.xtheme.plugins.products import ProductHighlightPlugin

            from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus
            from shuup.xtheme.layout import Layout
            from shuup.xtheme._theme import get_current_theme

            theme = get_current_theme(shop)

            if theme:
                layout = Layout(theme, "front_content")

                # adds the carousel
                layout.begin_row()
                layout.begin_column({"md": 12})
                layout.add_plugin(CarouselPlugin.identifier,
                                  {"carousel": carousel.pk})

                # adds some products
                layout.begin_row()
                layout.begin_column({"md": 12})
                layout.add_plugin(ProductHighlightPlugin.identifier, {})

                svc = SavedViewConfig(
                    theme_identifier=theme.identifier,
                    shop=shop,
                    view_name="IndexView",
                    status=SavedViewConfigStatus.CURRENT_DRAFT)
                svc.set_layout_data(layout.placeholder_name, layout)
                svc.save()
                svc.publish()

        return carousel
コード例 #8
0
ファイル: views.py プロジェクト: ruqaiya/shuup
    def _create_sample_carousel(cls, shop, business_segment):
        """
        Create the sample carousel for the given business_segment
        and also injects it to the default theme currently being used in front
        """
        if business_segment not in BUSINESS_SEGMENTS:
            return None

        carousel_data = BUSINESS_SEGMENTS[business_segment]["carousel"]
        carousel = create_sample_carousel(carousel_data, business_segment, shop)

        # injects the carousel plugin with in the front_content placeholder
        # this will only works if the theme have this placeholder, we expect so
        if 'shuup.xtheme' in settings.INSTALLED_APPS:
            from shuup.front.apps.carousel.plugins import CarouselPlugin
            from shuup.xtheme.plugins.products import ProductHighlightPlugin

            from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus
            from shuup.xtheme.layout import Layout
            from shuup.xtheme._theme import get_current_theme

            theme = get_current_theme(shop)

            if theme:
                layout = Layout(theme, "front_content")

                # adds the carousel
                layout.begin_row()
                layout.begin_column({"md": 12})
                layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk})

                # adds some products
                layout.begin_row()
                layout.begin_column({"md": 12})
                layout.add_plugin(ProductHighlightPlugin.identifier, {})

                svc = SavedViewConfig(
                    theme_identifier=theme.identifier,
                    shop=shop,
                    view_name="IndexView",
                    status=SavedViewConfigStatus.CURRENT_DRAFT
                )
                svc.set_layout_data(layout.placeholder_name, layout)
                svc.save()
                svc.publish()

        return carousel
コード例 #9
0
ファイル: test_carousel.py プロジェクト: ruqaiya/shuup
def test_carousel_custom_colors(rf):
    from shuup.front.apps.carousel.plugins import CarouselPlugin
    from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus
    from shuup.xtheme.layout import Layout
    from shuup.xtheme._theme import get_current_theme
    from django.core.urlresolvers import reverse

    shop = get_default_shop()
    shop.maintenance_mode = False
    shop.save()

    carousel = Carousel.objects.create(name="test")
    carousel.shops.add(shop)
    test_image = Image.objects.create(original_filename="slide.jpg")
    test_slide = Slide.objects.create(
        carousel=carousel, name="test",
        available_from=(datetime.now() - timedelta(days=1)),
        image=test_image, target=LinkTargetType.CURRENT
    )

    theme = get_current_theme(shop)

    # adds the carousel to the front page
    layout = Layout(theme, "front_content")
    layout.begin_row()
    layout.begin_column({"md": 12})
    layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk})
    svc = SavedViewConfig(
        theme_identifier=theme.identifier,
        shop=shop,
        view_name="IndexView",
        status=SavedViewConfigStatus.CURRENT_DRAFT
    )
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    svc.publish()

    client = Client()

    # no customized color
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert "owl-carousel" in content
    assert ".owl-nav .owl-prev" not in content
    assert ".owl-nav .owl-next" not in content
    assert ".owl-dot:nth-child(" not in content

    # put colors in arrows
    carousel.arrows_color = "#ffaabb"
    carousel.save()
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert ".owl-nav .owl-prev" in content
    assert ".owl-nav .owl-next" in content
    assert "color: #ffaabb !important;" in content

    # put custom color in dots
    test_slide.inactive_dot_color = "#a1b2c3"
    test_slide.active_dot_color = "#d4e4f6"
    test_slide.save()
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert ".owl-dot:nth-child(1)" in content
    assert "border-color: #a1b2c3 !important" in content
    assert "background-color: #d4e4f6 !important;" in content
コード例 #10
0
def test_carousel_custom_colors(rf):
    from shuup.front.apps.carousel.plugins import CarouselPlugin
    from shuup.utils.django_compat import reverse
    from shuup.xtheme._theme import get_current_theme
    from shuup.xtheme.layout import Layout
    from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus

    shop = get_default_shop()
    shop.maintenance_mode = False
    shop.save()

    carousel = Carousel.objects.create(name="test")
    carousel.shops.add(shop)
    test_image = Image.objects.create(original_filename="slide.jpg")
    test_slide = Slide.objects.create(
        carousel=carousel,
        name="test",
        available_from=(datetime.now() - timedelta(days=1)),
        image=test_image,
        target=LinkTargetType.CURRENT,
    )

    theme = get_current_theme(shop)

    # adds the carousel to the front page
    layout = Layout(theme, "front_content")
    layout.begin_row()
    layout.begin_column({"md": 12})
    layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk})
    svc = SavedViewConfig(
        theme_identifier=theme.identifier, shop=shop, view_name="IndexView", status=SavedViewConfigStatus.CURRENT_DRAFT
    )
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    svc.publish()

    client = Client()

    # no customized color
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert "owl-carousel" in content
    assert ".owl-nav .owl-prev" not in content
    assert ".owl-nav .owl-next" not in content
    assert ".owl-dot:nth-child(" not in content

    # put colors in arrows
    carousel.arrows_color = "#ffaabb"
    carousel.save()
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert ".owl-nav .owl-prev" in content
    assert ".owl-nav .owl-next" in content
    assert "color: #ffaabb !important;" in content

    # put custom color in dots
    test_slide.inactive_dot_color = "#a1b2c3"
    test_slide.active_dot_color = "#d4e4f6"
    test_slide.save()
    response = client.get(reverse("shuup:index"))
    content = response.content.decode("utf-8")
    assert ".owl-dot:nth-child(1)" in content
    assert "border-color: #a1b2c3 !important" in content
    assert "background-color: #d4e4f6 !important;" in content