-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for datetime serialization.
- Loading branch information
1 parent
d0afe21
commit 45c58ec
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from unittest import TestCase | ||
from datetime import datetime, timezone | ||
from eduvpn.storage import serialize_datetime, deserialize_datetime | ||
|
||
|
||
utc = timezone.utc | ||
|
||
|
||
class DateTimeSerializationTests(TestCase): | ||
def test_serialize_datetime(self): | ||
self.assertEqual( | ||
serialize_datetime(datetime(2022, 1, 3, 13, 46, 29, 0, utc)), | ||
'2022-01-03T13:46:29+00:00', | ||
) | ||
|
||
def test_deserialize_datetime(self): | ||
self.assertEqual( | ||
deserialize_datetime('2022-01-03T13:46:29'), | ||
datetime(2022, 1, 3, 13, 46, 29, 0, utc), | ||
) | ||
self.assertEqual( | ||
deserialize_datetime('2022-01-03T13:46:29.123456'), | ||
datetime(2022, 1, 3, 13, 46, 29, 123456, utc), | ||
) | ||
|
||
self.assertEqual( | ||
deserialize_datetime('2022-01-03T13:46:29+00:00'), | ||
datetime(2022, 1, 3, 13, 46, 29, 0, utc), | ||
) | ||
self.assertEqual( | ||
deserialize_datetime('2022-01-03T13:46:29-00:00'), | ||
datetime(2022, 1, 3, 13, 46, 29, 0, utc), | ||
) | ||
|
||
def test_serialize_roundtrip(self): | ||
dt = datetime.now(timezone.utc) | ||
self.assertEqual( | ||
deserialize_datetime(serialize_datetime(dt)), | ||
dt, | ||
) |