def test_save_marketing_check(rf, admin_user): admin_contact = get_person_contact(admin_user) shop = get_default_shop() with override_settings(SHUUP_CHECKOUT_CONFIRM_FORM_PROPERTIES={}): request = apply_request_middleware(rf.get("/"), shop=shop, user=admin_user, customer=admin_contact) form = ConfirmForm(request=request) assert form.fields["marketing"].initial is False assert form.fields["marketing"].widget.__class__ == forms.CheckboxInput admin_contact.options = {} admin_contact.options["marketing_permission_asked"] = True admin_contact.save() form = ConfirmForm(request=request) assert form.fields["marketing"].initial is False assert form.fields["marketing"].widget.__class__ == forms.HiddenInput admin_contact.marketing_permission = True admin_contact.save() form = ConfirmForm(request=request) assert form.fields["marketing"].initial is True assert form.fields["marketing"].widget.__class__ == forms.HiddenInput # test with anonymous request = apply_request_middleware(rf.get("/"), shop=shop, user=admin_user, customer=AnonymousContact()) form = ConfirmForm(request=request) assert form.fields["marketing"].initial is False assert form.fields["marketing"].widget.__class__ == forms.CheckboxInput
def test_confirm_form_field_provides(rf): with override_provides("checkout_confirm_form_field_provider", ["shuup_tests.front.utils.FieldTestProvider"]): request = apply_request_middleware(rf.post("/"), shop=get_default_shop()) payload = {} # make form invalid form = ConfirmForm(request=request, data=payload) assert FieldTestProvider.key in form.fields assert not form.is_valid() assert form.errors[ FieldTestProvider.key][0] == FieldTestProvider.error_msg
def test_confirm_form_field_overrides(rf): with override_settings(SHUUP_CHECKOUT_CONFIRM_FORM_PROPERTIES={}): request = apply_request_middleware(rf.get("/"), shop=get_default_shop()) form = ConfirmForm(request=request) assert type(form.fields["comment"].widget) != forms.HiddenInput assert form.fields["marketing"].initial is False with override_settings( SHUUP_CHECKOUT_CONFIRM_FORM_PROPERTIES={ "comment": {"widget": forms.HiddenInput()}, "marketing": {"initial": True} } ): form = ConfirmForm(request=request) assert type(form.fields["comment"].widget) == forms.HiddenInput assert form.fields["marketing"].initial is True
def test_confirm_form_field_overrides(): with override_settings(SHUUP_CHECKOUT_CONFIRM_FORM_PROPERTIES={}): form = ConfirmForm() assert type(form.fields["comment"].widget) != forms.HiddenInput assert form.fields["marketing"].initial is False with override_settings(SHUUP_CHECKOUT_CONFIRM_FORM_PROPERTIES={ "comment": { "widget": forms.HiddenInput() }, "marketing": { "initial": True } }): form = ConfirmForm() assert type(form.fields["comment"].widget) == forms.HiddenInput assert form.fields["marketing"].initial is True