コード例 #1
0
def test_user_creator_with_valide_data(email, password):
    created = UserCreator(data={
        "email": email,
        "password": password,
    })()

    created.refresh_from_db()

    assert created.email == email
    assert created.is_active == True
コード例 #2
0
def test_token_after_creating_user():
    created = UserCreator(data={
        "email": "*****@*****.**",
        "password": "******",
    })()

    assert Token.objects.get(user=created)
コード例 #3
0
def test_user_with_same_email_case_is_case_insensetive(user):
    with pytest.raises(ValidationError) as exc:
        created = UserCreator(data={
            "email": "*****@*****.**",
            "password": "******",
        })()

    assert str(exc.value) == AccountErrorMessages.NON_UNIQUE_EMAIL_ERROR.value
コード例 #4
0
def test_user_with_same_email(user):
    with pytest.raises(ValidationError) as exc:
        created = UserCreator(data={
            "email": "*****@*****.**",
            "password": "******",
        })()

    assert str(exc.value) == AccountErrorMessages.NON_UNIQUE_EMAIL_ERROR.value
コード例 #5
0
def test_user_creator_with_invalid_password(email, password):
    with pytest.raises(ValidationError) as exc:
        created = UserCreator(data={
            "email": email,
            "password": password,
        })()

    assert str(exc.value
               ) == AccountErrorMessages.INCORRECT_PASSWORD_SCHEME_ERROR.value
コード例 #6
0
ファイル: views.py プロジェクト: 3asyPe/astudy
def create_account_api(request, *args, **kwargs):
    try:
        user = UserCreator(data=request.data)()
    except ValidationError as exc:
        logger.exception("A validation error occured during account creation")
        return Response({"error": str(exc)}, status=400)

    token = AccountToolkit.get_or_create_token(user=user)

    logger.info(f"New account with email - {user.email} is created")
    return Response(
        {
            'token': token.key,
            'user_id': user.id,
            'email': user.email,
            'admin': user.is_admin,
        },
        status=201)
コード例 #7
0
def test_user_creator_with_empty_password(password):
    with pytest.raises(RestValidationError) as exc:
        created = UserCreator(data={
            "email": "*****@*****.**",
            "password": password,
        })()
コード例 #8
0
def test_user_creator_with_invalid_email(email):
    with pytest.raises(RestValidationError) as exc:
        created = UserCreator(data={
            "email": email,
            "password": "******"
        })()