Skip to content

Commit

Permalink
extend Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Apr 30, 2024
1 parent 7e6a7db commit 5e36e14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
18 changes: 16 additions & 2 deletions src/edutap/wallet_google/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from .modelbase import GoogleWalletClassModel
from .modelbase import GoogleWalletObjectModel
from .modelbase import GoogleWalletObjectWithClassReferenceMixin
from .modelbase import GoogleWalletWithIdModel
from .modelcore import GoogleWalletModel
from .models.primitives import Pagination
from .models.primitives.enums import State
Expand Down Expand Up @@ -33,7 +36,7 @@ def _validate_data(
or a Pydantic model instance.
:return: data as an instance of the given model
"""
if not isinstance(data, GoogleWalletModel):
if not isinstance(data, (GoogleWalletModel, GoogleWalletWithIdModel)):
return model.model_validate(data)
if not isinstance(data, model):
raise ValueError(
Expand Down Expand Up @@ -151,7 +154,18 @@ def update(
raise_when_operation_not_allowed(name, "update")
model_metadata = lookup_metadata(name)
model = model_metadata["model"]
if not isinstance(data, GoogleWalletModel) and partial:
if (
not isinstance(
data,
(
GoogleWalletModel,
GoogleWalletWithIdModel,
GoogleWalletClassModel,
GoogleWalletObjectModel,
),
)
and partial
):
resource_id = data[model_metadata["resource_id"]]
# we can not validate partial data for patch yet
verified_json = json.dumps(data)
Expand Down
15 changes: 6 additions & 9 deletions src/edutap/wallet_google/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,26 @@ class GoogleWalletSettings(BaseSettings):
"""Settings for Google Wallet Preferences."""

model_config = SettingsConfigDict(
# env_file=".env",
# env_file_encoding="utf-8",
env_prefix="EDUTAP_WALLET_GOOGLE_",
case_sensitive=False,
# extra="ignore",
extra="allow",
extra="ignore",
# extra="allow",
)

record_api_calls_dir: Path | None = ROOT_DIR / "tests" / "data"
record_api_calls_dir: Path | None = None # ROOT_DIR / "tests" / "data"
base_url: HttpUrl = HttpUrl("https://walletobjects.googleapis.com/walletobjects/v1")
save_url: HttpUrl = HttpUrl("https://pay.google.com/gp/v/save")
scopes: list[HttpUrl] = [
HttpUrl("https://www.googleapis.com/auth/wallet_object.issuer")
]

# credentials_dir: Path = Field(alias="EDUTAP_WALLET_PATH_CREDENTIAL_DIR", default=ROOT_DIR)

# credentials_file: str = "credentials.json"
credentials_file: Path = ROOT_DIR / "credentials.json"

issuer_account_email: EmailStr | None = None
issuer_id: str | None = Field(min_length=19, max_length=20, default=None)

callback_url: HttpUrl | None = None
callback_update_url: HttpUrl | None = None


class HTTPRecorder(HTTPAdapter):
"""Record the HTTP requests and responses to a file."""
Expand Down
6 changes: 4 additions & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from edutap.wallet_google.session import GoogleWalletSettings
from pprint import pprint as print
from pprint import pprint


def test_settings():
settings = GoogleWalletSettings()
print(settings.__dict__)
print("Test Settings - Dump Settings Values:")
# print(settings.model_dump())
pprint(settings.model_dump(), indent=2, sort_dicts=True)

assert (
str(settings.base_url)
Expand Down

0 comments on commit 5e36e14

Please sign in to comment.