def test_run_multishop(): shop1 = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") event = get_initialized_test_event() step = Step(actions=[ AddOrderLogEntry({ "order": { "variable": "order" }, "message": { "constant": "It Works." }, "message_identifier": { "constant": "test_run" }, }) ], next=StepNext.STOP) script = Script(event_identifier=event.identifier, name="Test Script", shop=shop2, enabled=True) script.set_steps([step]) script.save() # runs for shop1 - no script exists event.run(shop1) assert not event.variable_values["order"].log_entries.filter( identifier="test_run").exists() # run for shop2 - ok event.run(shop2) assert event.variable_values["order"].log_entries.filter( identifier="test_run").exists() script.delete()
def test_run(): event = get_initialized_test_event() step = Step(actions=[ AddOrderLogEntry({ "order": { "variable": "order" }, "message": { "constant": "It Works." }, "message_identifier": { "constant": "test_run" }, }) ], next=StepNext.STOP) script = Script(event_identifier=event.identifier, name="Test Script") script.set_steps([step]) script.save() event.run() # The script is disabled by default, of course it won't run assert not event.variable_values["order"].log_entries.filter( identifier="test_run").exists() # Let's try that again. script.enabled = True script.save() event.run() assert event.variable_values["order"].log_entries.filter( identifier="test_run").exists() script.delete()
def test_notify_on_company_created(regular_user, allow_company_registration): if "shuup.front.apps.customer_information" not in settings.INSTALLED_APPS: pytest.skip("shuup.front.apps.customer_information required in installed apps") if "shuup.notify" not in settings.INSTALLED_APPS: pytest.skip("shuup.notify required in installed apps") configuration.set(None, "allow_company_registration", allow_company_registration) step = Step( cond_op=StepConditionOperator.NONE, actions=[ AddNotification( { "message": {"constant": "It Works. {{ customer_email }}"}, "message_identifier": {"constant": "company_created"}, } ) ], next=StepNext.STOP, ) script = Script( event_identifier=CompanyAccountCreated.identifier, name="Test Script", enabled=True, shop=get_default_shop() ) script.set_steps([step]) script.save() assert not Notification.objects.filter(identifier="company_created").exists() assert get_person_contact(regular_user) assert not get_company_contact(regular_user) client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) company_edit_url = reverse("shuup:company_edit") if allow_company_registration: client.soup(company_edit_url) data = _default_company_data() data.update(_default_address_data("billing")) data.update(_default_address_data("shipping")) response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 assert get_company_contact(regular_user) assert Notification.objects.filter(identifier="company_created").count() == 1 notification = Notification.objects.filter(identifier="company_created").first() assert notification assert data["contact-email"] in notification.message # New save should not add new notifications response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 assert Notification.objects.filter(identifier="company_created").count() == 1 script.delete() else: response = client.get(company_edit_url) assert reverse("shuup:customer_edit") in response.url assert Notification.objects.filter(identifier="company_created").count() == 0
def create_script(self, form=None): condition = BooleanEqual({ "v1": {"constant": True}, "v2": {"constant": False} }) script = Script(event_identifier=AlertLimitReached.identifier, name="Dummy Alert", enabled=True) script.set_steps([Step(next=StepNext.STOP, conditions=(condition,))]) script.save() return script
def create_script(self, shop, form=None): condition = BooleanEqual({ "v1": {"constant": True}, "v2": {"constant": False} }) script = Script(event_identifier=AlertLimitReached.identifier, name="Dummy Alert", enabled=True, shop=shop) script.set_steps([Step(next=StepNext.STOP, conditions=(condition,))]) script.save() return script
def test_notify_on_company_created(regular_user, allow_company_registration): if "shuup.front.apps.customer_information" not in settings.INSTALLED_APPS: pytest.skip("shuup.front.apps.customer_information required in installed apps") if "shuup.notify" not in settings.INSTALLED_APPS: pytest.skip("shuup.notify required in installed apps") configuration.set(None, "allow_company_registration", allow_company_registration) step = Step( cond_op=StepConditionOperator.NONE, actions=[ AddNotification({ "message": {"constant": "It Works. {{ customer_email }}"}, "message_identifier": {"constant": "company_created"}, }) ], next=StepNext.STOP ) script = Script( event_identifier=CompanyAccountCreated.identifier, name="Test Script", enabled=True, shop=get_default_shop()) script.set_steps([step]) script.save() assert not Notification.objects.filter(identifier="company_created").exists() assert get_person_contact(regular_user) assert not get_company_contact(regular_user) client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) company_edit_url = reverse("shuup:company_edit") if allow_company_registration: client.soup(company_edit_url) data = _default_company_data() data.update(_default_address_data("billing")) data.update(_default_address_data("shipping")) response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 assert get_company_contact(regular_user) assert Notification.objects.filter(identifier="company_created").count() == 1 notification = Notification.objects.filter(identifier="company_created").first() assert notification assert data["contact-email"] in notification.message # New save should not add new notifications response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 assert Notification.objects.filter(identifier="company_created").count() == 1 script.delete() else: response = client.get(company_edit_url) assert reverse("shuup:customer_edit") in response.url assert Notification.objects.filter(identifier="company_created").count() == 0
def test_run(): event = get_initialized_test_event() step = Step(actions=[AddOrderLogEntry({ "order": {"variable": "order"}, "message": {"constant": "It Works."}, "message_identifier": {"constant": "test_run"}, })], next=StepNext.STOP) script = Script(event_identifier=event.identifier, name="Test Script", shop=factories.get_default_shop()) script.set_steps([step]) script.save() event.run(factories.get_default_shop()) # The script is disabled by default, of course it won't run assert not event.variable_values["order"].log_entries.filter(identifier="test_run").exists() # Let's try that again. script.enabled = True script.save() event.run(factories.get_default_shop()) assert event.variable_values["order"].log_entries.filter(identifier="test_run").exists() script.delete()
def test_run_multishop(): shop1 = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") event = get_initialized_test_event() step = Step(actions=[AddOrderLogEntry({ "order": {"variable": "order"}, "message": {"constant": "It Works."}, "message_identifier": {"constant": "test_run"}, })], next=StepNext.STOP) script = Script(event_identifier=event.identifier, name="Test Script", shop=shop2, enabled=True) script.set_steps([step]) script.save() # runs for shop1 - no script exists event.run(shop1) assert not event.variable_values["order"].log_entries.filter(identifier="test_run").exists() # run for shop2 - ok event.run(shop2) assert event.variable_values["order"].log_entries.filter(identifier="test_run").exists() script.delete()