From 588bd4c193baed84d52028e0225f805849aabf79 Mon Sep 17 00:00:00 2001 From: Daniil Mashkin Date: Wed, 22 Nov 2023 20:32:14 +0000 Subject: [PATCH] #503 unittests fixed --- app/analytics/analytics_logging.py | 5 +---- app/session/tests/test_session_helpers.py | 4 +++- app/session/tests/test_session_routes.py | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/analytics/analytics_logging.py b/app/analytics/analytics_logging.py index 3f4c43df..03588dce 100644 --- a/app/analytics/analytics_logging.py +++ b/app/analytics/analytics_logging.py @@ -20,11 +20,8 @@ def log_user_a_event( event_to_add.action = action event_to_add.label = label event_to_add.value = event_value - event_to_add.event_timestamp = datetime.strptime( - str(event_timestamp), "%Y-%m-%d %H:%M:%S" - ) + event_to_add.event_timestamp = event_timestamp event_to_add.page_url = page_url - # event_to_add.event_timestamp = datetime.now(timezone.utc) db.session.add(event_to_add) db.session.commit() except: diff --git a/app/session/tests/test_session_helpers.py b/app/session/tests/test_session_helpers.py index 26cec18c..3d399b97 100644 --- a/app/session/tests/test_session_helpers.py +++ b/app/session/tests/test_session_helpers.py @@ -34,7 +34,9 @@ def test_store_session_creation( assert Sessions.query.count() == 1, "Single session should be created" created_session = Sessions.query.first() assert created_session.session_uuid == session_uuid - assert created_session.session_created_timestamp == session_created_timestamp + db_time = created_session.session_created_timestamp.isoformat(" ", "seconds") + expected_time = session_created_timestamp.isoformat(" ", "seconds") + assert db_time == expected_time assert created_session.user_uuid == user_uuid assert created_session.ip_address == ip_address diff --git a/app/session/tests/test_session_routes.py b/app/session/tests/test_session_routes.py index 49a949a7..8d044f28 100644 --- a/app/session/tests/test_session_routes.py +++ b/app/session/tests/test_session_routes.py @@ -42,7 +42,7 @@ def test_post_session_creates_unique_uuids(client): assert ( session.session_uuid == response_uuid ), "The endpoint should return same UUID as stored in DB" - assert ( - session.session_created_timestamp == faked_now - ), "The session object has been created now" + db_time = session.session_created_timestamp.isoformat(" ", "seconds") + expected_time = faked_now.isoformat(" ", "seconds") + assert db_time == expected_time, "The session object has been created now" assert session.user_uuid == user.user_uuid, "Mocked user linked"