From 801cc36720fd01a4888938502be28dbd29691644 Mon Sep 17 00:00:00 2001 From: halcy Date: Fri, 18 Nov 2022 00:29:26 +0200 Subject: Improve server time test --- tests/test_instance.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/test_instance.py') diff --git a/tests/test_instance.py b/tests/test_instance.py index 5de61f6..3b42c3e 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -2,6 +2,8 @@ import pytest from mastodon.Mastodon import MastodonVersionError import datetime +import os +import pickle @pytest.mark.vcr() def test_instance(api): @@ -40,7 +42,18 @@ def test_health(api): @pytest.mark.vcr() def test_server_time(api): + # present date... + present_time = api.get_approx_server_time() + # hahahahaha + + if os.path.exists("tests/cassettes/test_server_time_datetimeobjects.pkl"): + present_time_real = datetime.datetime.fromtimestamp(pickle.load(open("tests/cassettes/test_server_time_datetimeobjects.pkl", 'rb'))) + else: + present_time_real = datetime.datetime.now() + pickle.dump(present_time_real.timestamp(), open("tests/cassettes/test_server_time_datetimeobjects.pkl", 'wb')) + assert isinstance(api.get_approx_server_time(), datetime.datetime) + assert abs((api.get_approx_server_time() - present_time_real).total_seconds()) < 5 @pytest.mark.vcr() def test_nodeinfo(api): -- cgit v1.2.3