def test_company_edit_form_links_company(regular_user, allow_company_registration): get_default_shop() configuration.set(None, "allow_company_registration", allow_company_registration) person = get_person_contact(regular_user) assert not get_company_contact(regular_user) client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) data = default_company_data() data.update(default_address_data("billing")) data.update(default_address_data("shipping")) company_edit_url = reverse("wshop:company_edit") if allow_company_registration: soup = client.soup(company_edit_url) response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 assert get_company_contact(regular_user) else: response = client.get(company_edit_url) assert response.status_code == 404 response = client.post(company_edit_url, data) assert response.status_code == 404
def test_notify_on_company_created(regular_user, allow_company_registration): if "wshop.front.apps.customer_information" not in settings.INSTALLED_APPS: pytest.skip( "wshop.front.apps.customer_information required in installed apps") if "wshop.notify" not in settings.INSTALLED_APPS: pytest.skip("wshop.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("wshop: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 response.status_code == 404 assert Notification.objects.filter( identifier="company_created").count() == 0
def test_order_flow_with_phases(get_shipping_method, shipping_data, get_payment_method, payment_data): cache.clear() create_default_order_statuses() populate_if_required() c = SmartClient() _populate_client_basket(c) # Create methods shipping_method = get_shipping_method() payment_method = get_payment_method() # Resolve paths addresses_path = reverse("wshop:checkout", kwargs={"phase": "addresses"}) methods_path = reverse("wshop:checkout", kwargs={"phase": "methods"}) shipping_path = reverse("wshop:checkout", kwargs={"phase": "shipping"}) payment_path = reverse("wshop:checkout", kwargs={"phase": "payment"}) confirm_path = reverse("wshop:checkout", kwargs={"phase": "confirm"}) # Phase: Addresses addresses_soup = c.soup(addresses_path) inputs = fill_address_inputs(addresses_soup, with_company=False) response = c.post(addresses_path, data=inputs) assert response.status_code == 302, "Address phase should redirect forth to methods" # Phase: Methods response = c.get(methods_path) assert response.status_code == 200 response = c.post(methods_path, data={ "shipping_method": shipping_method.pk, "payment_method": payment_method.pk }) assert response.status_code == 302, "Methods phase should redirect forth" if isinstance(shipping_method.carrier, CarrierWithCheckoutPhase): # Phase: Shipping response = c.get(shipping_path) assert response.status_code == 200 response = c.post(shipping_path, data=shipping_data) assert response.status_code == 302, "Payments phase should redirect forth" if isinstance(payment_method.payment_processor, PaymentWithCheckoutPhase): # Phase: payment response = c.get(payment_path) assert response.status_code == 200 response = c.post(payment_path, data=payment_data) assert response.status_code == 302, "Payments phase should redirect forth" # Phase: Confirm assert Order.objects.count() == 0 confirm_soup = c.soup(confirm_path) response = c.post(confirm_path, data=extract_form_fields(confirm_soup)) assert response.status_code == 302, "Confirm should redirect forth" order = Order.objects.first() if isinstance(shipping_method.carrier, CarrierWithCheckoutPhase): assert order.shipping_data.get("input_value") == "20540" if isinstance(payment_method.payment_processor, PaymentWithCheckoutPhase): assert order.payment_data.get("input_value") assert order.payment_status == PaymentStatus.NOT_PAID # Resolve order specific paths (payment and complete) process_payment_path = reverse("wshop:order_process_payment", kwargs={ "pk": order.pk, "key": order.key }) process_payment_return_path = reverse( "wshop:order_process_payment_return", kwargs={ "pk": order.pk, "key": order.key }) order_complete_path = reverse("wshop:order_complete", kwargs={ "pk": order.pk, "key": order.key }) # Check confirm redirection to payment page assert response.url.endswith(process_payment_path), ( "Confirm should have redirected to payment page") # Visit payment page response = c.get(process_payment_path) assert response.status_code == 302, "Payment page should redirect forth" assert response.url.endswith(process_payment_return_path) # Check payment return response = c.get(process_payment_return_path) assert response.status_code == 302, "Payment return should redirect forth" assert response.url.endswith(order_complete_path) # Check payment status has changed to DEFERRED order = Order.objects.get(pk=order.pk) # reload assert order.payment_status == PaymentStatus.DEFERRED
def test_company_tax_number_limitations(regular_user, allow_company_registration): get_default_shop() configuration.set(None, "allow_company_registration", allow_company_registration) person = get_person_contact(regular_user) assert not get_company_contact(regular_user) if allow_company_registration: client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) company_edit_url = reverse("wshop:company_edit") soup = 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) # re-save should work properly response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 client.logout() # another company tries to use same tax number new_user_password = "******" new_user_username = "******" user = User.objects.create_user(new_user_username, "*****@*****.**", new_user_password) person = get_person_contact(user=user) assert not get_company_contact(user) client = SmartClient() client.login(username=new_user_username, password=new_user_password) company_edit_url = reverse("wshop:company_edit") soup = 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 == 200 # this time around, nothing was saved. assert not get_company_contact(user) # company contact yet # change tax number data["contact-tax_number"] = "111111" response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 302 # this time around, nothing was saved. assert get_company_contact(user) # company contact yet # go back to normal and try to get tax number approved data["contact-tax_number"] = "111110" response, soup = client.response_and_soup(company_edit_url, data, "post") assert response.status_code == 200 # this time around, nothing was saved. else: client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) company_edit_url = reverse("wshop:company_edit") response = client.get(company_edit_url) assert response.status_code == 404