Ejemplo n.º 1
0
def change_beneficiary_email(body: ChangeBeneficiaryEmailBody) -> None:
    try:
        users_api.change_user_email(body.token)
    except InvalidTokenError as error:
        errors = ApiErrors()
        errors.status_code = 400
        raise errors from error
Ejemplo n.º 2
0
    def test_change_user_email_current_email_not_existing_anymore(self):
        # Given
        expiration_date = datetime.now() + timedelta(hours=1)
        token_payload = dict(current_email="*****@*****.**", new_email="*****@*****.**")
        token = encode_jwt_payload(token_payload, expiration_date)

        # When
        users_api.change_user_email(token)

        # Then
        old_user = User.query.filter_by(email="*****@*****.**").first()
        assert old_user is None
        new_user = User.query.filter_by(email="*****@*****.**").first()
        assert new_user is None
Ejemplo n.º 3
0
    def test_change_user_email_undecodable_token(self):
        # Given
        users_factories.UserFactory(email="*****@*****.**", firstName="UniqueNameForEmailChangeTest")
        token = "wtftokenwhatareyoutryingtodo"

        # When
        with pytest.raises(jwt.exceptions.InvalidTokenError):
            users_api.change_user_email(token)

        # Then
        old_user = User.query.filter_by(email="*****@*****.**").first()
        assert old_user is not None
        new_user = User.query.filter_by(email="*****@*****.**").first()
        assert new_user is None
Ejemplo n.º 4
0
    def test_change_user_email_new_email_already_existing(self):
        # Given
        users_factories.UserFactory(email="*****@*****.**", firstName="UniqueNameForEmailChangeTest")
        expiration_date = datetime.now() + timedelta(hours=1)
        token_payload = dict(current_email="*****@*****.**", new_email="*****@*****.**")
        token = encode_jwt_payload(token_payload, expiration_date)

        # When
        users_api.change_user_email(token)

        # Then
        old_user = User.query.filter_by(email="*****@*****.**").first()
        assert old_user is None
        new_user = User.query.filter_by(email="*****@*****.**").first()
        assert new_user is not None
Ejemplo n.º 5
0
    def test_change_user_email_expired_token(self):
        # Given
        users_factories.UserFactory(email="*****@*****.**", firstName="UniqueNameForEmailChangeTest")
        expiration_date = datetime.now() - timedelta(hours=1)
        token_payload = dict(current_email="*****@*****.**", new_email="*****@*****.**")
        token = encode_jwt_payload(token_payload, expiration_date)

        # When
        with pytest.raises(jwt.exceptions.InvalidTokenError):
            users_api.change_user_email(token)

        # Then
        old_user = User.query.filter_by(email="*****@*****.**").first()
        assert old_user is not None
        new_user = User.query.filter_by(email="*****@*****.**").first()
        assert new_user is None
Ejemplo n.º 6
0
    def test_change_user_email(self):
        # Given
        user = users_factories.UserFactory(email="*****@*****.**", firstName="UniqueNameForEmailChangeTest")
        users_factories.UserSessionFactory(user=user)
        expiration_date = datetime.now() + timedelta(hours=1)
        token_payload = dict(current_email="*****@*****.**", new_email="*****@*****.**")
        token = encode_jwt_payload(token_payload, expiration_date)

        # When
        users_api.change_user_email(token)

        # Then
        assert user.email == "*****@*****.**"
        new_user = User.query.filter_by(email="*****@*****.**").first()
        assert new_user is not None
        assert new_user.firstName == "UniqueNameForEmailChangeTest"
        old_user = User.query.filter_by(email="*****@*****.**").first()
        assert old_user is None
        assert UserSession.query.filter_by(userId=user.id).first() is None