-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-19910: add e2e tests for currency endpoints #275
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
Empty file.
Empty file.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import string | ||
|
|
||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def currencies_service(mpt_ops): | ||
| return mpt_ops.exchange.currencies | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_currencies_service(async_mpt_ops): | ||
| return async_mpt_ops.exchange.currencies | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def currency_id(e2e_config): | ||
| return e2e_config["exchange.currency.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def currency_data(short_uuid): | ||
| digit_to_alpha = str.maketrans(string.digits, "GHIJKLMNOP") | ||
| code = short_uuid[:3].translate(digit_to_alpha).upper() | ||
| return { | ||
| "name": f"e2e - please delete {short_uuid}", | ||
| "code": code, | ||
| "precision": 2, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_currency(currencies_service, currency_data, logo_fd): | ||
| currency = currencies_service.create(currency_data, file=logo_fd) | ||
|
|
||
| yield currency | ||
|
|
||
| try: | ||
| currencies_service.delete(currency.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_created_currency(async_currencies_service, currency_data, logo_fd): | ||
| currency = await async_currencies_service.create(currency_data, file=logo_fd) | ||
|
|
||
| yield currency | ||
|
|
||
| try: | ||
| await async_currencies_service.delete(currency.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421 | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.models import FileModel | ||
| from tests.e2e.helper import assert_async_service_filter_with_iterate | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| def test_create_currency(async_created_currency, currency_data): | ||
| result = async_created_currency.code | ||
|
|
||
| assert result == currency_data["code"] | ||
|
|
||
|
|
||
| async def test_get_currency(async_currencies_service, currency_id): | ||
| result = await async_currencies_service.get(currency_id) | ||
|
|
||
| assert result.id == currency_id | ||
|
|
||
|
|
||
| async def test_get_currency_not_found(async_currencies_service): | ||
| bogus_id = "CUR-0000-0000" | ||
|
|
||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| await async_currencies_service.get(bogus_id) | ||
|
|
||
|
|
||
| async def test_update_currency( | ||
| async_currencies_service, async_created_currency, logo_fd, short_uuid | ||
| ): | ||
| update_data = {"name": f"e2e - please delete {short_uuid}"} | ||
|
|
||
| result = await async_currencies_service.update( | ||
| async_created_currency.id, update_data, file=logo_fd | ||
| ) | ||
|
albertsola marked this conversation as resolved.
|
||
|
|
||
| assert result.name == update_data["name"] | ||
|
|
||
|
|
||
| async def test_delete_currency(async_currencies_service, async_created_currency): | ||
| await async_currencies_service.delete(async_created_currency.id) # act | ||
|
|
||
|
|
||
| async def test_filter_currencies(async_currencies_service, currency_id): | ||
| await assert_async_service_filter_with_iterate( | ||
| async_currencies_service, currency_id, None | ||
| ) # act | ||
|
|
||
|
|
||
| async def test_download_icon(async_currencies_service, async_created_currency): | ||
| result = await async_currencies_service.download_icon(async_created_currency.id) | ||
|
|
||
| assert isinstance(result, FileModel) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.models import FileModel | ||
| from tests.e2e.helper import assert_service_filter_with_iterate | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| def test_create_currency(created_currency, currency_data): | ||
| result = created_currency.code | ||
|
|
||
| assert result == currency_data["code"] | ||
|
|
||
|
|
||
| def test_get_currency(currencies_service, currency_id): | ||
| result = currencies_service.get(currency_id) | ||
|
|
||
| assert result.id == currency_id | ||
|
|
||
|
|
||
| def test_get_currency_not_found(currencies_service): | ||
| bogus_id = "CUR-0000-0000" | ||
|
|
||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| currencies_service.get(bogus_id) | ||
|
|
||
|
|
||
| def test_update_currency(currencies_service, created_currency, logo_fd, short_uuid): | ||
| update_data = {"name": f"e2e - please delete {short_uuid}"} | ||
|
|
||
| result = currencies_service.update(created_currency.id, update_data, file=logo_fd) | ||
|
|
||
|
albertsola marked this conversation as resolved.
|
||
| assert result.name == update_data["name"] | ||
|
|
||
|
|
||
| def test_delete_currency(currencies_service, created_currency): | ||
| currencies_service.delete(created_currency.id) # act | ||
|
|
||
|
|
||
| def test_filter_currencies(currencies_service, currency_id): | ||
| assert_service_filter_with_iterate(currencies_service, currency_id, None) # act | ||
|
|
||
|
|
||
| def test_download_icon(currencies_service, created_currency): | ||
| result = currencies_service.download_icon(created_currency.id) | ||
|
|
||
| assert isinstance(result, FileModel) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.