From 847c9e10cd6eddf51377ea14f48441b4dbcaed3f Mon Sep 17 00:00:00 2001 From: Trevor Visser Date: Mon, 20 May 2024 12:09:13 +0200 Subject: [PATCH] test: adjusted tests to handle random internal server errors from Revolut --- Makefile | 6 +++--- tests/test_foreign_exchange.py | 16 ++++++++-------- tests/test_payment_drafts.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index e658265..7d8ea5c 100644 --- a/Makefile +++ b/Makefile @@ -33,13 +33,13 @@ test-gen-creds: test-lint: @echo "Running lint tests..." - @poetry run python -m black pyrevolut tests - @poetry run python -m ruff check pyrevolut/ tests/ --fix + @poetry run black pyrevolut tests + @poetry run ruff check pyrevolut/ tests/ --fix @echo "Lint tests complete!" test-integration: @echo "Running integration tests..." - @poetry run python -m pytest -n 1 --dist=loadfile --cov-report term-missing --cov-report=xml:coverage.xml --cov=pyrevolut tests + @poetry run pytest -n 1 --dist=loadfile --cov-report term-missing --cov-report=xml:coverage.xml --cov=pyrevolut tests @echo "Integration tests complete!" test: diff --git a/tests/test_foreign_exchange.py b/tests/test_foreign_exchange.py index 857cc81..e5614e7 100644 --- a/tests/test_foreign_exchange.py +++ b/tests/test_foreign_exchange.py @@ -92,10 +92,7 @@ def test_sync_exchange_money(sync_client: Client): assert gbp_balance2 > gbp_balance assert eur_balance2 == eur_balance - 1.0 - with pytest.raises( - InternalRevolutError, - match="Oops! An error occurred while processing your request.", - ): + try: # Exchange 1 EUR from GBP to EUR response = sync_client.ForeignExchange.exchange_money( request_id=str(uuid4()), @@ -128,6 +125,9 @@ def test_sync_exchange_money(sync_client: Client): assert gbp_balance3 < gbp_balance2 assert eur_balance3 == eur_balance assert eur_balance3 > eur_balance2 + except InternalRevolutError: + # This error occurs randomly in the sandbox environment + pass @pytest.mark.asyncio @@ -215,10 +215,7 @@ async def test_async_exchange_money(async_client: AsyncClient): assert gbp_balance2 > gbp_balance assert eur_balance2 == eur_balance - 1.0 - with pytest.raises( - InternalRevolutError, - match="Oops! An error occurred while processing your request.", - ): + try: # Exchange 1 EUR from GBP to EUR response = await async_client.ForeignExchange.exchange_money( request_id=str(uuid4()), @@ -251,3 +248,6 @@ async def test_async_exchange_money(async_client: AsyncClient): assert gbp_balance3 < gbp_balance2 assert eur_balance3 == eur_balance assert eur_balance3 > eur_balance2 + except InternalRevolutError: + # This error occurs randomly in the sandbox environment + pass diff --git a/tests/test_payment_drafts.py b/tests/test_payment_drafts.py index 19d418f..3637b92 100644 --- a/tests/test_payment_drafts.py +++ b/tests/test_payment_drafts.py @@ -5,7 +5,7 @@ from pyrevolut.client import Client from pyrevolut.api import EnumAccountState -from pyrevolut.exceptions import PyRevolutAPIException +from pyrevolut.exceptions import InternalRevolutError def test_sync_get_all_payment_drafts(sync_client: Client): @@ -61,10 +61,7 @@ def test_sync_create_delete_payment_draft(sync_client: Client): recipient for recipient in recipients if recipient["country"] == "GB" ) - with pytest.raises( - PyRevolutAPIException, - match="Oops! An error occurred while processing your request. It has been logged for further investigation.", - ): + try: # Create a payment draft response = sync_client.PaymentDrafts.create_payment_draft( account_id=gbp_account["id"], @@ -82,6 +79,9 @@ def test_sync_create_delete_payment_draft(sync_client: Client): # Delete the payment draft sync_client.PaymentDrafts.delete_payment_draft(payment_draft_id=response["id"]) time.sleep(random.randint(1, 3)) + except InternalRevolutError: + # This error occurs randomly in the sandbox environment + pass @pytest.mark.asyncio @@ -140,10 +140,7 @@ async def test_async_create_delete_payment_draft(async_client: Client): recipient for recipient in recipients if recipient["country"] == "GB" ) - with pytest.raises( - PyRevolutAPIException, - match="Oops! An error occurred while processing your request. It has been logged for further investigation.", - ): + try: # Create a payment draft response = await async_client.PaymentDrafts.create_payment_draft( account_id=gbp_account["id"], @@ -163,3 +160,6 @@ async def test_async_create_delete_payment_draft(async_client: Client): payment_draft_id=response["id"] ) await asyncio.sleep(random.randint(1, 3)) + except InternalRevolutError: + # This error occurs randomly in the sandbox environment + pass