try to fix tests, again

This commit is contained in:
halcy 2022-11-18 00:06:24 +02:00
parent c35104748d
commit d19b7185d8
5 changed files with 38 additions and 31 deletions

View File

@ -2,6 +2,11 @@ A note on versioning: This librarys major version will grow with the APIs
version number. Breaking changes will be indicated by a change in the minor version number. Breaking changes will be indicated by a change in the minor
(or major) version number, and will generally be avoided. (or major) version number, and will generally be avoided.
v1.6.2
------
* Add ability to schedule statuses with automatic conversion to server timezone.
* Fix some issues with datetime conversion
v1.6.1 v1.6.1
------ ------
* BREAKING CHANGE: Change behaviour of streaming api handlers to no longer raise an exception when an unknown event is received and change the contract of the unknown event handler to explicitly state that it will not receive events once Mastodon.py updates. * BREAKING CHANGE: Change behaviour of streaming api handlers to no longer raise an exception when an unknown event is received and change the contract of the unknown event handler to explicitly state that it will not receive events once Mastodon.py updates.

View File

@ -519,7 +519,7 @@ class Mastodon:
return datetime.datetime.fromtimestamp(epoch_time) return datetime.datetime.fromtimestamp(epoch_time)
else: else:
raise MastodonAPIError("No server time in response.") raise MastodonAPIError("No server time in response.")
@staticmethod @staticmethod
def get_supported_version(): def get_supported_version():
""" """
@ -3409,8 +3409,7 @@ class Mastodon:
if v != None: if v != None:
try: try:
if isinstance(v, int): if isinstance(v, int):
json_object[k] = datetime.datetime.fromtimestamp( json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc)
v, pytz.utc)
else: else:
json_object[k] = dateutil.parser.parse(v) json_object[k] = dateutil.parser.parse(v)
except: except:

View File

