Skip to content

Commit

Permalink
Mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiDiwanTT committed Jul 28, 2023
1 parent d735181 commit 4b0cfcd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/model/time_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class IdentifierPlaytimeEntry(Base):
ForeignKey("identifiers.id", onupdate="CASCADE", ondelete="CASCADE"),
nullable=False,
)
timestamp: Mapped[DateTime] = Column(DateTime(timezone=True), nullable=False)
timestamp: Mapped[datetime.datetime] = Column(
DateTime(timezone=True), nullable=False
)
total_seconds_played = Column(
Integer,
CheckConstraint(
Expand Down Expand Up @@ -65,7 +67,7 @@ class IdentifierPlaytime(Base):
identifier_str = Column(String, nullable=False)

# This should be a per-minute datetime
timestamp: Mapped[DateTime] = Column(
timestamp: Mapped[datetime.datetime] = Column(
DateTime(timezone=True),
CheckConstraint(
"extract(second from timestamp)::integer = 0",
Expand Down
10 changes: 6 additions & 4 deletions tests/api/test_controller_playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_track_playtime(self, circulation_fixture: CirculationControllerFixture)
with circulation_fixture.request_context_with_library(
"/", method="POST", json=data
):
flask.request.patron = patron
flask.request.patron = patron # type: ignore
response = circulation_fixture.manager.playtime_entries.track_playtimes(
identifier.type, identifier.identifier
)
Expand All @@ -50,12 +50,14 @@ def test_track_playtime(self, circulation_fixture: CirculationControllerFixture)
entry = get_one(
db.session, IdentifierPlaytimeEntry, tracking_id="tracking-id-0"
)
assert entry is not None
assert entry.total_seconds_played == 12
assert entry.timestamp.isoformat() == "2000-01-01T12:00:00+00:00"

entry = get_one(
db.session, IdentifierPlaytimeEntry, tracking_id="tracking-id-1"
)
assert entry is not None
assert entry.total_seconds_played == 17
assert entry.timestamp.isoformat() == "2000-01-01T12:01:00+00:00"

Expand All @@ -69,7 +71,7 @@ def test_track_playtime_duplicate_id_ok(
db.session.add(
IdentifierPlaytimeEntry(
tracking_id="tracking-id-0",
timestamp="2000-01-01T12:00Z",
timestamp="2000-01-01T12:00Z", # type: ignore
total_seconds_played=12,
identifier_id=identifier.id,
)
Expand All @@ -92,7 +94,7 @@ def test_track_playtime_duplicate_id_ok(
with circulation_fixture.request_context_with_library(
"/", method="POST", json=data
):
flask.request.patron = patron
flask.request.patron = patron # type: ignore
response = circulation_fixture.manager.playtime_entries.track_playtimes(
identifier.type, identifier.identifier
)
Expand Down Expand Up @@ -128,7 +130,7 @@ def test_track_playtime_failure(
with circulation_fixture.request_context_with_library(
"/", method="POST", json=data
):
flask.request.patron = patron
flask.request.patron = patron # type: ignore
with patch("api.controller.create") as mock_create:
mock_create.side_effect = IntegrityError(
"STATEMENT", {}, Exception("Fake Exception")
Expand Down

0 comments on commit 4b0cfcd

Please sign in to comment.