Skip to content

Commit

Permalink
add mock_settings fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 16, 2024
1 parent c8662d2 commit 3ea0af8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ def integration_test_id():
"%Y-%m-%d_%H-%M-%S_%f"
)
yield f"{prefix}.{timestamp}"


@pytest.fixture
def mock_settings():
from edutap.wallet_google.session import session_manager

yield session_manager.settings
del session_manager._settings
17 changes: 4 additions & 13 deletions tests/test_api_save_link.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
def test_api_save_link(monkeypatch):
def test_api_save_link(mock_settings):
from edutap.wallet_google.settings import ROOT_DIR

monkeypatch.setenv(
"EDUTAP_WALLET_GOOGLE_ISSUER_ID",
"1234567890123456789",
mock_settings.issuer_id = "1234567890123456789"
mock_settings.credentials_file = (
ROOT_DIR / "tests" / "data" / "credentials_fake.json"
)
monkeypatch.setenv(
"EDUTAP_WALLET_GOOGLE_CREDENTIALS_FILE",
str(ROOT_DIR / "tests" / "data" / "credentials_fake.json"),
)
from edutap.wallet_google.session import session_manager

del session_manager._settings

from edutap.wallet_google import api

Expand All @@ -30,5 +23,3 @@ def test_api_save_link(monkeypatch):
link
== "https://pay.google.com/gp/v/save/eyJ0eXAiOiAiSldUIiwgImFsZyI6ICJSUzI1NiIsICJraWQiOiAiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.eyJpc3MiOiAiZWR1dGFwLXRlc3QtZXhhbXBsZUBzb2RpdW0tcmF5LTEyMzQ1Ni5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsICJhdWQiOiAiZ29vZ2xlIiwgInR5cCI6ICJzYXZldHRvd2FsbGV0IiwgImlhdCI6ICIiLCAicGF5bG9hZCI6IHsib2ZmZXJPYmplY3RzIjogW3siaWQiOiAidGVzdC0yLmVkdXRhcC5ldSIsICJjbGFzc0lkIjogInRlc3QtY2xhc3MtMS5lZHV0YXAuZXUiLCAic3RhdGUiOiAiU1RBVEVfVU5TUEVDSUZJRUQiLCAiaGFzTGlua2VkRGV2aWNlIjogZmFsc2UsICJkaXNhYmxlRXhwaXJhdGlvbk5vdGlmaWNhdGlvbiI6IGZhbHNlLCAibm90aWZ5UHJlZmVyZW5jZSI6ICJOT1RJRklDQVRJT05fU0VUVElOR1NfRk9SX1VQREFURVNfVU5TUEVDSUZJRUQifV0sICJnZW5lcmljT2JqZWN0cyI6IFt7ImlkIjogInRlc3QtMS5lZHV0YXAuZXUifV19LCAib3JpZ2lucyI6IFtdfQ.LEPJBlt7ic9cPWKUvpoxUWe5yvdK0_kqPlBFkHmqFBfO5eeYN-owTHCElCGhnHeE730D4U3XjQWeZXfcaEAQcdBKB8udoT2Tja7Rw_M8M18kpBrSdGDRKT_uXG_-RkG3uVB30Lu5otlJiX2VOJWg9H6NR7wD_pfUt67cLjiBeMILuIVi-h0CDUV0dObEjnOHrRhj6KeKdfqq6izwwmw4iSQxsaQrDxWZtwCZ__pV5UK54Od6-lNrsBQwz241SDYv9kJTXrImrjRZXdoht6xgwqxg-GcuqUJgcczG-TLyN_9aI4FtA2cz8PCXyKPXnd-_HTe9nohi05dfMDeVWsmP6g"
)

del session_manager._settings
8 changes: 3 additions & 5 deletions tests/test_handler_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
}


def test_callback():
def test_callback(mock_settings):
...
from edutap.wallet_google.models.handlers import CallbackData
from edutap.wallet_google.session import session_manager

settings = session_manager.settings
settings.callback_verify_signature = False
mock_settings.callback_verify_signature = False

callback_data = CallbackData(**real_callback_data)

from edutap.wallet_google.handlers.fastapi import router
Expand All @@ -31,4 +30,3 @@ def test_callback():
app.include_router(router)
client = TestClient(app)
client.post("/googlewallet/callback", json=callback_data.model_dump(mode="json"))
del session_manager._settings
7 changes: 2 additions & 5 deletions tests/test_handler_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
}


def test_handler_validate_invalid():
def test_handler_validate_invalid(mock_settings):
from edutap.wallet_google.handlers.validate import verified_signed_message
from edutap.wallet_google.session import session_manager

settings = session_manager.settings
settings.callback_verify_signature = True
mock_settings.callback_verify_signature = True

data = CallbackData.model_validate(callbackdata_for_test_failure)
with pytest.raises(GooglePayError):
verified_signed_message(data)
del session_manager._settings

0 comments on commit 3ea0af8

Please sign in to comment.