add media v2 API + tests, move v1 test

pull/253/head
halcy 2022-11-08 23:24:42 +02:00
rodzic 3277ca7778
commit d0b1da993d
9 zmienionych plików z 71534 dodań i 1999 usunięć

66
TODO.md
Wyświetl plik

@ -4,63 +4,63 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
3.1.3
-----
[ ] POST /api/v1/media → POST /api/v2/media (v1 deprecated)
* [x] POST /api/v1/media → POST /api/v2/media (v1 deprecated)
3.1.4
-----
[ ] Add ability to exclude local content from federated timeline
[ ] Add ability to exclude remote content from hashtag timelines in web UI
[ ] Add invites_enabled attribute to GET /api/v1/instance in REST API
* [ ] Add ability to exclude local content from federated timeline
* [ ] Add ability to exclude remote content from hashtag timelines in web UI
* [ ] Add invites_enabled attribute to GET /api/v1/instance in REST API
3.2.0
-----
[ ] Add personal notes for accounts
[ ] Add customizable thumbnails for audio and video attachments
[ ] Add color extraction for thumbnails
* [ ] Add personal notes for accounts
* [ ] Add customizable thumbnails for audio and video attachments
* [ ] Add color extraction for thumbnails
3.3.0
-----
[ ] Add option to be notified when a followed user posts
[ ] Add duration option to the mute function
[ ] Add ability to block access or limit sign-ups from chosen IPs
[ ] Add support for managing multiple stream subscriptions in a single connection
[ ] Add support for limiting results by both min_id and max_id at the same time in REST API
[ ] Add GET /api/v1/accounts/:id/featured_tags to REST API
* [ ] Add option to be notified when a followed user posts
* [ ] Add duration option to the mute function
* [ ] Add ability to block access or limit sign-ups from chosen IPs
* [ ] Add support for managing multiple stream subscriptions in a single connection
* [ ] Add support for limiting results by both min_id and max_id at the same time in REST API
* [ ] Add GET /api/v1/accounts/:id/featured_tags to REST API
3.4.0
-----
[ ] Add server rules
[ ] Add POST /api/v1/emails/confirmations to REST API
[ ] Add GET /api/v1/accounts/lookup to REST API
[ ] Add policy param to POST /api/v1/push/subscriptions in REST API
[ ] Add details to error response for POST /api/v1/accounts in REST API
* [ ] Add server rules
* [ ] Add POST /api/v1/emails/confirmations to REST API
* [ ] Add GET /api/v1/accounts/lookup to REST API
* [ ] Add policy param to POST /api/v1/push/subscriptions in REST API
* [ ] Add details to error response for POST /api/v1/accounts in REST API
3.4.2
-----
[ ] Add configuration attribute to GET /api/v1/instance
* [ ] Add configuration attribute to GET /api/v1/instance
3.5.0
-----
[ ] 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
[ ] Add GET /api/v1/accounts/familiar_followers to REST API
[ ] Add POST /api/v1/accounts/:id/remove_from_followers to REST API
[ ] Add category and rule_ids params to POST /api/v1/reports IN REST API
[ ] Add global lang param to REST API
[ ] Add types param to GET /api/v1/notifications in REST API
[ ] Add notifications for moderators about new sign-ups
* [ ] 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
* [ ] Add GET /api/v1/accounts/familiar_followers to REST API
* [ ] Add POST /api/v1/accounts/:id/remove_from_followers to REST API
* [ ] Add category and rule_ids params to POST /api/v1/reports IN REST API
* [ ] Add global lang param to REST API
* [ ] Add types param to GET /api/v1/notifications in REST API
* [ ] Add notifications for moderators about new sign-ups
3.5.3
-----
[ ] Add limited attribute to accounts in REST API
* [ ] Add limited attribute to accounts in REST API
4.0.0 and beyond
----------------
? ? ? ?
General improvements that would be good to do before doing another release:
[ ] Split mastodon.py into parts in some way that makes sense, it's getting very unwieldy
[ ] Fix the CI
[ ] Get test coverage like, real high
* [ ] Split mastodon.py into parts in some way that makes sense, it's getting very unwieldy
* [ ] Fix the CI
* [ ] Get test coverage like, real high

