kopia lustrzana https://github.com/halcy/Mastodon.py
make test setup work on 4.4.3, add delete_media to status_delete
rodzic
93a96af966
commit
e9e1c2406a
|
@ -21,6 +21,7 @@ v2.1.0 (IN PROGRESS)
|
|||
* Fix `moved` accidentally being named `moved_to_account` (Thanks @unusualevent for the report)
|
||||
* Added a warning for deprecated endpoints if the "deprecation" header is present
|
||||
* Added `oauth_userinfo` endpoint.
|
||||
* Added `delete_media` parameter to `status_delete`.
|
||||
|
||||
v2.0.1
|
||||
------
|
||||
|
|
8
TODO.md
8
TODO.md
|
@ -9,15 +9,9 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
|
|||
* [ ] New endpoints for featured tags: tag_feature(name), tag_unfeature(name)
|
||||
* [ ] New endpoint: instance_terms, with or without date (format?)
|
||||
* [x] Some oauth stuff (userinfo? capability discovery? see issue for that)
|
||||
* [ ] status_delete now has a media delete param
|
||||
* [x] status_delete now has a media delete param
|
||||
* [ ] push_subscribe now has a "standard" parameter to switch between two versions. may also need to update crypto impls?
|
||||
* [ ] account_register now has a date of birth param (as above: format?)
|
||||
* [ ] update_credentials now has an attribution_domains param for link attribution (list)
|
||||
* [x] Various updates to return values (automatable, hopefully, other than docs)
|
||||
* [x] There is a "Deprecation" http header now, expose that to users?
|
||||
|
||||
General improvements that would be good to do before doing another release
|
||||
--------------------------------------------------------------------------
|
||||
* [ ] Get test coverage like, real high
|
||||
|
||||
* [ ] Also add links to tests to the docstrings so people can see usage examples
|
||||
|
|
|
@ -425,16 +425,25 @@ class Mastodon(Internals):
|
|||
return self.status_post(**keyword_args)
|
||||
|
||||
@api_version("1.0.0", "1.0.0")
|
||||
def status_delete(self, id: Union[Status, IdType]) -> Status:
|
||||
def status_delete(self, id: Union[Status, IdType], delete_media: bool = None) -> Status:
|
||||
"""
|
||||
Delete a status
|
||||
|
||||
Returns the now-deleted status, with an added "source" attribute that contains
|
||||
Returns the now-deleted status, with an added "text" attribute that contains
|
||||
the text that was used to compose this status (this can be used to power
|
||||
"delete and redraft" functionality)
|
||||
"delete and redraft" functionality) as well as either poll or media_attachments
|
||||
set in the same way. Note that when reattaching media, you have to wait up to several
|
||||
seconds for the media to be un-attached from the original status - that operation is
|
||||
not synchronous with the delete.
|
||||
|
||||
Pass `delete_media=True` to delete the media attachments of the status immediately,
|
||||
instead of just scheduling them for deletion as part of the next media cleanup. If you
|
||||
set this, you will not be able to reuse them in a new status (so if you're delete-redrafting,
|
||||
you should not set this).
|
||||
"""
|
||||
id = self.__unpack_id(id)
|
||||
return self.__api_request('DELETE', f'/api/v1/statuses/{id}')
|
||||
params = self.__generate_params(locals(), ['id'])
|
||||
return self.__api_request('DELETE', f'/api/v1/statuses/{id}', params)
|
||||
|
||||
@api_version("1.0.0", "2.0.0")
|
||||
def status_reblog(self, id: Union[Status, IdType], visibility: Optional[str] = None) -> Status:
|
||||
|
|
Plik diff jest za duży
Load Diff
113
tests/setup.sql
113
tests/setup.sql
|
@ -1,5 +1,3 @@
|
|||
DELETE FROM settings WHERE thing_id = 1234567890123456;
|
||||
DELETE FROM settings WHERE thing_id = 1234567890123457;
|
||||
DELETE FROM oauth_access_tokens WHERE id = 6543210987654321;
|
||||
DELETE FROM oauth_access_tokens WHERE id = 1234567890123456;
|
||||
DELETE FROM oauth_access_tokens WHERE id = 1234567890123457;
|
||||
|
@ -95,121 +93,16 @@ INSERT INTO settings (
|
|||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
123456,
|
||||
'open_registrations',
|
||||
E'--- true\n...\n',
|
||||
NULL,
|
||||
NULL,
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123456,
|
||||
'notification_emails',
|
||||
E'---\nfollow_request: false',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123457,
|
||||
'default_privacy',
|
||||
E'--- public\n...\n',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123458,
|
||||
'default_sensitive',
|
||||
E'--- false\n...\n',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123459,
|
||||
'notification_emails',
|
||||
E'---\nfollow_request: false',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test_2@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123460,
|
||||
'default_privacy',
|
||||
E'--- public\n...\n',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test_2@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
INSERT INTO settings (
|
||||
id,
|
||||
var,
|
||||
value,
|
||||
thing_type,
|
||||
thing_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
1234567890123461,
|
||||
'default_sensitive',
|
||||
E'--- false\n...\n',
|
||||
'User',
|
||||
(SELECT id FROM users WHERE email = 'mastodonpy_test_2@localhost'),
|
||||
now(),
|
||||
now()
|
||||
);
|
||||
UPDATE users SET
|
||||
settings = '{"notification_emails.follow_request": false, "default_privacy": "public", "default_sensitive": false}'
|
||||
WHERE email IN ('mastodonpy_test@localhost', 'mastodonpy_test_2@localhost');
|
||||
|
|
|
@ -299,4 +299,35 @@ def test_status_translate(api, status):
|
|||
# our test server does not support translation, so this will raise a MastodonAPIError
|
||||
with pytest.raises(MastodonAPIError):
|
||||
translation = api.status_translate(status['id'], 'de')
|
||||
|
||||
|
||||
@pytest.mark.vcr(match_on=['path'])
|
||||
def test_status_delete_media(api, status):
|
||||
# Prepare a status with media
|
||||
try:
|
||||
media = api.media_post('tests/image.jpg')
|
||||
status_with_media = api.status_post('Status with media', media_ids=media)
|
||||
|
||||
# Delete it without media wipe
|
||||
deleted_status = api.status_delete(status_with_media['id'], delete_media=False)
|
||||
assert deleted_status['id'] == status_with_media['id']
|
||||
print(deleted_status.media_attachments[0].id)
|
||||
|
||||
time.sleep(5) # Wait for media deletion to be processed
|
||||
|
||||
# Now repost and delete it with media wipe
|
||||
status_with_media = api.status_post('Status with media reposted', media_ids=[deleted_status.media_attachments[0].id])
|
||||
deleted_status = api.status_delete(status_with_media['id'], delete_media=True)
|
||||
assert deleted_status['id'] == status_with_media['id']
|
||||
|
||||
time.sleep(5) # Wait for media deletion to be processed
|
||||
|
||||
# Check that the media is deleted by trying to repost again (should fail)
|
||||
with pytest.raises(MastodonAPIError):
|
||||
api.status_post('Trying to repost deleted media', media_ids=status_with_media['media_attachments'][0].id)
|
||||
finally:
|
||||
# Delete status if it exists
|
||||
try:
|
||||
api.status_delete(status_with_media['id'])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue