def test_provider_provides_definitions(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_company_registration_form_provider", ["shuup_tests.front.utils.FormDefTestProvider"]): with override_provides("front_registration_field_provider", ["shuup_tests.front.utils.FieldTestProvider"]): request = apply_request_middleware(rf.post("/"), shop=shop) current_username = "******" current_name = "123" payload = { "company-tax_number": "123", "company-name": current_name, "billing-country": "US", "billing-city": "city", "billing-street": "street", "contact_person-last_name": "last", "contact_person-first_name": "first", "contact_person-email": "*****@*****.**", "user_account-password1": "asdf123", "user_account-password2": "asdf123", "user_account-username": current_username, } form_group = CompanyRegistrationForm(request=request, data=payload) assert FormDefTestProvider.test_name in form_group.form_defs # test CompanyRegistrationForm itself assert "company" in form_group.form_defs assert "billing" in form_group.form_defs assert "contact_person" in form_group.form_defs assert "user_account" in form_group.form_defs assert form_group.form_defs["billing"].form_class == cached_load("SHUUP_ADDRESS_MODEL_FORM") assert not form_group.is_valid() assert FormDefTestProvider.test_name in form_group.errors assert FieldTestProvider.key in form_group.errors[FormDefTestProvider.test_name] assert len(form_group.errors) == 1 # no other errors key = "%s-%s" % (FormDefTestProvider.test_name, FieldTestProvider.key) payload.update({key: 1}) form_group = CompanyRegistrationForm(request=request, data=payload) assert FormDefTestProvider.test_name in form_group.form_defs assert form_group.is_valid() assert FormDefTestProvider.test_name not in form_group.errors assert not len(form_group.errors) # no errors # test signal fires company_registration_save.connect( change_company_signal, dispatch_uid="test_registration_change_company_signal" ) form_group.save(commit=True) assert not User.objects.filter(username=username).exists() assert not CompanyContact.objects.filter(name=current_name).exists() assert User.objects.filter(username="******").exists() assert CompanyContact.objects.filter(name="changed_name").exists() company_registration_save.disconnect(dispatch_uid="test_registration_change_company_signal")
def test_provider_provides_definitions(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_company_registration_form_provider", ["shuup_tests.front.utils.FormDefTestProvider"]): with override_provides("front_registration_field_provider", ["shuup_tests.front.utils.FieldTestProvider"]): request = apply_request_middleware(rf.post("/"), shop=shop) current_username = "******" current_name = "123" payload = { 'company-tax_number':"123", 'company-name': current_name, 'billing-country': "US", 'billing-city': "city", 'billing-street': "street", 'contact_person-last_name': "last", 'contact_person-first_name': "first", 'contact_person-email': "*****@*****.**", 'user_account-password1': "asdf123", 'user_account-password2': "asdf123", 'user_account-username': current_username } form_group = CompanyRegistrationForm(request=request, data=payload) assert FormDefTestProvider.test_name in form_group.form_defs # test CompanyRegistrationForm itself assert "company" in form_group.form_defs assert "billing" in form_group.form_defs assert "contact_person" in form_group.form_defs assert "user_account" in form_group.form_defs assert form_group.form_defs["billing"].form_class == cached_load('SHUUP_ADDRESS_MODEL_FORM') assert not form_group.is_valid() assert FormDefTestProvider.test_name in form_group.errors assert FieldTestProvider.key in form_group.errors[FormDefTestProvider.test_name] assert len(form_group.errors) == 1 # no other errors key = "%s-%s" % (FormDefTestProvider.test_name, FieldTestProvider.key) payload.update({key: 1}) form_group = CompanyRegistrationForm(request=request, data=payload) assert FormDefTestProvider.test_name in form_group.form_defs assert form_group.is_valid() assert FormDefTestProvider.test_name not in form_group.errors assert not len(form_group.errors) # no errors # test signal fires company_registration_save.connect( change_company_signal, dispatch_uid="test_registration_change_company_signal") form_group.save(commit=True) assert not User.objects.filter(username=username).exists() assert not CompanyContact.objects.filter(name=current_name).exists() assert User.objects.filter(username="******").exists() assert CompanyContact.objects.filter(name="changed_name").exists() company_registration_save.disconnect(dispatch_uid="test_registration_change_company_signal")