Wyświetl plik

@ -1817,10 +1817,7 @@ class Mastodon:
if not isinstance(media_ids, (list, tuple)):
media_ids = [media_ids]
for media_id in media_ids:
if isinstance(media_id, dict):
media_ids_proper.append(media_id["id"])
else:
media_ids_proper.append(media_id)
media_ids_proper.append(self.__unpack_id(media_id))
except Exception as e:
raise MastodonIllegalArgumentError("Invalid media "
"dict: %s" % e)

Wyświetl plik

@ -28,7 +28,7 @@ To set this up, follow the development guide and set up the database using "rail
It also needs various things to be set up for it. The following command should do the trick:
RAILS_ENV=development rails db:setup && RAILS_ENV=development bin/tootctl accounts create admin2 --email alice@example.com --confirmed --role Owner && psql -d mastodon_development < ~/Mastodon.py/tests/setup.sql && sleep 4 && foreman start
sudo redis-cli flushall && sleep 3 && sudo /etc/init.d/redis-server restart && RAILS_ENV=development rails db:setup && RAILS_ENV=development bin/tootctl accounts create admin2 --email zerocool@example.com --confirmed --role Owner && psql -d mastodon_development < ~/masto/Mastodon.py/tests/setup.sql && sleep 4 && foreman start
Tests that send requests to Mastodon should be marked as needing VCR with the `pytest.mark.vcr` decorator.

BIN
tests/amewatson.jpg 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 26 KiB

Wyświetl plik

@ -1,18 +1,53 @@
import pytest
import vcr
import time
@pytest.mark.vcr(match_on=['path'])
def test_media_post_v1(api):
with vcr.use_cassette('test_media_post.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
media = api.media_post(
'tests/image.jpg',
description="John Lennon doing a funny walk",
focus=(-0.5, 0.3))
assert media
status = api.status_post(
'LOL check this out',
media_ids=media,
sensitive=False
)
assert status
try:
assert status['sensitive'] == False
assert status['media_attachments']
assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk"
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
finally:
api.status_delete(status['id'])
@pytest.mark.vcr(match_on=['path'])
@pytest.mark.parametrize('sensitive', (False, True))
def test_media_post(api, sensitive):
media = api.media_post(
'tests/image.jpg',
description="John Lennon doing a funny walk",
'tests/video.mp4',
description="me when a cat",
focus=(-0.5, 0.3))
assert media
assert media.url is None
time.sleep(10)
media2 = api.media(media)
assert media2.id == media.id
assert not media2.url is None
status = api.status_post(
'LOL check this out',
media_ids=media,
media_ids=media2,
sensitive=sensitive
)
@ -20,10 +55,45 @@ def test_media_post(api, sensitive):
try:
assert status['sensitive'] == sensitive
assert status['media_attachments']
assert status['media_attachments'][0]['description'] == "me when a cat"
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
finally:
api.status_delete(status['id'])
def test_media_post_multiple(api):
media = api.media_post(
'tests/image.jpg',
description="John Lennon doing a funny walk",
focus=(-0.5, 0.3),
synchronous=True)
media2 = api.media_post(
'tests/amewatson.jpg',
description="hololives #1 detective, watson ameliachan",
focus=(0.5, 0.5),
synchronous=True)
assert media
assert media.url is not None
assert media2
assert media2.url is not None
status = api.status_post(
'LOL check this out',
media_ids=[media, media2.id],
)
assert status
try:
assert status['media_attachments']
assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk"
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
assert status['media_attachments'][1]['description'] == "hololives #1 detective, watson ameliachan"
assert status['media_attachments'][1]['meta']['focus']['x'] == 0.5
assert status['media_attachments'][1]['meta']['focus']['y'] == 0.5
finally:
api.status_delete(status['id'])

BIN
tests/video.mp4 100644

Plik binarny nie jest wyświetlany.