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
def test_token_after_creating_user(): created = UserCreator(data={ "email": "*****@*****.**", "password": "******", })() assert Token.objects.get(user=created)
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
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
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
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)
def test_user_creator_with_empty_password(password): with pytest.raises(RestValidationError) as exc: created = UserCreator(data={ "email": "*****@*****.**", "password": password, })()
def test_user_creator_with_invalid_email(email): with pytest.raises(RestValidationError) as exc: created = UserCreator(data={ "email": email, "password": "******" })()