Exemple #1
0
def test_email_auth_form(rf, regular_user):
    shop = get_default_shop()
    prepare_user(regular_user)
    payload = {
        "username": regular_user.username,
        "password": REGULAR_USER_PASSWORD,
    }
    request = apply_request_middleware(rf.get("/"), shop=shop)
    with override_provides("front_auth_form_field_provider", ["shuup_tests.front.utils.FieldTestProvider"]):

        form = EmailAuthenticationForm(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 = EmailAuthenticationForm(request=request, data=payload)
        assert FieldTestProvider.key in form.fields
        assert form.is_valid()

        login_allowed.connect(login_allowed_signal, dispatch_uid="test_login_allowed")
        with pytest.raises(ValidationError):
            form.confirm_login_allowed(regular_user)
        login_allowed.disconnect(dispatch_uid="test_login_allowed")
        form.confirm_login_allowed(regular_user)
Exemple #2
0
def test_email_auth_form(rf, regular_user):
    shop = get_default_shop()
    prepare_user(regular_user)
    payload = {
        "username": regular_user.username,
        "password": REGULAR_USER_PASSWORD,
    }
    request = apply_request_middleware(rf.get("/"), shop=shop)
    with override_provides("front_auth_form_field_provider", ["shuup_tests.front.utils.FieldTestProvider"]):

        form = EmailAuthenticationForm(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 = EmailAuthenticationForm(request=request, data=payload)
        assert FieldTestProvider.key in form.fields
        assert form.is_valid()

        login_allowed.connect(login_allowed_signal, dispatch_uid="test_login_allowed")
        with pytest.raises(ValidationError):
            form.confirm_login_allowed(regular_user)
        login_allowed.disconnect(dispatch_uid="test_login_allowed")
        form.confirm_login_allowed(regular_user)