def test_stock_alert_limit_script_template_admin(rf, admin_user): get_default_shop() Script.objects.all().delete() identifier = StockLimitEmailScriptTemplate.identifier # should redirect us since the script template has a bound form request = apply_request_middleware(rf.post("/", {"id": identifier}), user=admin_user) response = ScriptTemplateView.as_view()(request) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script-template-config", kwargs={"id": identifier}) assert Script.objects.count() == 0 # create data = { "en-body": "my body", "en-subject": "something", "base-recipient": "*****@*****.**", "base-last24hrs": True } request = apply_request_middleware(rf.post("/", data), user=admin_user) response = ScriptTemplateConfigView.as_view()(request, id=identifier) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") script = Script.objects.first() assert script is not None _assert_stock_alert_limit_script(script, data) # edit data.update({ "en-body": "my body 2", "en-subject": "something 2", "base-recipient": "*****@*****.**", }) request = apply_request_middleware(rf.post("/", data), user=admin_user) response = ScriptTemplateEditView.as_view()(request, pk=script.pk) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") assert Script.objects.count() == 1 edited_script = Script.objects.first() _assert_stock_alert_limit_script(edited_script, data)
def test_stock_alert_limit_script_template_admin(rf): get_default_shop() Script.objects.all().delete() identifier = StockLimitEmailScriptTemplate.identifier # should redirect us since the script template has a bound form request = apply_request_middleware(rf.post("/", {"id": identifier})) response = ScriptTemplateView.as_view()(request) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script-template-config", kwargs={"id": identifier}) assert Script.objects.count() == 0 # create data = { "en-body": "my body", "en-subject": "something", "base-recipient": "*****@*****.**", "base-last24hrs": True } request = apply_request_middleware(rf.post("/", data)) response = ScriptTemplateConfigView.as_view()(request, id=identifier) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") script = Script.objects.first() assert script is not None _assert_stock_alert_limit_script(script, data) # edit data.update({ "en-body": "my body 2", "en-subject": "something 2", "base-recipient": "*****@*****.**", }) request = apply_request_middleware(rf.post("/", data)) response = ScriptTemplateEditView.as_view()(request, pk=script.pk) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") assert Script.objects.count() == 1 edited_script = Script.objects.first() _assert_stock_alert_limit_script(edited_script, data)
def test_generic_script_template_admin(rf, script_template_cls): get_default_shop() Script.objects.all().delete() identifier = script_template_cls.identifier # should redirect us since the script template has a bound form request = apply_request_middleware(rf.post("/", {"id": identifier})) response = ScriptTemplateView.as_view()(request) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script-template-config", kwargs={"id": identifier}) assert Script.objects.count() == 0 # create data = { "base-send_to": "customer", "en-body": "my body", "en-subject": "something", "fi-body": "my body FI", "fi-subject": "something FI" } request = apply_request_middleware(rf.post("/", data)) response = ScriptTemplateConfigView.as_view()(request, id=identifier) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") script = Script.objects.first() assert script is not None _assert_generic_script(script_template_cls, script, data) # edit data.update({ "en-body": "my body 2", "en-subject": "something 2" }) request = apply_request_middleware(rf.post("/", data)) response = ScriptTemplateEditView.as_view()(request, pk=script.pk) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") assert Script.objects.count() == 1 edited_script = Script.objects.first() _assert_generic_script(script_template_cls, edited_script, data)
def test_generic_script_template_admin(rf, admin_user, script_template_cls): get_default_shop() Script.objects.all().delete() identifier = script_template_cls.identifier # should redirect us since the script template has a bound form request = apply_request_middleware(rf.post("/", {"id": identifier}), user=admin_user) response = ScriptTemplateView.as_view()(request) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script-template-config", kwargs={"id": identifier}) assert Script.objects.count() == 0 # create data = { "base-send_to": "customer", "en-body": "my body", "en-subject": "something", "fi-body": "my body FI", "fi-subject": "something FI" } request = apply_request_middleware(rf.post("/", data), user=admin_user) response = ScriptTemplateConfigView.as_view()(request, id=identifier) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") script = Script.objects.first() assert script is not None _assert_generic_script(script_template_cls, script, data) # edit data.update({ "en-body": "my body 2", "en-subject": "something 2" }) request = apply_request_middleware(rf.post("/", data), user=admin_user) response = ScriptTemplateEditView.as_view()(request, pk=script.pk) assert response.status_code == 302 assert response.url == reverse("shuup_admin:notify.script.list") assert Script.objects.count() == 1 edited_script = Script.objects.first() _assert_generic_script(script_template_cls, edited_script, data)