aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-18 00:29:26 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-18 00:29:26 +0200
commit801cc36720fd01a4888938502be28dbd29691644 (patch)
tree6165371bc98a7d9b97fe7ff5be58d787455b3a9a
parentc122f1531f03b16316fd8532cffd92f65705d56b (diff)
downloadmastodon.py-801cc36720fd01a4888938502be28dbd29691644.tar.gz
Improve server time test
-rw-r--r--tests/cassettes/test_server_time.yaml138
-rw-r--r--tests/cassettes/test_server_time_datetimeobjects.pklbin0 -> 21 bytes
-rw-r--r--tests/test_instance.py13
3 files changed, 145 insertions, 6 deletions
diff --git a/tests/cassettes/test_server_time.yaml b/tests/cassettes/test_server_time.yaml
index a94b3aa..0fc41dd 100644
--- a/tests/cassettes/test_server_time.yaml
+++ b/tests/cassettes/test_server_time.yaml
@@ -23,7 +23,7 @@ interactions:
23 Content-Security-Policy: 23 Content-Security-Policy:
24 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src 24 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
25 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; 25 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
26 style-src ''self'' http://localhost:3000 ''nonce-2+ENJYUdR8BJrDBHHtp0Iw==''; 26 style-src ''self'' http://localhost:3000 ''nonce-nXW9HiLDQqbVti2KZWM53g=='';
27 media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' 27 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
28 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' 28 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
29 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 29 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@@ -33,13 +33,13 @@ interactions:
33 Content-Type: 33 Content-Type:
34 - text/html; charset=utf-8 34 - text/html; charset=utf-8
35 Date: 35 Date:
36 - Thu, 17 Nov 2022 20:42:32 GMT 36 - Thu, 17 Nov 2022 22:29:05 GMT
37 ETag: 37 ETag:
38 - W/"9bb3b62cb5fb0388ee3b972a95ee0633" 38 - W/"f8be64695d9085d89a46283e6757ef67"
39 Referrer-Policy: 39 Referrer-Policy:
40 - origin 40 - origin
41 Set-Cookie: 41 Set-Cookie:
42 - _mastodon_session=S%2F25BrjlEMmL38vg%2FCMcsvHcd8%2BW45HbUkMBwTiqvTgNnzQ%2FhKVYvwORXtqZ5IgNVXl7gMcJ7SxG9y1ks1LN%2Bw3rvgb%2FxECYIlBWY7C3m%2B0aWsWG%2F8iNJsZfHvXlEY3xQxDzenmA2Mw35wRyPiT%2FSUJvwM9I5RtY1iUDsaCPzUbhGFcw3aoGUTdeag37%2FfGsJuG%2F9JsR0jj%2FCgWAlokV8%2Freu8XPUBFFDmjV9SdyFfzsIvP8%2Bd7cAebpCpaqp2DPngNSm8k6xgqXCuMCqpNc09slWQHzfDVqtWPTCMc95SmGpO0DOethwA44F8WbsfX1x5HGml8%3D--x1Ipi2xI5V5ct712--m3eM1Vf8f4oi87fjm0LEvw%3D%3D; 42 - _mastodon_session=9%2Bur1I%2Fdtu02oDpNYK%2FtUWLgOanmWgJYVADb34wLg9y25c7xDikPRFcBo71ZqkBXcr0aeHHGiRIPWrH9x8ly6pIsQW90xYNUylhfPndW7vbZVvJqzaVogpSg1oWJmNLLNPDSSWR%2FWJQ9TRCQjSdZM7YWJyAuS6ybSXsI%2BMt9HQjC3W%2BZ7iVYEQFMPbCZN1s4auBla%2Bh%2BNCxRkBBOzNUO03V%2FJCyiHFwpAoUlElpnOeb1F1Fd2sDi%2FzDoOQfdwDX3pdFMs66tZMxOG3NqwkBRoCjmQ3ZHqkfUZ%2BiUtGKFM3RkxFgf6r7Vs4bPE7tVN9n1jB%2Bix3s%3D--IoU4Z629%2BzDZIN%2B7--ps2kda%2BvTZvcFmNUEmRJPA%3D%3D;
43 path=/; HttpOnly; SameSite=Lax 43 path=/; HttpOnly; SameSite=Lax
44 Vary: 44 Vary:
45 - Accept 45 - Accept
@@ -52,9 +52,135 @@ interactions:
52 X-Permitted-Cross-Domain-Policies: 52 X-Permitted-Cross-Domain-Policies:
53 - none 53 - none
54 X-Request-Id: 54 X-Request-Id:
55 - 9d6b0c84-dff7-481a-a975-c669b8469976 55 - 9e2e0a4d-5080-4b95-96cb-88de77e0fed7
56 X-Runtime: 56 X-Runtime:
57 - '0.691929' 57 - '0.028315'
58 X-XSS-Protection:
59 - 1; mode=block
60 status:
61 code: 200
62 message: OK
63- request:
64 body: null
65 headers:
66 Accept:
67 - '*/*'
68 Accept-Encoding:
69 - gzip, deflate
70 Authorization:
71 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
72 Connection:
73 - keep-alive
74 Cookie:
75 - _mastodon_session=9%2Bur1I%2Fdtu02oDpNYK%2FtUWLgOanmWgJYVADb34wLg9y25c7xDikPRFcBo71ZqkBXcr0aeHHGiRIPWrH9x8ly6pIsQW90xYNUylhfPndW7vbZVvJqzaVogpSg1oWJmNLLNPDSSWR%2FWJQ9TRCQjSdZM7YWJyAuS6ybSXsI%2BMt9HQjC3W%2BZ7iVYEQFMPbCZN1s4auBla%2Bh%2BNCxRkBBOzNUO03V%2FJCyiHFwpAoUlElpnOeb1F1Fd2sDi%2FzDoOQfdwDX3pdFMs66tZMxOG3NqwkBRoCjmQ3ZHqkfUZ%2BiUtGKFM3RkxFgf6r7Vs4bPE7tVN9n1jB%2Bix3s%3D--IoU4Z629%2BzDZIN%2B7--ps2kda%2BvTZvcFmNUEmRJPA%3D%3D
76 User-Agent:
77 - tests/v311
78 method: HEAD
79 uri: http://localhost:3000/
80 response:
81 body:
82 string: ''
83 headers:
84 Cache-Control:
85 - max-age=0, public
86 Content-Security-Policy:
87 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
88 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
89 style-src ''self'' http://localhost:3000 ''nonce-XiBPioKluGBjIKmMpOnxwg=='';
90 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
91 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
92 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
93 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
94 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
95 worker-src ''self'' blob: http://localhost:3000'
96 Content-Type:
97 - text/html; charset=utf-8
98 Date:
99 - Thu, 17 Nov 2022 22:29:06 GMT
100 ETag:
101 - W/"3b5c660342924ee22adaead4e61b8c61"
102 Referrer-Policy:
103 - origin
104 Set-Cookie:
105 - _mastodon_session=uh3TnZQHpCFWGKegBrpeXz%2F1Vx3brDN4EaOE52yOjkO8LgjV4Zdc%2Fhqyiha6m4g55D%2BBvhpnyTaKtIPze6h7MporjUOzGIp6kz%2Bn%2FYsMoJnbBNaTe0gEcwvSbvD%2FYUG%2F9OWcuNZ6T7wfwoGavkWFhSOGXlfX6WGfAjEwcoY60EqVhjuvNkqASVzND4%2FZgIXkCyKcLWFlgqiKSyTDA5Dr2IsMC1DErEnXxTyZJnvKTEzmAZdmu08QuPlJjFR%2FL2bhP4R%2FsHcDEB%2FCe0PgCLsJIv%2BUMl6Pjyl9Q5xYTyhG6n%2Fwp5qaZo1Xc6s%2BjgRAuEJ%2F7XcYpKU%3D--E6KHuGdfZvSsPXBg--%2F713IcELMZqhavNHEoHyAw%3D%3D;
106 path=/; HttpOnly; SameSite=Lax
107 Vary:
108 - Accept
109 X-Content-Type-Options:
110 - nosniff
111 X-Download-Options:
112 - noopen
113 X-Frame-Options:
114 - SAMEORIGIN
115 X-Permitted-Cross-Domain-Policies:
116 - none
117 X-Request-Id:
118 - 5a29618e-2aec-445a-b461-cd1e4709a98a
119 X-Runtime:
120 - '0.022491'
121 X-XSS-Protection:
122 - 1; mode=block
123 status:
124 code: 200
125 message: OK
126- request:
127 body: null
128 headers:
129 Accept:
130 - '*/*'
131 Accept-Encoding:
132 - gzip, deflate
133 Authorization:
134 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
135 Connection:
136 - keep-alive
137 Cookie:
138 - _mastodon_session=uh3TnZQHpCFWGKegBrpeXz%2F1Vx3brDN4EaOE52yOjkO8LgjV4Zdc%2Fhqyiha6m4g55D%2BBvhpnyTaKtIPze6h7MporjUOzGIp6kz%2Bn%2FYsMoJnbBNaTe0gEcwvSbvD%2FYUG%2F9OWcuNZ6T7wfwoGavkWFhSOGXlfX6WGfAjEwcoY60EqVhjuvNkqASVzND4%2FZgIXkCyKcLWFlgqiKSyTDA5Dr2IsMC1DErEnXxTyZJnvKTEzmAZdmu08QuPlJjFR%2FL2bhP4R%2FsHcDEB%2FCe0PgCLsJIv%2BUMl6Pjyl9Q5xYTyhG6n%2Fwp5qaZo1Xc6s%2BjgRAuEJ%2F7XcYpKU%3D--E6KHuGdfZvSsPXBg--%2F713IcELMZqhavNHEoHyAw%3D%3D
139 User-Agent:
140 - tests/v311
141 method: HEAD
142 uri: http://localhost:3000/
143 response:
144 body:
145 string: ''
146 headers:
147 Cache-Control:
148 - max-age=0, public
149 Content-Security-Policy:
150 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
151 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
152 style-src ''self'' http://localhost:3000 ''nonce-3V+Y3NQPR7ogARWAKoOmPA=='';
153 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
154 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
155 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
156 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
157 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
158 worker-src ''self'' blob: http://localhost:3000'
159 Content-Type:
160 - text/html; charset=utf-8
161 Date:
162 - Thu, 17 Nov 2022 22:29:06 GMT
163 ETag:
164 - W/"818a87013531b8f4e9b2052440c21631"
165 Referrer-Policy:
166 - origin
167 Set-Cookie:
168 - _mastodon_session=HzqGfcAAFBlwhl021YjmxBlQrhCMXb93XugXjXbslcjqIHvlI%2B%2BvLHcnjCcKgxeYqu02FNmgARy7eb8m1GrATgUzDzs1HglhEYTeN%2BpKy0q4QwVCB2X1LCRLa84%2FXOG4YE8YF6tOFKGt1zdOcx3Auh20pZ8JoM8eCUP9Fr8%2FfhXDG1wfd5eFDsWJpvntWdqonQfZe%2FKbKxEHysA1HJz3Ke98laJY8cz%2FCq2T%2FjImsL0h4MqxuepbBizGfHgDyyr2b4psJUoru8Yqq93rZhH07gMh0QPBaVCnkYnhhoANksdbG24cOknP5K0RHBjbh4%2Bjj6IsyWQ%3D--fZgRaWLdzjI%2Fu5hU--BU9evoOFE9S%2BdFhVaCaAfQ%3D%3D;
169 path=/; HttpOnly; SameSite=Lax
170 Vary:
171 - Accept
172 X-Content-Type-Options:
173 - nosniff
174 X-Download-Options:
175 - noopen
176 X-Frame-Options:
177 - SAMEORIGIN
178 X-Permitted-Cross-Domain-Policies:
179 - none
180 X-Request-Id:
181 - 5fdd2421-a8d4-48c5-8e14-6d045ddf6239
182 X-Runtime:
183 - '0.030469'
58 X-XSS-Protection: 184 X-XSS-Protection:
59 - 1; mode=block 185 - 1; mode=block
60 status: 186 status:
diff --git a/tests/cassettes/test_server_time_datetimeobjects.pkl b/tests/cassettes/test_server_time_datetimeobjects.pkl
new file mode 100644
index 0000000..45770d4
--- /dev/null
+++ b/tests/cassettes/test_server_time_datetimeobjects.pkl
Binary files differ
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
3from mastodon.Mastodon import MastodonVersionError 3from mastodon.Mastodon import MastodonVersionError
4import datetime 4import datetime
5import os
6import pickle
5 7
6@pytest.mark.vcr() 8@pytest.mark.vcr()
7def test_instance(api): 9def test_instance(api):
@@ -40,7 +42,18 @@ def test_health(api):
40 42
41@pytest.mark.vcr() 43@pytest.mark.vcr()
42def test_server_time(api): 44def 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()
46def test_nodeinfo(api): 59def test_nodeinfo(api):
Powered by cgit v1.2.3 (git 2.41.0)