Example #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
Example #2
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}
        ),
        (
            {"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
Example #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
Example #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}
Example #5
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") == None

    test_carousel.shops = [shop]
    plugin = CarouselPlugin(config={"carousel": test_carousel.pk})
    assert plugin.get_context_data(context).get("carousel") == test_carousel
Example #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
Example #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
Example #8
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