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
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
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
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}
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
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
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