Skip to content

Commit

Permalink
test and fix save_link
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 12, 2024
1 parent 088d6a1 commit 6c1a967
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/edutap/wallet_google/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def save_link(
for model in models:
if isinstance(model, Reference):
if model.model_name is not None:
name = model.model_name
name = lookup_metadata_by_name(model.model_name)["plural"]
elif model.model_type is not None:
name = lookup_metadata_by_model_type(model.model_type)["plural"]
else:
Expand All @@ -380,6 +380,7 @@ def save_link(
jwt_string = jwt.encode(
signer,
claims.model_dump(
mode="json",
exclude_unset=False,
exclude_defaults=False,
exclude_none=True,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_api_save_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def test_api_save_link():
from edutap.wallet_google.api import save_link
from edutap.wallet_google.models.datatypes.jwt import Reference
from edutap.wallet_google.models.passes.retail import OfferClass
from edutap.wallet_google.models.passes.retail import OfferObject

link = save_link(
[
Reference(id="test-1.edutap.eu", model_name="GenericObject"),
OfferObject(id="test-2.edutap.eu", classId="test-class-1.edutap.eu"),
]
)
assert link == "https://walletobjects.googleapis.com/walletobjects/v1/jwt/eyJ0eXAiOiAiSldUIiwgImFsZyI6ICJSUzI1NiIsICJraWQiOiAiZThjMTFjZDI0ZmVjYTE1ZjViMzNmMjhiZjNiOWQ0MmUyZjE4ZTM2MSJ9.eyJpc3MiOiAiZWR1dGFwLXdhbGxldC1hcGlAZWR1dGFwLTQwMTgxMS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsICJhdWQiOiAiZ29vZ2xlIiwgInR5cCI6ICJzYXZldHRvd2FsbGV0IiwgImlhdCI6ICIiLCAicGF5bG9hZCI6IHsib2ZmZXJPYmplY3RzIjogW3siaWQiOiAidGVzdC0yLmVkdXRhcC5ldSIsICJjbGFzc0lkIjogInR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