-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(task-view): do not use the
timezone.utc
timezone to preserve a …
…naive datetime
- Loading branch information
1 parent
0537e58
commit a3f0f5e
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import datetime | ||
|
||
from sqlalchemy.orm import Session # type: ignore | ||
|
||
from antarest.core.tasks.model import TaskJob | ||
|
||
|
||
def test_database_date_utc(db_session: Session) -> None: | ||
now = datetime.datetime.utcnow() | ||
later = now + datetime.timedelta(seconds=1) | ||
|
||
with db_session: | ||
task_job = TaskJob(name="foo") | ||
db_session.add(task_job) | ||
db_session.commit() | ||
|
||
with db_session: | ||
task_job = db_session.query(TaskJob).filter(TaskJob.name == "foo").one() | ||
assert now <= task_job.creation_date <= later | ||
assert task_job.completion_date is None | ||
|
||
with db_session: | ||
task_job = db_session.query(TaskJob).filter(TaskJob.name == "foo").one() | ||
task_job.completion_date = datetime.datetime.utcnow() | ||
db_session.commit() | ||
|
||
with db_session: | ||
task_job = db_session.query(TaskJob).filter(TaskJob.name == "foo").one() | ||
assert now <= task_job.creation_date <= task_job.completion_date <= later |