@ -20,7 +20,7 @@ interactions:
uri: http://localhost:3000/api/v1/statuses uri: http://localhost:3000/api/v1/statuses
response: response:
body: body:
string: '{"id":"109361356928932952","created_at":"2022-11-17T21:51:16.968Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361356928932952","url":"http://localhost:3000/@mastodonpy_test/109361356928932952","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eToot!\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"Mastodon.py string: '{"id":"109361414886671615","created_at":"2022-11-17T22:06:01.334Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361414886671615","url":"http://localhost:3000/@mastodonpy_test/109361414886671615","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eToot!\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"Mastodon.py
test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John
Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI
walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":7,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}' walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":7,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'
@ -30,7 +30,7 @@ interactions:
Content-Security-Policy: Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-Wze0VHokLwYZzGZsh21BIg==''; style-src ''self'' http://localhost:3000 ''nonce-zdbQSwbx4iw16vSozkEaBw=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -40,7 +40,7 @@ interactions:
Content-Type: Content-Type:
- application/json; charset=utf-8 - application/json; charset=utf-8
ETag: ETag:
- W/"e61d0e228d8657f6ccd5c18304a4f1c7" - W/"df3c2de04c21d605b95386d3e8dfd158"
Referrer-Policy: Referrer-Policy:
- strict-origin-when-cross-origin - strict-origin-when-cross-origin
Transfer-Encoding: Transfer-Encoding:
@ -58,13 +58,13 @@ interactions:
X-RateLimit-Limit: X-RateLimit-Limit:
- '300' - '300'
X-RateLimit-Remaining: X-RateLimit-Remaining:
- '299' - '295'
X-RateLimit-Reset: X-RateLimit-Reset:
- '2022-11-18T00:00:00.990213Z' - '2022-11-18T00:00:00.353667Z'
X-Request-Id: X-Request-Id:
- 75f26554-cf0a-478e-a28d-aa07fe7699c1 - e332cfa8-a612-45f2-804c-1c3277fd8b1c
X-Runtime: X-Runtime:
- '0.040252' - '0.032788'
X-XSS-Protection: X-XSS-Protection:
- 1; mode=block - 1; mode=block
status: status:
@ -84,10 +84,10 @@ interactions:
User-Agent: User-Agent:
- tests/v311 - tests/v311
method: GET method: GET
uri: http://localhost:3000/api/v1/timelines/home?max_id=109361358176256000&min_id=109361355554816000 uri: http://localhost:3000/api/v1/timelines/home?max_id=109361416175616000&min_id=109361413554176000
response: response:
body: body:
string: '[{"id":"109361356928932952","created_at":"2022-11-17T21:51:16.968Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361356928932952","url":"http://localhost:3000/@mastodonpy_test/109361356928932952","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eToot!\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"Mastodon.py string: '[{"id":"109361414886671615","created_at":"2022-11-17T22:06:01.334Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361414886671615","url":"http://localhost:3000/@mastodonpy_test/109361414886671615","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eToot!\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"Mastodon.py
test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John
Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI
walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":7,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}]' walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":7,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}]'
@ -97,7 +97,7 @@ interactions:
Content-Security-Policy: Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-/U4/IBa1u7/14h9/kkCoPA==''; style-src ''self'' http://localhost:3000 ''nonce-2KxFxB3gPWoSTIQQOcj+Yg=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -107,10 +107,10 @@ interactions:
Content-Type: Content-Type:
- application/json; charset=utf-8 - application/json; charset=utf-8
ETag: ETag:
- W/"68fd8fd0bc8b32aea5450a1f00072741" - W/"587b4daea4aea69b51dc4985d33293bc"
Link: Link:
- <http://localhost:3000/api/v1/timelines/home?max_id=109361356928932952>; rel="next", - <http://localhost:3000/api/v1/timelines/home?max_id=109361414886671615>; rel="next",
<http://localhost:3000/api/v1/timelines/home?min_id=109361356928932952>; rel="prev" <http://localhost:3000/api/v1/timelines/home?min_id=109361414886671615>; rel="prev"
Referrer-Policy: Referrer-Policy:
- strict-origin-when-cross-origin - strict-origin-when-cross-origin
Transfer-Encoding: Transfer-Encoding:
@ -126,9 +126,9 @@ interactions:
X-Permitted-Cross-Domain-Policies: X-Permitted-Cross-Domain-Policies:
- none - none
X-Request-Id: X-Request-Id:
- 5aecbb98-aa41-42ef-819a-9a7194fbb91a - cce9e9fa-1662-4415-aef7-2b42f239eec2
X-Runtime: X-Runtime:
- '0.022338' - '0.021393'
X-XSS-Protection: X-XSS-Protection:
- 1; mode=block - 1; mode=block
status: status:
@ -148,7 +148,7 @@ interactions:
User-Agent: User-Agent:
- tests/v311 - tests/v311
method: GET method: GET
uri: http://localhost:3000/api/v1/timelines/home?max_id=109361359486976000&min_id=109361358176256000 uri: http://localhost:3000/api/v1/timelines/home?max_id=109361417486336000&min_id=109361416175616000
response: response:
body: body:
string: '[]' string: '[]'
@ -158,7 +158,7 @@ interactions:
Content-Security-Policy: Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-9y78d6yOrkrcKX9mQp3WTw==''; style-src ''self'' http://localhost:3000 ''nonce-IUhdTTDwet1ZMyN0WYNkbA=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -184,9 +184,9 @@ interactions:
X-Permitted-Cross-Domain-Policies: X-Permitted-Cross-Domain-Policies:
- none - none
X-Request-Id: X-Request-Id:
- d4f8db1a-03c9-44a4-89dd-ef0159e4a00f - 436aa7ea-1e88-4c84-89dc-c9a0592210c0
X-Runtime: X-Runtime:
- '0.009579' - '0.008071'
X-XSS-Protection: X-XSS-Protection:
- 1; mode=block - 1; mode=block
status: status:
@ -208,10 +208,10 @@ interactions:
User-Agent: User-Agent:
- tests/v311 - tests/v311
method: DELETE method: DELETE
uri: http://localhost:3000/api/v1/statuses/109361356928932952 uri: http://localhost:3000/api/v1/statuses/109361414886671615
response: response:
body: body:
string: '{"id":"109361356928932952","created_at":"2022-11-17T21:51:16.968Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361356928932952","url":"http://localhost:3000/@mastodonpy_test/109361356928932952","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"text":"Toot!","filtered":[],"reblog":null,"application":{"name":"Mastodon.py string: '{"id":"109361414886671615","created_at":"2022-11-17T22:06:01.334Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109361414886671615","url":"http://localhost:3000/@mastodonpy_test/109361414886671615","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"text":"Toot!","filtered":[],"reblog":null,"application":{"name":"Mastodon.py
test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John test suite","website":null},"account":{"id":"109337440686176140","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"John
Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI Lennon","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"\u003cp\u003eI
walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":6,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}' walk funny\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","avatar_static":"http://localhost:3000/system/accounts/avatars/109/337/440/686/176/140/original/d6cd9a5a5e65da30.jpg","header":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","header_static":"http://localhost:3000/system/accounts/headers/109/337/440/686/176/140/original/2b7760a42692fbde.jpg","followers_count":0,"following_count":0,"statuses_count":6,"last_status_at":"2022-11-17","noindex":false,"emojis":[],"fields":[{"name":"bread","value":"toasty.","verified_at":null},{"name":"lasagna","value":"no!!!","verified_at":null}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'
@ -221,7 +221,7 @@ interactions:
Content-Security-Policy: Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-5wpK9zpFeDxFYga8QqVhrA==''; style-src ''self'' http://localhost:3000 ''nonce-qxtfoR4f93J/Fs22icd/Xg=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -231,7 +231,7 @@ interactions:
Content-Type: Content-Type:
- application/json; charset=utf-8 - application/json; charset=utf-8
ETag: ETag:
- W/"6cdc52fd88e914cc490d0db147b2cccd" - W/"1a6201cb0015e79169fd5e55d46489a9"
Referrer-Policy: Referrer-Policy:
- strict-origin-when-cross-origin - strict-origin-when-cross-origin
Transfer-Encoding: Transfer-Encoding:
@ -247,9 +247,9 @@ interactions:
X-Permitted-Cross-Domain-Policies: X-Permitted-Cross-Domain-Policies:
- none - none
X-Request-Id: X-Request-Id:
- d0c1d221-b16a-45c3-8ba1-789444b14b96 - 2cf29880-e9f0-4b0f-916b-295ba354a464
X-Runtime: X-Runtime:
- '0.026318' - '0.022470'
X-XSS-Protection: X-XSS-Protection:
- 1; mode=block - 1; mode=block
status: status:

View File

@ -85,10 +85,13 @@ def test_min_max_id_datetimes(api, status):
the_past = data_dict["the_past"] the_past = data_dict["the_past"]
the_future = data_dict["the_future"] the_future = data_dict["the_future"]
the_far_future = data_dict["the_far_future"] the_far_future = data_dict["the_far_future"]
print("restoring from dict\n", the_past, the_future, the_far_future)
else: else:
the_past = datetime.datetime.now() - datetime.timedelta(seconds=20) epoch_time = datetime.datetime.now().timestamp()
the_future = datetime.datetime.now() + datetime.timedelta(seconds=20) now = datetime.datetime.fromtimestamp(epoch_time)
the_far_future = datetime.datetime.now() + datetime.timedelta(seconds=40) the_past = now - datetime.timedelta(seconds=20)
the_future = now + datetime.timedelta(seconds=20)
the_far_future = now + datetime.timedelta(seconds=40)
pickle.dump({ pickle.dump({
"the_past": the_past, "the_past": the_past,
"the_future": the_future, "the_future": the_future,