Example #1
0
def signup_webapp():
    objects_to_save = []
    check_valid_signup_webapp(request)

    new_user = User(from_dict=request.json)
    new_user.email = sanitize_email(new_user.email)
    new_user.notificationSubscriptions = asdict(
        NotificationSubscriptions(marketing_email=bool(request.json.get("contact_ok")))
    )

    if settings.IS_INTEGRATION:
        objects_to_save.append(payments_api.create_deposit(new_user, "test"))
    else:
        authorized_emails, departement_codes = get_authorized_emails_and_dept_codes(ttl_hash=get_ttl_hash())
        departement_code = _get_departement_code_when_authorized_or_error(authorized_emails, departement_codes)
        new_user.departementCode = departement_code

    new_user.remove_admin_role()
    new_user.remove_beneficiary_role()
    new_user.isEmailValidated = True
    new_user.needsToFillCulturalSurvey = False
    new_user.hasSeenTutorials = True
    objects_to_save.append(new_user)

    repository.save(*objects_to_save)

    update_external_user(new_user)

    return jsonify(as_dict(new_user, includes=BENEFICIARY_INCLUDES)), 201
Example #2
0
def test_check_valid_signup_webapp_raises_api_error_if_no_email():
    # Given
    mocked_request = Mock()
    mocked_request.json = {"contact_ok": True, "password": "******"}

    # When
    with pytest.raises(ApiErrors) as errors:
        check_valid_signup_webapp(mocked_request)

    # Then
    assert errors.value.errors["email"] == ["Vous devez renseigner un email."]
Example #3
0
def test_check_valid_signup_webapp_raises_api_error_if_not_contact_ok():
    # Given
    mocked_request = Mock()
    mocked_request.json = {
        "password": "******",
        "email": "*****@*****.**"
    }

    # When
    with pytest.raises(ApiErrors) as errors:
        check_valid_signup_webapp(mocked_request)

    # Then
    assert errors.value.errors["contact_ok"] == [
        "Vous devez obligatoirement cocher cette case."
    ]
Example #4
0
def test_check_valid_signup_webapp_does_not_raise_api_error_if_contact_ok_is_true_has_password_and_email(
):
    # Given
    mocked_request = Mock()
    mocked_request.json = {
        "password": "******",
        "email": "*****@*****.**",
        "contact_ok": True
    }

    # When
    try:
        check_valid_signup_webapp(mocked_request)
    except ApiErrors:
        # Then
        assert False
Example #5
0
def test_check_valid_signup_webapp_raises_api_error_if_password_is_not_strong_enough(
):
    # Given
    mocked_request = Mock()
    mocked_request.json = {
        "contact_ok": True,
        "email": "*****@*****.**",
        "password": "******"
    }

    # When
    with pytest.raises(ApiErrors) as errors:
        check_valid_signup_webapp(mocked_request)

    # Then
    assert errors.value.errors["password"] == [
        "Ton mot de passe doit contenir au moins :\n"
        "- 12 caractères\n"
        "- Un chiffre\n"
        "- Une majuscule et une minuscule\n"
        "- Un caractère spécial"
    ]
Example #6
0
def signup_webapp():
    objects_to_save = []
    check_valid_signup_webapp(request)

    new_user = User(from_dict=request.json)
    if request.json.get("contact_ok"):
        new_user.hasAllowedRecommendations = True

    if settings.IS_INTEGRATION:
        new_user.departementCode = "00"
        objects_to_save.append(payments_api.create_deposit(new_user, "test"))
    else:
        authorized_emails, departement_codes = get_authorized_emails_and_dept_codes()
        departement_code = _get_departement_code_when_authorized_or_error(authorized_emails, departement_codes)
        new_user.departementCode = departement_code

    new_user.isBeneficiary = False
    new_user.isAdmin = False
    new_user.isEmailValidated = True
    objects_to_save.append(new_user)

    repository.save(*objects_to_save)

    return jsonify(as_dict(new_user, includes=BENEFICIARY_INCLUDES)), 201