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

    new_user = User(from_dict=request.json)

    if IS_INTEGRATION:
        new_user.departementCode = '00'
        objects_to_save.append(_create_initial_deposit(new_user))
    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.canBookFreeOffers = False
    new_user.isAdmin = False
    objects_to_save.append(new_user)

    PcObject.save(*objects_to_save)

    if request.json.get('contact_ok'):
        try:
            subscribe_newsletter(new_user)
        except MailServiceException as e:
            app.logger.error('Mail service failure', e)

    return jsonify(as_dict(new_user, includes=USER_INCLUDES)), 201
示例#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.']
示例#3
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
示例#4
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.'
    ]
示例#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'] == [
        'Le mot de passe doit faire au moins 12 caractères et contenir à minima 1 majuscule, 1 minuscule, 1 chiffre et 1 caractère spécial parmi '
        '_-&?~#|^@=+.$,<>%*!:;'
    ]