Skip to content

Commit

Permalink
Code review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jan 16, 2025
1 parent 9030d8f commit 400b8eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ repos:
rev: v3.17.0
hooks:
- id: pyupgrade
# TODO: Remove when Pydantic supports `datetime.date | None` type annotation.
# Otherwise, `pyupgrade` will rewrite from `Optional[datetime.date]`.
exclude: ^src/palace/manager/api/circulation.py
args:
- --py310-plus

Expand Down
8 changes: 3 additions & 5 deletions src/palace/manager/api/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from abc import ABC, abstractmethod
from collections.abc import Iterable, Mapping
from typing import Literal, Optional, TypeVar
from typing import Literal, TypeVar

import flask
import requests
Expand Down Expand Up @@ -564,9 +564,7 @@ class BaseCirculationApiSettings(BaseSettings):
)
}

# TODO: Using `Optional[datetime.date]` here because Pydantic does not
# currently handle the annotation of `datetime.date | None` properly.
subscription_activation_date: Optional[datetime.date] = FormField(
subscription_activation_date: datetime.date | None = FormField(
default=None,
form=ConfigurationFormItem(
label=_("Collection Subscription Activation Date"),
Expand All @@ -579,7 +577,7 @@ class BaseCirculationApiSettings(BaseSettings):
required=False,
),
)
subscription_expiration_date: Optional[datetime.date] = FormField(
subscription_expiration_date: datetime.date | None = FormField(
default=None,
form=ConfigurationFormItem(
label=_("Collection Subscription Expiration Date"),
Expand Down
22 changes: 22 additions & 0 deletions tests/manager/api/admin/test_form_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from werkzeug.datastructures import ImmutableMultiDict

from palace.manager.api.admin.form_data import ProcessFormData
Expand Down Expand Up @@ -46,6 +48,22 @@ class MockSettings(BaseSettings):
description="Another date.",
),
)
field6: datetime.date | None = FormField(
None,
form=ConfigurationFormItem(
label="Another date field with a date type",
type=ConfigurationFormItemType.DATE,
description="A python date.",
),
)
field7: datetime.date | None = FormField(
None,
form=ConfigurationFormItem(
label="Another date field with a date type",
type=ConfigurationFormItemType.DATE,
description="A python date.",
),
)


def test_get_settings():
Expand All @@ -59,6 +77,8 @@ def test_get_settings():
("field3", "value5"),
("field4", "2024-10-23"),
("field5", ""),
("field6", "2024-10-23"),
("field7", ""),
]
)
settings = ProcessFormData.get_settings(MockSettings, data)
Expand All @@ -67,3 +87,5 @@ def test_get_settings():
assert settings.field3 == "value5"
assert settings.field4 == "2024-10-23"
assert settings.field5 is None
assert settings.field6 == datetime.date(2024, 10, 23)
assert settings.field7 is None

0 comments on commit 400b8eb

Please sign in to comment.