-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: align test suits #39
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c66febd
feat: remove useless type hints, remove comments and rename tests ins…
AlexTheWizardL cc49ce7
fix: align test suits missed type hints
AlexTheWizardL d312393
refactor: Align mock directories in tests
lasuk ee37248
feat: use comments instead of docstring, move nack valuable docstrings
AlexTheWizardL 05262a7
fix: call base class method to circumvent the cache
AlexTheWizardL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,88 @@ | ||
"""Unit tests for cached accounts.""" | ||
|
||
import time | ||
from cashctrl_api import CachedCashCtrlClient | ||
from cashctrl_api import CachedCashCtrlClient, CashCtrlClient | ||
import pandas as pd | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cc_client() -> CachedCashCtrlClient: | ||
def cc_client(): | ||
return CachedCashCtrlClient() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any benefit of using a fixture? |
||
def accounts() -> pd.DataFrame: | ||
"""Explicitly call the base class method to circumvent the cache.""" | ||
cc_client = CachedCashCtrlClient() | ||
return cc_client.list_accounts() | ||
def accounts(cc_client): | ||
# Explicitly call the base class method to circumvent the cache. | ||
return CashCtrlClient.list_accounts(cc_client) | ||
|
||
|
||
def test_account_cache_is_none_on_init(cc_client: CachedCashCtrlClient) -> None: | ||
def test_account_cache_is_none_on_init(cc_client): | ||
assert cc_client._accounts_cache is None | ||
assert cc_client._accounts_cache_time is None | ||
|
||
|
||
def test_cached_accounts_same_to_actual( | ||
cc_client: CachedCashCtrlClient, accounts: pd.DataFrame | ||
) -> None: | ||
def test_cached_accounts_same_to_actual(cc_client, accounts): | ||
pd.testing.assert_frame_equal(cc_client.list_accounts(), accounts) | ||
|
||
|
||
def test_account_from_id( | ||
cc_client: CachedCashCtrlClient, accounts: pd.DataFrame | ||
) -> None: | ||
def test_account_from_id(cc_client, accounts): | ||
assert ( | ||
cc_client.account_from_id(accounts["id"].iat[0]) == accounts["number"].iat[0] | ||
), "Cached account number doesn't correspond actual number" | ||
|
||
|
||
def test_account_from_id_invalid_id_raises_error( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
def test_account_from_id_invalid_id_raises_error(cc_client): | ||
with pytest.raises(ValueError, match="No account found for id"): | ||
cc_client.account_from_id(99999999) | ||
|
||
|
||
def test_account_from_id_invalid_id_returns_none_with_allowed_missing( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
def test_account_from_id_invalid_id_returns_none_with_allowed_missing(cc_client): | ||
assert cc_client.account_from_id(99999999, allow_missing=True) is None | ||
|
||
|
||
def test_account_to_id( | ||
cc_client: CachedCashCtrlClient, accounts: pd.DataFrame | ||
) -> None: | ||
def test_account_to_id(cc_client, accounts): | ||
assert ( | ||
cc_client.account_to_id(accounts["number"].iat[1]) == accounts["id"].iat[1] | ||
), "Cached account id doesn't correspond actual id" | ||
|
||
|
||
def test_account_to_id_with_invalid_account_number_raises_error( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
def test_account_to_id_with_invalid_account_number_raises_error(cc_client): | ||
with pytest.raises(ValueError, match="No id found for account"): | ||
cc_client.account_to_id(99999999) | ||
|
||
|
||
def test_account_to_id_with_invalid_account_number_returns_none_with_allowed_missing( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
def test_account_to_id_with_invalid_account_number_returns_none_with_allowed_missing(cc_client): | ||
assert cc_client.account_to_id(99999999, allow_missing=True) is None | ||
|
||
|
||
def test_account_to_currency( | ||
cc_client: CachedCashCtrlClient, accounts: pd.DataFrame | ||
) -> None: | ||
def test_account_to_currency(cc_client, accounts): | ||
assert ( | ||
cc_client.account_to_currency(accounts["number"].iat[1]) | ||
== accounts["currencyCode"].iat[1] | ||
), "Cached account currency doesn't correspond actual currency" | ||
|
||
|
||
def test_account_to_currency_with_invalid_account_number_raises_error( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
def test_account_to_currency_with_invalid_account_number_raises_error(cc_client): | ||
with pytest.raises(ValueError, match="No currency found for account"): | ||
cc_client.account_to_currency(99999999) | ||
|
||
|
||
def test_account_to_currency_with_invalid_account_number_returns_none_with_allowed_missing( | ||
cc_client: CachedCashCtrlClient | ||
) -> None: | ||
cc_client | ||
): | ||
assert cc_client.account_to_currency(99999999, allow_missing=True) is None | ||
|
||
|
||
def test_account_cache_timeout() -> None: | ||
def test_account_cache_timeout(): | ||
cc_client = CachedCashCtrlClient(cache_timeout=1) | ||
cc_client.list_accounts() | ||
assert not cc_client._is_expired(cc_client._accounts_cache_time) | ||
time.sleep(1) | ||
assert cc_client._is_expired(cc_client._accounts_cache_time) | ||
|
||
|
||
def test_account_cache_invalidation() -> None: | ||
def test_account_cache_invalidation(): | ||
cc_client = CachedCashCtrlClient() | ||
cc_client.list_accounts() | ||
assert not cc_client._is_expired(cc_client._accounts_cache_time) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any benefit of using a fixture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only lines of code are reduced since no need to define a class instance in every test suit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided on the meeting to remove fixture for this case