Skip to content

Commit

Permalink
Fix some tests, fix a pleroma specific date parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
halcy authored and halcy committed Nov 21, 2022
1 parent bf96add commit 8865d11
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 103 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ 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
(or major) version number, and will generally be avoided.

v1.7.4
------
* Clean code up a bit (thanks eumiro)
* Fix some Pleroma related issues (thanks aveao, taraletti, adbenitez)
* Add post editing (`status_update`, `status_source`, `status_history`)
* Add missing streaming events
* Add missing parameters on directory endpoint (thanks heharkon)
* This isn't somehing I changed but thank you a / triggerofsol for answering Many questions I had about specifics of what the API does that are not documented
* TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma.

v1.6.3
------
* Add server rules API (`instance_rules`)
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m

3.5.0
-----
* [ ] Add support for incoming edited posts
* [x] Add support for incoming edited posts
* [ ] Add notifications for posts deleted by moderators
* [ ] Add explore page with trending posts and links
* [ ] Add graphs and retention metrics to admin dashboard
Expand Down
12 changes: 7 additions & 5 deletions mastodon/Mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,11 @@ def __json_date_parse(json_object):
else:
json_object[k] = dateutil.parser.parse(v)
except:
raise MastodonAPIError('Encountered invalid date.')
if isinstance(v, str) and len(x.strip()) == 0:
# Pleroma bug workaround: Empty string becomes start of epoch
json_object[k] = datetime.datetime.fromtimestamp(0)
else:
raise MastodonAPIError('Encountered invalid date.')
return json_object

@staticmethod
Expand Down Expand Up @@ -3693,10 +3697,8 @@ def __api_request(self, method, endpoint, params={}, files={}, headers={}, acces
self.ratelimit_reset = int(
response_object.headers['X-RateLimit-Reset'])
else:
ratelimit_reset_datetime = dateutil.parser.parse(
response_object.headers['X-RateLimit-Reset'])
self.ratelimit_reset = self.__datetime_to_epoch(
ratelimit_reset_datetime)
ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset'])
self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime)

# Adjust server time to local clock
if 'Date' in response_object.headers:
Expand Down
10 changes: 5 additions & 5 deletions tests/cassettes/test_directory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ interactions:
uri: http://localhost:3000/api/v1/directory
response:
body:
string: '[{"id":"109383665090212021","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":false,"bot":false,"discoverable":true,"group":false,"created_at":"2022-11-21T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test_2","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":"2022-11-21","noindex":false,"emojis":[],"fields":[]}]'
string: '[{"id":"109384260135049902","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":false,"bot":false,"discoverable":true,"group":false,"created_at":"2022-11-21T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test_2","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"noindex":false,"emojis":[],"fields":[]}]'
headers:
Cache-Control:
- no-store
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-xpVs3DQUf/Qj6+scQHcj2w=='';
style-src ''self'' http://localhost:3000 ''nonce-4zQUTaGqbRq4cCv1ZKgOhw=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
Expand All @@ -33,7 +33,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"da415b35a62517444708496f746f2ca2"
- W/"4cd256c2bfbe67103f7671696dd86c2f"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
Expand All @@ -49,9 +49,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- d373f3cc-9362-450e-b7d9-06b8c0411b0d
- e421ca7a-a712-475c-9111-8e1b53b945c9
X-Runtime:
- '0.029489'
- '0.029318'
X-XSS-Protection:
- 1; mode=block
status:
Expand Down

0 comments on commit 8865d11

Please sign in to comment.