コード例 #1
0
def test_get_list_of_employers_api():
    user, token = create_user_and_token_for_tests()
    account = create_account_for_tests()
    number_of_employers = 4
    for i in range(number_of_employers):
        employer_data = Employer(name=f"Test {i}", associated_account_id=account.id)
        create_employer(employer_data)
    response = client.get(
        "/finance/employers/get-list",
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    response_data = response.json()
    assert len(response_data) == number_of_employers
コード例 #2
0
def test_delete_employer_api():
    user, token = create_user_and_token_for_tests()
    account = create_account_for_tests()
    employer = create_employer(Employer(name="Test", associated_account_id=account.id))
    response = client.delete(
        "/finance/employers/delete",
        data=employer.json(),
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
コード例 #3
0
ファイル: test_crud_employers.py プロジェクト: Nihisil/Keeper
def test_update_employer():
    account = create_account_for_tests()
    employer_data = Employer(name="Test", associated_account_id=account.id)
    employer = create_employer(employer_data)
    assert employer.id is not None
    assert employer.updated is not None

    updated_employer = Employer(**employer_data.dict())
    updated_employer.name = "New one"
    updated_employer = update_employer(updated_employer)

    assert updated_employer.id == employer.id
    assert updated_employer.name != employer.name
コード例 #4
0
ファイル: test_crud_employers.py プロジェクト: Nihisil/Keeper
def test_get_employers_list():
    account = create_account_for_tests()
    number_of_employers = 4
    for i in range(number_of_employers):
        employer = create_employer(Employer(name=f"Test {i}", associated_account_id=account.id))
        create_transaction_for_tests(amount=i + 1, employer=employer)

    employers = get_employers_list()
    assert len(employers) == number_of_employers
    assert employers[0].earnings == 4
    assert employers[0].earnings_currency is not None
    assert employers[1].earnings == 3
    assert employers[2].earnings == 2
    assert employers[3].earnings == 1
コード例 #5
0
def test_update_employer_api():
    user, token = create_user_and_token_for_tests()
    account = create_account_for_tests()
    employer = create_employer(Employer(name="Test", associated_account_id=account.id))
    new_data = Employer(**employer.dict())
    new_data.name = "Updated"
    response = client.put(
        "/finance/employers/update",
        data=new_data.json(),
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    response_data = response.json()
    assert response_data["name"] == new_data.name
コード例 #6
0
ファイル: test_crud_employers.py プロジェクト: Nihisil/Keeper
def test_create_employer():
    account = create_account_for_tests()
    employer_data = Employer(name="Test", associated_account_id=account.id)
    employer = create_employer(employer_data)
    assert employer.id is not None
    assert employer.updated is not None
コード例 #7
0
ファイル: test_crud_employers.py プロジェクト: Nihisil/Keeper
def test_delete_employer():
    account = create_account_for_tests()
    employer = create_employer(Employer(name="Test", associated_account_id=account.id))
    delete_employer(employer)
    assert len(get_employers_list()) == 0
コード例 #8
0
ファイル: utils.py プロジェクト: Nihisil/Keeper
def create_employer_for_tests(account: Optional[Account] = None) -> Employer:
    if not account:
        account = create_account_for_tests()
    return create_employer(
        Employer(name=get_random_string_and_numbers(12),
                 associated_account_id=account.id))
コード例 #9
0
def create_employer_api(data: Employer) -> Employer:
    return create_employer(data)