def test_cannot_register_account_with_already_registered_email() -> None:
    uow = register_account_helper()

    with pytest.raises(
            AccountRegistrationError,
            match=f"Account with the email '{EMAIL_TALEL}' already exists"):
        register_account_helper(uow)
def test_cannot_register_account_with_already_registered_username() -> None:
    uow = register_account_helper()

    with pytest.raises(
            AccountRegistrationError,
            match=f"Account with the username '{USERNAME_TALEL}' already exists"
    ):
        register_account_helper(uow, EMAIL_BIANCA, USERNAME_TALEL)
def test_cannot_verify_already_verified_account() -> None:
    uow = register_account_helper()
    verify_account_helper(uow)

    with pytest.raises(AccountVerificationError,
                       match='Account already verified'):
        verify_account_helper(uow)
def test_can_register_account() -> None:
    uow = register_account_helper()
    account_record = uow.fake_db['account'][0]

    assert uow.committed
    assert account_record.email == EMAIL_TALEL
    assert account_record.user.username == USERNAME_TALEL
def test_can_get_access_token_for_user() -> None:
    uow = register_account_helper()
    access_token = get_access_token_helper(uow)

    username = Authentication().get_jwt_identity(access_token)['username']

    assert username == USERNAME_TALEL
def test_access_token_expires_after_30_min() -> None:
    thirtyone_mins_from_now = generate_time_from_now(1860)
    uow = register_account_helper()
    access_token = get_access_token_helper(uow)

    with freeze_time(thirtyone_mins_from_now):
        with pytest.raises(ExpiredSignatureError):
            Authentication.verify_token(access_token)
def test_can_verify_account() -> None:
    uow = register_account_helper()
    account_record = uow.fake_db['account'][0]

    assert not account_record.verified

    verify_account_helper(uow)

    assert account_record.verified
def test_can_get_user_projects() -> None:
    uow = register_account_helper()

    create_project_helper(uow)
    project_record = get_user_projects_helper(uow)

    assert len(project_record) == 1
    assert project_record[0].title == talelio_server_project['title']
    assert project_record[0].body == talelio_server_project['body']

    create_project_helper(uow, project=talelio_client_project)
    project_record = get_user_projects_helper(uow)

    assert len(project_record) == 2
    assert project_record[1].title == talelio_client_project['title']
    assert project_record[1].body == talelio_client_project['body']
def test_cannot_register_account_with_non_whitelisted_email() -> None:
    with pytest.raises(AccountRegistrationError,
                       match='Email not whitelisted'):
        register_account_helper()
def test_can_create_project() -> None:
    uow = register_account_helper()
    project_record = create_project_helper(uow)

    assert project_record[0].title == talelio_server_project['title']
    assert project_record[0].body == talelio_server_project['body']
def test_cannot_get_projects_for_non_existing_user() -> None:
    uow = register_account_helper()

    with pytest.raises(UserError,
                       match=f"User '{USERNAME_BIANCA}' does not exist"):
        get_user_projects_helper(uow, username=USERNAME_BIANCA)
def test_cannot_create_project_for_non_existing_user() -> None:
    uow = register_account_helper()

    with pytest.raises(UserError, match='User does not exist'):
        create_project_helper(uow, user_id=INITIAL_USER_ID + 1986)
def test_cannot_get_access_token_with_invalid_password() -> None:
    uow = register_account_helper()

    with pytest.raises(AccountError, match='Invalid username or password'):
        get_access_token_helper(uow, password='')