diff options
author | Lorenz Diener <[email protected]> | 2019-04-28 21:24:31 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-04-28 21:24:31 +0200 |
commit | eb0fa327c4b3b520e243d7b888724512a905347a (patch) | |
tree | 871b9777162c2272ca6808ad9ba9794df09c342c | |
parent | c82b0b19196d5d390419d71e2b45f11ec1c74a05 (diff) | |
download | mastodon.py-eb0fa327c4b3b520e243d7b888724512a905347a.tar.gz |
Add reblog visibility
-rw-r--r-- | mastodon/Mastodon.py | 20 | ||||
-rw-r--r-- | tests/cassettes/test_status_reblog_visibility.yaml | 96 | ||||
-rw-r--r-- | tests/test_status.py | 5 |
3 files changed, 116 insertions, 5 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index dd710b7..3fe3d21 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1370,8 +1370,7 @@ class Mastodon: | |||
1370 | should be marked as sensitive, which hides it by default on the Mastodon | 1370 | should be marked as sensitive, which hides it by default on the Mastodon |
1371 | web front-end. | 1371 | web front-end. |
1372 | 1372 | ||
1373 | The visibility parameter is a string value and matches the visibility | 1373 | The visibility parameter is a string value and accepts any of: |
1374 | option on the /api/v1/status POST API endpoint. It accepts any of: | ||
1375 | 'direct' - post will be visible only to mentioned users | 1374 | 'direct' - post will be visible only to mentioned users |
1376 | 'private' - post will be visible only to followers | 1375 | 'private' - post will be visible only to followers |
1377 | 'unlisted' - post will be public but not appear on the public timeline | 1376 | 'unlisted' - post will be public but not appear on the public timeline |
@@ -1514,15 +1513,26 @@ class Mastodon: | |||
1514 | self.__api_request('DELETE', url) | 1513 | self.__api_request('DELETE', url) |
1515 | 1514 | ||
1516 | @api_version("1.0.0", "2.0.0", __DICT_VERSION_STATUS) | 1515 | @api_version("1.0.0", "2.0.0", __DICT_VERSION_STATUS) |
1517 | def status_reblog(self, id): | 1516 | def status_reblog(self, id, visibility=None): |
1518 | """ | 1517 | """ |
1519 | Reblog a status. | 1518 | Reblog / boost a status. |
1519 | |||
1520 | The visibility parameter functions the same as in `status_post()`_ and | ||
1521 | allows you to reduce the visibility of a reblogged status. | ||
1520 | 1522 | ||
1521 | Returns a `toot dict`_ with a new status that wraps around the reblogged one. | 1523 | Returns a `toot dict`_ with a new status that wraps around the reblogged one. |
1522 | """ | 1524 | """ |
1525 | params = self.__generate_params(locals(), ['id']) | ||
1526 | valid_visibilities = ['private', 'public', 'unlisted', 'direct'] | ||
1527 | if 'visibility' in params: | ||
1528 | params['visibility'] = params['visibility'].lower() | ||
1529 | if params['visibility'] not in valid_visibilities: | ||
1530 | raise ValueError('Invalid visibility value! Acceptable ' | ||
1531 | 'values are %s' % valid_visibilities) | ||
1532 | |||
1523 | id = self.__unpack_id(id) | 1533 | id = self.__unpack_id(id) |
1524 | url = '/api/v1/statuses/{0}/reblog'.format(str(id)) | 1534 | url = '/api/v1/statuses/{0}/reblog'.format(str(id)) |
1525 | return self.__api_request('POST', url) | 1535 | return self.__api_request('POST', url, params) |
1526 | 1536 | ||
1527 | @api_version("1.0.0", "2.0.0", __DICT_VERSION_STATUS) | 1537 | @api_version("1.0.0", "2.0.0", __DICT_VERSION_STATUS) |
1528 | def status_unreblog(self, id): | 1538 | def status_unreblog(self, id): |
diff --git a/tests/cassettes/test_status_reblog_visibility.yaml b/tests/cassettes/test_status_reblog_visibility.yaml new file mode 100644 index 0000000..500a68d --- /dev/null +++ b/tests/cassettes/test_status_reblog_visibility.yaml | |||
@@ -0,0 +1,96 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: status=Toot%21 | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
8 | Connection: [keep-alive] | ||
9 | Content-Length: ['14'] | ||
10 | Content-Type: [application/x-www-form-urlencoded] | ||
11 | User-Agent: [python-requests/2.18.4] | ||
12 | method: POST | ||
13 | uri: http://localhost:3000/api/v1/statuses | ||
14 | response: | ||
15 | body: {string: '{"id":"102005434139190710","created_at":"2019-04-28T19:23:22.764Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102005434139190710","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102005434139190710","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py | ||
16 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":1,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'} | ||
17 | headers: | ||
18 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
19 | Content-Type: [application/json; charset=utf-8] | ||
20 | ETag: [W/"5f9216b37a617266e1e57234796c9452"] | ||
21 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
22 | Transfer-Encoding: [chunked] | ||
23 | Vary: ['Accept-Encoding, Origin'] | ||
24 | X-Content-Type-Options: [nosniff] | ||
25 | X-Download-Options: [noopen] | ||
26 | X-Frame-Options: [SAMEORIGIN] | ||
27 | X-Permitted-Cross-Domain-Policies: [none] | ||
28 | X-Request-Id: [9c86d267-e58f-44e5-a529-26b9ff76fc9e] | ||
29 | X-Runtime: ['0.201113'] | ||
30 | X-XSS-Protection: [1; mode=block] | ||
31 | content-length: ['1235'] | ||
32 | status: {code: 200, message: OK} | ||
33 | - request: | ||
34 | body: visibility=unlisted | ||
35 | headers: | ||
36 | Accept: ['*/*'] | ||
37 | Accept-Encoding: ['gzip, deflate'] | ||
38 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
39 | Connection: [keep-alive] | ||
40 | Content-Length: ['19'] | ||
41 | Content-Type: [application/x-www-form-urlencoded] | ||
42 | User-Agent: [python-requests/2.18.4] | ||
43 | method: POST | ||
44 | uri: http://localhost:3000/api/v1/statuses/102005434139190710/reblog | ||
45 | response: | ||
46 | body: {string: '{"id":"102005434155449471","created_at":"2019-04-28T19:23:23.011Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"unlisted","language":null,"uri":"http://localhost/users/mastodonpy_test/statuses/102005434155449471/activity","content":"\u003cp\u003eRT | ||
47 | \u003cspan class=\"h-card\"\u003e\u003ca href=\"http://localhost/@mastodonpy_test\" | ||
48 | class=\"u-url mention\"\u003e@\u003cspan\u003emastodonpy_test\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
49 | Toot!\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102005434155449471","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":true,"muted":false,"reblog":{"id":"102005434139190710","created_at":"2019-04-28T19:23:22.764Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102005434139190710","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102005434139190710","replies_count":0,"reblogs_count":1,"favourites_count":0,"favourited":false,"reblogged":true,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py | ||
50 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":2,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null},"application":null,"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":2,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'} | ||
51 | headers: | ||
52 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
53 | Content-Type: [application/json; charset=utf-8] | ||
54 | ETag: [W/"2959f64592e5d171090e7ddea7694697"] | ||
55 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
56 | Transfer-Encoding: [chunked] | ||
57 | Vary: ['Accept-Encoding, Origin'] | ||
58 | X-Content-Type-Options: [nosniff] | ||
59 | X-Download-Options: [noopen] | ||
60 | X-Frame-Options: [SAMEORIGIN] | ||
61 | X-Permitted-Cross-Domain-Policies: [none] | ||
62 | X-Request-Id: [cf8be3bc-b130-41f2-b113-19d60a7b7f2a] | ||
63 | X-Runtime: ['0.306052'] | ||
64 | X-XSS-Protection: [1; mode=block] | ||
65 | content-length: ['2613'] | ||
66 | status: {code: 200, message: OK} | ||
67 | - request: | ||
68 | body: null | ||
69 | headers: | ||
70 | Accept: ['*/*'] | ||
71 | Accept-Encoding: ['gzip, deflate'] | ||
72 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
73 | Connection: [keep-alive] | ||
74 | Content-Length: ['0'] | ||
75 | User-Agent: [python-requests/2.18.4] | ||
76 | method: DELETE | ||
77 | uri: http://localhost:3000/api/v1/statuses/102005434139190710 | ||
78 | response: | ||
79 | body: {string: '{}'} | ||
80 | headers: | ||
81 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
82 | Content-Type: [application/json; charset=utf-8] | ||
83 | ETag: [W/"7f009dc9f14d1cd3a178123556c5e99c"] | ||
84 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
85 | Transfer-Encoding: [chunked] | ||
86 | Vary: ['Accept-Encoding, Origin'] | ||
87 | X-Content-Type-Options: [nosniff] | ||
88 | X-Download-Options: [noopen] | ||
89 | X-Frame-Options: [SAMEORIGIN] | ||
90 | X-Permitted-Cross-Domain-Policies: [none] | ||
91 | X-Request-Id: [11dfaf76-732a-4a29-a1cf-41a526ad3c9a] | ||
92 | X-Runtime: ['0.031563'] | ||
93 | X-XSS-Protection: [1; mode=block] | ||
94 | content-length: ['2'] | ||
95 | status: {code: 200, message: OK} | ||
96 | version: 1 | ||
diff --git a/tests/test_status.py b/tests/test_status.py index 88c59ce..4f6295f 100644 --- a/tests/test_status.py +++ b/tests/test_status.py | |||
@@ -50,6 +50,11 @@ def test_status_reblogged_by(status, api): | |||
50 | assert reblogs | 50 | assert reblogs |
51 | 51 | ||
52 | @pytest.mark.vcr() | 52 | @pytest.mark.vcr() |
53 | def test_status_reblog_visibility(status, api): | ||
54 | reblog_result = api.status_reblog(status['id'], visibility = 'unlisted') | ||
55 | assert reblog_result.visibility == 'unlisted' | ||
56 | |||
57 | @pytest.mark.vcr() | ||
53 | def test_status_favourited_by(status, api): | 58 | def test_status_favourited_by(status, api): |
54 | api.status_favourite(status['id']) | 59 | api.status_favourite(status['id']) |
55 | favourites = api.status_favourited_by(status['id']) | 60 | favourites = api.status_favourited_by(status['id']) |