コード例 #1
0
def test_carousel_plugin_form():
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={})
    form_class = plugin.get_editor_form_class()

    checks = [({}, {
        "carousel": None,
        "active": False
    }),
              ({
                  "carousel": test_carousel.pk
              }, {
                  "carousel": test_carousel.pk,
                  "active": False
              }),
              ({
                  "carousel": test_carousel.pk,
                  "active": False
              }, {
                  "carousel": test_carousel.pk,
                  "active": False
              }),
              ({
                  "carousel": test_carousel.pk,
                  "active": True
              }, {
                  "carousel": test_carousel.pk,
                  "active": True
              })]

    for data, expected in checks:
        form = form_class(data=data, plugin=plugin)
        assert form.is_valid()
        assert form.get_config() == expected
コード例 #2
0
ファイル: test_carousel.py プロジェクト: ruqaiya/shuup
def test_carousel_plugin_form(rf):
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={})
    form_class = plugin.get_editor_form_class()

    checks = [
        (
            {},
            {"carousel": None, "active": False}
        ),
        (
            {"carousel": test_carousel.pk},
            {"carousel": test_carousel.pk, "active": False}
        ),
        (
            {"carousel": test_carousel.pk, "active": False},
            {"carousel": test_carousel.pk, "active": False}
        ),
        (
            {"carousel": test_carousel.pk, "active": True},
            {"carousel": test_carousel.pk, "active": True}
        )
    ]

    for data, expected in checks:
        form = form_class(
            data=data,
            plugin=plugin,
            request=apply_request_middleware(rf.get("/"))
        )
        assert form.is_valid()
        assert form.get_config() == expected
コード例 #3
0
def test_carousel_plugin_form(rf):
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={})
    form_class = plugin.get_editor_form_class()

    checks = [
        ({}, {"carousel": None, "active": False, "render_image_text": False}),
        ({"carousel": test_carousel.pk}, {"carousel": test_carousel.pk, "active": False, "render_image_text": False}),
        (
            {"carousel": test_carousel.pk, "active": False},
            {"carousel": test_carousel.pk, "active": False, "render_image_text": False},
        ),
        (
            {"carousel": test_carousel.pk, "active": True, "render_image_text": False},
            {"carousel": test_carousel.pk, "active": True, "render_image_text": False},
        ),
        (
            {"carousel": test_carousel.pk, "active": True, "render_image_text": True},
            {"carousel": test_carousel.pk, "active": True, "render_image_text": True},
        ),
    ]

    for data, expected in checks:
        form = form_class(data=data, plugin=plugin, request=apply_request_middleware(rf.get("/")))
        assert form.is_valid()
        assert form.get_config() == expected
コード例 #4
0
def test_carousel_plugin_form():
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={})
    form_class = plugin.get_editor_form_class()
    form = form_class(data={"carousel": test_carousel.pk}, plugin=plugin)
    assert form.is_valid()
    assert form.get_config() == {"carousel": test_carousel.pk}
コード例 #5
0
ファイル: test_carousel.py プロジェクト: ruqaiya/shuup
def test_carousel_plugin_form_get_context():
    shop = get_default_shop()
    context = get_jinja_context()
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == None

    test_carousel.shops = [shop]
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == test_carousel
コード例 #6
0
def test_carousel_plugin_form_get_context():
    shop = get_default_shop()
    context = get_jinja_context()
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") is None
    test_carousel.shops.add(shop)
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == test_carousel
コード例 #7
0
def test_carousel_plugin_form_get_context():
    context = get_jinja_context()
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == test_carousel
コード例 #8
0
ファイル: test_carousel.py プロジェクト: gurch101/shuup
def test_carousel_plugin_form_get_context():
    context = get_jinja_context()
    test_carousel = Carousel.objects.create(name="test")
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == test_carousel