aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-04-28 20:38:49 +0200
committerLorenz Diener <[email protected]>2019-04-28 20:38:49 +0200
commit20a640eb7ee4628979252743c567d31cab4dbb91 (patch)
treef316f3998ccab9e36d7882899433cd95ee312ffb
parentee4549acd0a6fa75bfea1a3e0498ef2029af5c9f (diff)
downloadmastodon.py-20a640eb7ee4628979252743c567d31cab4dbb91.tar.gz
Fix the isoformat formatter
-rw-r--r--mastodon/Mastodon.py19
-rw-r--r--tests/cassettes/test_scheduled_status.yaml52
2 files changed, 43 insertions, 28 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index c037ceb..679aac8 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1381,7 +1381,7 @@ class Mastodon:
1381 in_reply_to_id = self.__unpack_id(in_reply_to_id) 1381 in_reply_to_id = self.__unpack_id(in_reply_to_id)
1382 1382
1383 if scheduled_at != None: 1383 if scheduled_at != None:
1384 scheduled_at = scheduled_at.astimezone(pytz.utc).isoformat() 1384 scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
1385 1385
1386 params_initial = locals() 1386 params_initial = locals()
1387 1387
@@ -1585,7 +1585,7 @@ class Mastodon:
1585 1585
1586 Returns a `scheduled toot dict`_ 1586 Returns a `scheduled toot dict`_
1587 """ 1587 """
1588 scheduled_at = scheduled_at.astimezone(pytz.utc).isoformat() 1588 scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
1589 id = self.__unpack_id(id) 1589 id = self.__unpack_id(id)
1590 params = self.__generate_params(locals(), ['id']) 1590 params = self.__generate_params(locals(), ['id'])
1591 url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) 1591 url = '/api/v1/scheduled_statuses/{0}'.format(str(id))
@@ -2406,12 +2406,27 @@ class Mastodon:
2406 2406
2407 @staticmethod 2407 @staticmethod
2408 def __json_hooks(json_object): 2408 def __json_hooks(json_object):
2409 """
2410 All the json hooks. Used in request parsing.
2411 """
2409 json_object = Mastodon.__json_strnum_to_bignum(json_object) 2412 json_object = Mastodon.__json_strnum_to_bignum(json_object)
2410 json_object = Mastodon.__json_date_parse(json_object) 2413 json_object = Mastodon.__json_date_parse(json_object)
2411 json_object = Mastodon.__json_truefalse_parse(json_object) 2414 json_object = Mastodon.__json_truefalse_parse(json_object)
2412 json_object = Mastodon.__json_allow_dict_attrs(json_object) 2415 json_object = Mastodon.__json_allow_dict_attrs(json_object)
2413 return json_object 2416 return json_object
2414 2417
2418 @staticmethod
2419 def __consistent_isoformat_utc(datetime_val):
2420 """
2421 Function that does what isoformat does but it actually does the same
2422 every time instead of randomly doing different things on some systems
2423 and also it represents that time as the equivalent UTC time.
2424 """
2425 isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
2426 if isotime[-2] != ":":
2427 isotime = isotime[:-2] + ":" + isotime[-2:]
2428 return isotime
2429
2415 def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, do_ratelimiting=True): 2430 def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, do_ratelimiting=True):
2416 """ 2431 """
2417 Internal API request helper. 2432 Internal API request helper.
diff --git a/tests/cassettes/test_scheduled_status.yaml b/tests/cassettes/test_scheduled_status.yaml
index 04fec5a..c0843ea 100644
--- a/tests/cassettes/test_scheduled_status.yaml
+++ b/tests/cassettes/test_scheduled_status.yaml
@@ -12,12 +12,12 @@ interactions:
12 method: POST 12 method: POST
13 uri: http://localhost:3000/api/v1/statuses 13 uri: http://localhost:3000/api/v1/statuses
14 response: 14 response:
15 body: {string: '{"id":"18","scheduled_at":"4000-01-01T11:33:14.000Z","params":{"text":"please 15 body: {string: '{"id":"19","scheduled_at":"4000-01-01T11:33:14.000Z","params":{"text":"please
16 ensure adequate headroom","media_ids":null,"sensitive":null,"spoiler_text":null,"visibility":null,"scheduled_at":null,"poll":null,"idempotency":null,"in_reply_to_id":null,"application_id":1234567890123456},"media_attachments":[]}'} 16 ensure adequate headroom","media_ids":null,"sensitive":null,"spoiler_text":null,"visibility":null,"scheduled_at":null,"poll":null,"idempotency":null,"in_reply_to_id":null,"application_id":1234567890123456},"media_attachments":[]}'}
17 headers: 17 headers:
18 Cache-Control: ['max-age=0, private, must-revalidate'] 18 Cache-Control: ['max-age=0, private, must-revalidate']
19 Content-Type: [application/json; charset=utf-8] 19 Content-Type: [application/json; charset=utf-8]
20 ETag: [W/"55a21b75b918b4af7fdb4b8d90f7d6e7"] 20 ETag: [W/"869b974553c558251472c898ce2b4b30"]
21 Referrer-Policy: [strict-origin-when-cross-origin] 21 Referrer-Policy: [strict-origin-when-cross-origin]
22 Transfer-Encoding: [chunked] 22 Transfer-Encoding: [chunked]
23 Vary: ['Accept-Encoding, Origin'] 23 Vary: ['Accept-Encoding, Origin']
@@ -25,8 +25,8 @@ interactions:
25 X-Download-Options: [noopen] 25 X-Download-Options: [noopen]
26 X-Frame-Options: [SAMEORIGIN] 26 X-Frame-Options: [SAMEORIGIN]
27 X-Permitted-Cross-Domain-Policies: [none] 27 X-Permitted-Cross-Domain-Policies: [none]
28 X-Request-Id: [0a550963-ff3c-46a1-b8b5-5e40dd64c746] 28 X-Request-Id: [268bf716-1ca5-4e0a-a1bf-9c06b23b0c6f]
29 X-Runtime: ['0.042131'] 29 X-Runtime: ['0.064617']
30 X-XSS-Protection: [1; mode=block] 30 X-XSS-Protection: [1; mode=block]
31 content-length: ['307'] 31 content-length: ['307']
32 status: {code: 200, message: OK} 32 status: {code: 200, message: OK}
@@ -41,14 +41,14 @@ interactions:
41 Content-Type: [application/x-www-form-urlencoded] 41 Content-Type: [application/x-www-form-urlencoded]
42 User-Agent: [python-requests/2.18.4] 42 User-Agent: [python-requests/2.18.4]
43 method: PUT 43 method: PUT
44 uri: http://localhost:3000/api/v1/scheduled_statuses/18 44 uri: http://localhost:3000/api/v1/scheduled_statuses/19
45 response: 45 response:
46 body: {string: '{"id":"18","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please 46 body: {string: '{"id":"19","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please
47 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}'} 47 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}'}
48 headers: 48 headers:
49 Cache-Control: ['max-age=0, private, must-revalidate'] 49 Cache-Control: ['max-age=0, private, must-revalidate']
50 Content-Type: [application/json; charset=utf-8] 50 Content-Type: [application/json; charset=utf-8]
51 ETag: [W/"4211b1c063163578d72e0d9fee015aac"] 51 ETag: [W/"d0254474867b88e60e2a7d1754ab928c"]
52 Referrer-Policy: [strict-origin-when-cross-origin] 52 Referrer-Policy: [strict-origin-when-cross-origin]
53 Transfer-Encoding: [chunked] 53 Transfer-Encoding: [chunked]
54 Vary: ['Accept-Encoding, Origin'] 54 Vary: ['Accept-Encoding, Origin']
@@ -56,8 +56,8 @@ interactions:
56 X-Download-Options: [noopen] 56 X-Download-Options: [noopen]
57 X-Frame-Options: [SAMEORIGIN] 57 X-Frame-Options: [SAMEORIGIN]
58 X-Permitted-Cross-Domain-Policies: [none] 58 X-Permitted-Cross-Domain-Policies: [none]
59 X-Request-Id: [00ce2af1-000d-40fc-9765-9661b4fda8a5] 59 X-Request-Id: [dcd95b0e-7116-454a-9ba4-122de3a6913e]
60 X-Runtime: ['0.023685'] 60 X-Runtime: ['0.047892']
61 X-XSS-Protection: [1; mode=block] 61 X-XSS-Protection: [1; mode=block]
62 content-length: ['307'] 62 content-length: ['307']
63 status: {code: 200, message: OK} 63 status: {code: 200, message: OK}
@@ -72,13 +72,13 @@ interactions:
72 method: GET 72 method: GET
73 uri: http://localhost:3000/api/v1/scheduled_statuses 73 uri: http://localhost:3000/api/v1/scheduled_statuses
74 response: 74 response:
75 body: {string: '[{"id":"18","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please 75 body: {string: '[{"id":"19","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please
76 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}]'} 76 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}]'}
77 headers: 77 headers:
78 Cache-Control: ['max-age=0, private, must-revalidate'] 78 Cache-Control: ['max-age=0, private, must-revalidate']
79 Content-Type: [application/json; charset=utf-8] 79 Content-Type: [application/json; charset=utf-8]
80 ETag: [W/"214cbc9aaa46dbb18c2d5a1437d145d5"] 80 ETag: [W/"f942fa659c7f711edf601fd02eb28f2f"]
81 Link: ['<http://localhost:3000/api/v1/scheduled_statuses?min_id=18>; rel="prev"'] 81 Link: ['<http://localhost:3000/api/v1/scheduled_statuses?min_id=19>; rel="prev"']
82 Referrer-Policy: [strict-origin-when-cross-origin] 82 Referrer-Policy: [strict-origin-when-cross-origin]
83 Transfer-Encoding: [chunked] 83 Transfer-Encoding: [chunked]
84 Vary: ['Accept-Encoding, Origin'] 84 Vary: ['Accept-Encoding, Origin']
@@ -86,8 +86,8 @@ interactions:
86 X-Download-Options: [noopen] 86 X-Download-Options: [noopen]
87 X-Frame-Options: [SAMEORIGIN] 87 X-Frame-Options: [SAMEORIGIN]
88 X-Permitted-Cross-Domain-Policies: [none] 88 X-Permitted-Cross-Domain-Policies: [none]
89 X-Request-Id: [9790aeb5-05f9-4d77-87bb-05e7add83909] 89 X-Request-Id: [97962c99-e4a1-4bd2-849d-51f48544c67c]
90 X-Runtime: ['0.017555'] 90 X-Runtime: ['0.022832']
91 X-XSS-Protection: [1; mode=block] 91 X-XSS-Protection: [1; mode=block]
92 content-length: ['309'] 92 content-length: ['309']
93 status: {code: 200, message: OK} 93 status: {code: 200, message: OK}
@@ -100,14 +100,14 @@ interactions:
100 Connection: [keep-alive] 100 Connection: [keep-alive]
101 User-Agent: [python-requests/2.18.4] 101 User-Agent: [python-requests/2.18.4]
102 method: GET 102 method: GET
103 uri: http://localhost:3000/api/v1/scheduled_statuses/18 103 uri: http://localhost:3000/api/v1/scheduled_statuses/19
104 response: 104 response:
105 body: {string: '{"id":"18","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please 105 body: {string: '{"id":"19","scheduled_at":"4000-01-01T11:23:14.000Z","params":{"poll":null,"text":"please
106 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}'} 106 ensure adequate headroom","media_ids":null,"sensitive":null,"visibility":null,"idempotency":null,"scheduled_at":null,"spoiler_text":null,"application_id":1234567890123456,"in_reply_to_id":null},"media_attachments":[]}'}
107 headers: 107 headers:
108 Cache-Control: ['max-age=0, private, must-revalidate'] 108 Cache-Control: ['max-age=0, private, must-revalidate']
109 Content-Type: [application/json; charset=utf-8] 109 Content-Type: [application/json; charset=utf-8]
110 ETag: [W/"4211b1c063163578d72e0d9fee015aac"] 110 ETag: [W/"d0254474867b88e60e2a7d1754ab928c"]
111 Referrer-Policy: [strict-origin-when-cross-origin] 111 Referrer-Policy: [strict-origin-when-cross-origin]
112 Transfer-Encoding: [chunked] 112 Transfer-Encoding: [chunked]
113 Vary: ['Accept-Encoding, Origin'] 113 Vary: ['Accept-Encoding, Origin']
@@ -115,8 +115,8 @@ interactions:
115 X-Download-Options: [noopen] 115 X-Download-Options: [noopen]
116 X-Frame-Options: [SAMEORIGIN] 116 X-Frame-Options: [SAMEORIGIN]
117 X-Permitted-Cross-Domain-Policies: [none] 117 X-Permitted-Cross-Domain-Policies: [none]
118 X-Request-Id: [720a388c-96a2-4159-951b-5e24012646be] 118 X-Request-Id: [f95378c9-b0c8-4c93-bf1e-f993db396b98]
119 X-Runtime: ['0.015976'] 119 X-Runtime: ['0.030762']
120 X-XSS-Protection: [1; mode=block] 120 X-XSS-Protection: [1; mode=block]
121 content-length: ['307'] 121 content-length: ['307']
122 status: {code: 200, message: OK} 122 status: {code: 200, message: OK}
@@ -130,13 +130,13 @@ interactions:
130 Content-Length: ['0'] 130 Content-Length: ['0']
131 User-Agent: [python-requests/2.18.4] 131 User-Agent: [python-requests/2.18.4]
132 method: DELETE 132 method: DELETE
133 uri: http://localhost:3000/api/v1/scheduled_statuses/18 133 uri: http://localhost:3000/api/v1/scheduled_statuses/19
134 response: 134 response:
135 body: {string: '{}'} 135 body: {string: '{}'}
136 headers: 136 headers:
137 Cache-Control: ['max-age=0, private, must-revalidate'] 137 Cache-Control: ['max-age=0, private, must-revalidate']
138 Content-Type: [application/json; charset=utf-8] 138 Content-Type: [application/json; charset=utf-8]
139 ETag: [W/"a97c68bcd1ca704122f54447e96fcb7a"] 139 ETag: [W/"0990eb85ee6e415913216239571d30e5"]
140 Referrer-Policy: [strict-origin-when-cross-origin] 140 Referrer-Policy: [strict-origin-when-cross-origin]
141 Transfer-Encoding: [chunked] 141 Transfer-Encoding: [chunked]
142 Vary: ['Accept-Encoding, Origin'] 142 Vary: ['Accept-Encoding, Origin']
@@ -144,8 +144,8 @@ interactions:
144 X-Download-Options: [noopen] 144 X-Download-Options: [noopen]
145 X-Frame-Options: [SAMEORIGIN] 145 X-Frame-Options: [SAMEORIGIN]
146 X-Permitted-Cross-Domain-Policies: [none] 146 X-Permitted-Cross-Domain-Policies: [none]
147 X-Request-Id: [b57c0e70-97bf-4777-8272-e0d06799291d] 147 X-Request-Id: [ed7c8df2-5a65-474e-81ec-9f4ef3f50b3d]
148 X-Runtime: ['0.025188'] 148 X-Runtime: ['0.028344']
149 X-XSS-Protection: [1; mode=block] 149 X-XSS-Protection: [1; mode=block]
150 content-length: ['2'] 150 content-length: ['2']
151 status: {code: 200, message: OK} 151 status: {code: 200, message: OK}
@@ -164,7 +164,7 @@ interactions:
164 headers: 164 headers:
165 Cache-Control: ['max-age=0, private, must-revalidate'] 165 Cache-Control: ['max-age=0, private, must-revalidate']
166 Content-Type: [application/json; charset=utf-8] 166 Content-Type: [application/json; charset=utf-8]
167 ETag: [W/"a3f1c7eff68af7234bcf2a8d4233d0c1"] 167 ETag: [W/"cc6e706f1723e565ab0b83aab7be53aa"]
168 Referrer-Policy: [strict-origin-when-cross-origin] 168 Referrer-Policy: [strict-origin-when-cross-origin]
169 Transfer-Encoding: [chunked] 169 Transfer-Encoding: [chunked]
170 Vary: ['Accept-Encoding, Origin'] 170 Vary: ['Accept-Encoding, Origin']
@@ -172,8 +172,8 @@ interactions:
172 X-Download-Options: [noopen] 172 X-Download-Options: [noopen]
173 X-Frame-Options: [SAMEORIGIN] 173 X-Frame-Options: [SAMEORIGIN]
174 X-Permitted-Cross-Domain-Policies: [none] 174 X-Permitted-Cross-Domain-Policies: [none]
175 X-Request-Id: [e1152c40-5d88-410a-bd73-cb0c7dbc3f92] 175 X-Request-Id: [6d71010e-5cc0-4029-a19b-67cac6b8f5bc]
176 X-Runtime: ['0.014370'] 176 X-Runtime: ['0.017476']
177 X-XSS-Protection: [1; mode=block] 177 X-XSS-Protection: [1; mode=block]
178 content-length: ['2'] 178 content-length: ['2']
179 status: {code: 200, message: OK} 179 status: {code: 200, message: OK}
Powered by cgit v1.2.3 (git 2.41.0)