Skip to content

Commit

Permalink
Add tests for datetime serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
alvra authored and gijzelaerr committed Mar 12, 2022
1 parent d0afe21 commit 45c58ec
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_storage.py
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,
)

0 comments on commit 45c58ec

Please sign in to comment.