diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-18 00:29:26 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-18 00:29:26 +0200 |
commit | 801cc36720fd01a4888938502be28dbd29691644 (patch) | |
tree | 6165371bc98a7d9b97fe7ff5be58d787455b3a9a /tests/test_instance.py | |
parent | c122f1531f03b16316fd8532cffd92f65705d56b (diff) | |
download | mastodon.py-801cc36720fd01a4888938502be28dbd29691644.tar.gz |
Improve server time test
Diffstat (limited to 'tests/test_instance.py')
-rw-r--r-- | tests/test_instance.py | 13 |
1 files changed, 13 insertions, 0 deletions
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 | |||
2 | 2 | ||
3 | from mastodon.Mastodon import MastodonVersionError | 3 | from mastodon.Mastodon import MastodonVersionError |
4 | import datetime | 4 | import datetime |
5 | import os | ||
6 | import pickle | ||
5 | 7 | ||
6 | @pytest.mark.vcr() | 8 | @pytest.mark.vcr() |
7 | def test_instance(api): | 9 | def test_instance(api): |
@@ -40,7 +42,18 @@ def test_health(api): | |||
40 | 42 | ||
41 | @pytest.mark.vcr() | 43 | @pytest.mark.vcr() |
42 | def test_server_time(api): | 44 | def test_server_time(api): |
45 | # present date... | ||
46 | present_time = api.get_approx_server_time() | ||
47 | # hahahahaha | ||
48 | |||
49 | if os.path.exists("tests/cassettes/test_server_time_datetimeobjects.pkl"): | ||
50 | present_time_real = datetime.datetime.fromtimestamp(pickle.load(open("tests/cassettes/test_server_time_datetimeobjects.pkl", 'rb'))) | ||
51 | else: | ||
52 | present_time_real = datetime.datetime.now() | ||
53 | pickle.dump(present_time_real.timestamp(), open("tests/cassettes/test_server_time_datetimeobjects.pkl", 'wb')) | ||
54 | |||
43 | assert isinstance(api.get_approx_server_time(), datetime.datetime) | 55 | assert isinstance(api.get_approx_server_time(), datetime.datetime) |
56 | assert abs((api.get_approx_server_time() - present_time_real).total_seconds()) < 5 | ||
44 | 57 | ||
45 | @pytest.mark.vcr() | 58 | @pytest.mark.vcr() |
46 | def test_nodeinfo(api): | 59 | def test_nodeinfo(api): |