def test_provider_provides_fields(rf, admin_user): if "shuup.front.apps.registration" not in settings.INSTALLED_APPS: pytest.skip("shuup.front.apps.registration required in installed apps") shop = get_default_shop() with override_provides( "front_registration_field_provider", [ "shuup_tests.front.utils.FieldTestProvider", ], ): current_username = "******" request = apply_request_middleware(rf.post("/"), shop=shop) payload = {"username": current_username, "password1": "asdf", "password2": "asdf", "email": "*****@*****.**"} form = PersonRegistrationForm(request=request, data=payload) assert FieldTestProvider.key in form.fields assert not form.is_valid() assert form.errors[FieldTestProvider.key][0] == FieldTestProvider.error_msg # accept terms payload.update({FieldTestProvider.key: True}) form = PersonRegistrationForm(request=request, data=payload) assert FieldTestProvider.key in form.fields assert form.is_valid() # test signal fires person_registration_save.connect(change_username_signal, dispatch_uid="test_registration_change_username") user = form.save() assert user.username != current_username assert user.username == "changed_username" person_registration_save.disconnect(dispatch_uid="test_registration_change_username")
def test_provider_provides_fields(rf, admin_user): if "shuup.front.apps.registration" not in settings.INSTALLED_APPS: pytest.skip("shuup.front.apps.registration required in installed apps") shop = get_default_shop() with override_provides("front_registration_field_provider", [ "shuup_tests.front.utils.FieldTestProvider", ]): current_username = "******" request = apply_request_middleware(rf.post("/"), shop=shop) payload = { "username": current_username, "password1": "asdf", "password2": "asdf", "email": "*****@*****.**" } form = PersonRegistrationForm(request=request, data=payload) assert FieldTestProvider.key in form.fields assert not form.is_valid() assert form.errors[FieldTestProvider.key][0] == FieldTestProvider.error_msg # accept terms payload.update({FieldTestProvider.key: True}) form = PersonRegistrationForm(request=request, data=payload) assert FieldTestProvider.key in form.fields assert form.is_valid() # test signal fires person_registration_save.connect(change_username_signal, dispatch_uid="test_registration_change_username") user = form.save() assert user.username != current_username assert user.username == "changed_username" person_registration_save.disconnect(dispatch_uid="test_registration_change_username")