diff options
author | Lorenz Diener <[email protected]> | 2019-10-11 22:07:51 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-10-11 22:07:51 +0200 |
commit | f42032dafcefd422d3819ace721accf75f2d0c91 (patch) | |
tree | 8e4bf4efefbe351bbc85a981df29c8f94d6c884e | |
parent | 17013f1d356f13004c66aed4181041f71c568b9e (diff) | |
download | mastodon.py-f42032dafcefd422d3819ace721accf75f2d0c91.tar.gz |
Add new card behaviour, freeze old test
-rw-r--r-- | mastodon/Mastodon.py | 16 | ||||
-rw-r--r-- | tests/cassettes_pre_2_9_2/test_status_card.yaml | 144 | ||||
-rw-r--r-- | tests/test_status.py | 16 |
3 files changed, 172 insertions, 4 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 91f5125..7f9a008 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -784,7 +784,7 @@ class Mastodon: | |||
784 | url = '/api/v1/statuses/{0}'.format(str(id)) | 784 | url = '/api/v1/statuses/{0}'.format(str(id)) |
785 | return self.__api_request('GET', url) | 785 | return self.__api_request('GET', url) |
786 | 786 | ||
787 | @api_version("1.0.0", "1.0.0", __DICT_VERSION_CARD) | 787 | @api_version("1.0.0", "3.0.0", __DICT_VERSION_CARD) |
788 | def status_card(self, id): | 788 | def status_card(self, id): |
789 | """ | 789 | """ |
790 | Fetch a card associated with a status. A card describes an object (such as an | 790 | Fetch a card associated with a status. A card describes an object (such as an |
@@ -792,11 +792,19 @@ class Mastodon: | |||
792 | 792 | ||
793 | Does not require authentication for publicly visible statuses. | 793 | Does not require authentication for publicly visible statuses. |
794 | 794 | ||
795 | This function is deprecated as of 3.0.0 and the endpoint does not | ||
796 | exist anymore - you should just use the "card" field of the status dicts | ||
797 | instead. Mastodon.py will try to mimick the old behaviour, but this | ||
798 | is somewhat inefficient and not guaranteed to be the case forever. | ||
799 | |||
795 | Returns a `card dict`_. | 800 | Returns a `card dict`_. |
796 | """ | 801 | """ |
797 | id = self.__unpack_id(id) | 802 | if self.verify_minimum_version("3.0.0"): |
798 | url = '/api/v1/statuses/{0}/card'.format(str(id)) | 803 | return self.status(id).card |
799 | return self.__api_request('GET', url) | 804 | else: |
805 | id = self.__unpack_id(id) | ||
806 | url = '/api/v1/statuses/{0}/card'.format(str(id)) | ||
807 | return self.__api_request('GET', url) | ||
800 | 808 | ||
801 | @api_version("1.0.0", "1.0.0", __DICT_VERSION_CONTEXT) | 809 | @api_version("1.0.0", "1.0.0", __DICT_VERSION_CONTEXT) |
802 | def status_context(self, id): | 810 | def status_context(self, id): |
diff --git a/tests/cassettes_pre_2_9_2/test_status_card.yaml b/tests/cassettes_pre_2_9_2/test_status_card.yaml new file mode 100644 index 0000000..fdaccff --- /dev/null +++ b/tests/cassettes_pre_2_9_2/test_status_card.yaml | |||
@@ -0,0 +1,144 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: status=http%3A%2F%2Fexample.org%2F | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
8 | Connection: [keep-alive] | ||
9 | Content-Length: ['34'] | ||
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: | ||
16 | string: !!binary | | ||
17 | H4sIAHLfoF0AA5RU227bMAz9lUDPTXyJ08UGBuwH9tanLYPByIyjVZYESU4bBPv3Ub5kTute9mTx | ||
18 | kIeiyENfmKhYwZI4zbPNJs3ydbrNk3SzZXeMWwSPVQmeItI4yZdJvEyShzQu4rjI8tV2m/+gOKFK | ||
19 | i0aeS6/LkE21Ut6iwLlulZ94HSonvDghKw4gHRJitJBoS4/P4T7KexJO7IUU/ky2afdScEIlqLqF | ||
20 | GsdMrRXkPnpviiiSmoM8auej1qF1UQPO60orQ2Ugoc6DJ4+LZh/cWjmX6tvLLLPk8FiBruxeyoo4 | ||
21 | IHup6ylygJOmej3OgtW1Fz2zniBNO/UbodTE5Fp5DNnYro3jNTfdB3sDFkeLh6+78V34DI2RuNK2 | ||
22 | jnZsYVGST+mDllI/LZTWBhVa8niwNXpylnvq+eOOTbM6A2rBJThHAUJ1o5I4xgxX9aFRiH2TO1Ju | ||
23 | yvoE79Wdb5AiuLGG1rCxx6OKwND0OHihFSsuTEFDAmPfh8GvzHkRJr9wLc2JyE+4d+HUsf8QnQ/z | ||
24 | vAz7lK6zzf2XbR73pyAuEuSQ9oWeWMf3s45KOCPhXA7MoH/NHyez32v/TwevFja+X6bpQ7oukqTY | ||
25 | pKssS8LCKh1KnxPLpD+fXIZQ/AlIK3PBvcdF2opaKJBRI5wTql4ZVV+JZVhKWu3/5x8RKpy9uPd8 | ||
26 | QHzn4g/4/bJQwHSNO4xiJtj4uxmh9I5ho38Lx4qfv4giUFbdmSTUYCWARueBHxva5iEmHEmUg+Wh | ||
27 | Hk7TPBzs9cdqqIxBln8BAAD//wMAq8iDptwFAAA= | ||
28 | headers: | ||
29 | Cache-Control: ['no-cache, no-store'] | ||
30 | Content-Encoding: [gzip] | ||
31 | Content-Type: [application/json; charset=utf-8] | ||
32 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
33 | Vary: ['Accept-Encoding, Origin'] | ||
34 | X-Content-Type-Options: [nosniff] | ||
35 | X-Download-Options: [noopen] | ||
36 | X-Frame-Options: [SAMEORIGIN] | ||
37 | X-Permitted-Cross-Domain-Policies: [none] | ||
38 | X-Request-Id: [5695c474-1f03-4198-934a-063f525d1421] | ||
39 | X-Runtime: ['0.206173'] | ||
40 | X-XSS-Protection: [1; mode=block] | ||
41 | status: {code: 200, message: OK} | ||
42 | - request: | ||
43 | body: null | ||
44 | headers: | ||
45 | Accept: ['*/*'] | ||
46 | Accept-Encoding: ['gzip, deflate'] | ||
47 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
48 | Connection: [keep-alive] | ||
49 | User-Agent: [python-requests/2.18.4] | ||
50 | method: GET | ||
51 | uri: http://localhost:3000/api/v1/instance/ | ||
52 | response: | ||
53 | body: | ||
54 | string: !!binary | | ||
55 | H4sIAHffoF0AA0yQXU7EMAyE7+Ln0vRnabe5AydAqDKJaQNpEiXO7sNq705KWcSb/WlGM/YNcjQg | ||
56 | wXqFdvWJoQI2bKmwF0zstXcFaUoqmsCmbBIKoA2NPcYLxXTwrp7qtpAcbQJ5g8SRcDNumTHsIdck | ||
57 | hfhLkqemaeBeFRnyjz4nirPy2THI/uA5PUDXlhq+xLoHaYqX17y9u6PLyhz+B4iA6iuJjbRBYTZc | ||
58 | KIkQ6WLo+jRhO+q++1Cncz9MdFZKT22D43M3NDSMuv4MS7nEolvybgT5CuTgrYJIiymH4f6Lgjlm | ||
59 | qkB5x6h4RvXbzWVr798AAAD//wMA7+lJTl0BAAA= | ||
60 | headers: | ||
61 | Cache-Control: ['max-age=300, public'] | ||
62 | Content-Encoding: [gzip] | ||
63 | Content-Type: [application/json; charset=utf-8] | ||
64 | Date: ['Fri, 11 Oct 2019 20:00:55 GMT'] | ||
65 | ETag: [W/"d02697950b63ada2556058876a3603cd"] | ||
66 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
67 | Vary: ['Accept-Encoding, Origin'] | ||
68 | X-Content-Type-Options: [nosniff] | ||
69 | X-Download-Options: [noopen] | ||
70 | X-Frame-Options: [SAMEORIGIN] | ||
71 | X-Permitted-Cross-Domain-Policies: [none] | ||
72 | X-Request-Id: [cdbcdbaf-3317-4d46-88dd-a2108d9d8644] | ||
73 | X-Runtime: ['0.050483'] | ||
74 | X-XSS-Protection: [1; mode=block] | ||
75 | status: {code: 200, message: OK} | ||
76 | - request: | ||
77 | body: null | ||
78 | headers: | ||
79 | Accept: ['*/*'] | ||
80 | Accept-Encoding: ['gzip, deflate'] | ||
81 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
82 | Connection: [keep-alive] | ||
83 | User-Agent: [python-requests/2.18.4] | ||
84 | method: GET | ||
85 | uri: http://localhost:3000/api/v1/statuses/102945524932891258/card | ||
86 | response: | ||
87 | body: | ||
88 | string: !!binary | | ||
89 | H4sIAHffoF0AA0yNyw4CIQxFf8V0PRHXrPU7DEoDjRQIFh8x/rsdGSfues+5N31BbwksRJFqjcGH | ||
90 | 45pwW1owMIGQJFR7GHizL+woq/B4PTeqQiWrnpvPOhcT5Ysm1yWWdsyOcegFjF+aays38vhfWdFa | ||
91 | isLLdScvEexOGVKI8j2JXdBt7ilNgHxC/5u+PwAAAP//AwBs2irL1gAAAA== | ||
92 | headers: | ||
93 | Cache-Control: ['no-cache, no-store'] | ||
94 | Content-Encoding: [gzip] | ||
95 | Content-Type: [application/json; charset=utf-8] | ||
96 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
97 | Vary: ['Accept-Encoding, Origin'] | ||
98 | X-Content-Type-Options: [nosniff] | ||
99 | X-Download-Options: [noopen] | ||
100 | X-Frame-Options: [SAMEORIGIN] | ||
101 | X-Permitted-Cross-Domain-Policies: [none] | ||
102 | X-Request-Id: [8d8488d2-f693-4edb-ba17-a9b4bb524b59] | ||
103 | X-Runtime: ['0.070177'] | ||
104 | X-XSS-Protection: [1; mode=block] | ||
105 | status: {code: 200, message: OK} | ||
106 | - request: | ||
107 | body: null | ||
108 | headers: | ||
109 | Accept: ['*/*'] | ||
110 | Accept-Encoding: ['gzip, deflate'] | ||
111 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
112 | Connection: [keep-alive] | ||
113 | Content-Length: ['0'] | ||
114 | User-Agent: [python-requests/2.18.4] | ||
115 | method: DELETE | ||
116 | uri: http://localhost:3000/api/v1/statuses/102945524932891258 | ||
117 | response: | ||
118 | body: | ||
119 | string: !!binary | | ||
120 | H4sIAHffoF0AA5RUy47bMAz8lYXOm1hWnG3sU3+gtz31AYOxGYetLAmWnN0g6L+XcpTA3Rrd9hRq | ||
121 | yKGG1MQXQa2oRC5VWWy3qig3alfmarsTj6IZEAK2NQSuUDIvV7lc5fmzkpWUVVGud7vyM9eRqQd0 | ||
122 | +lwHW8duZtT6dxSaxo4mzLIejadAJxTVAbRHRpwljUMd8DXex31P5GlPmsKZz27ca2oY1WC6ETq8 | ||
123 | dRoH4vQxBFdlmbYN6KP1IRs9Dj7rwQfbWuNYBjLqAwTO+Gxx4HHQS60+vu2ySI7DEvp6mlRUMiJ7 | ||
124 | bbs5coCTZb0BF8H2vosrs5sh/TjPOzJmdkwrS8LxFXqncW2HLhO3XrdtgWOVDQSyRlQXYaDnRYpP | ||
125 | acC1Oz/ECR/8yHqY/IJ7H6OJ/ZPpTdJ9Sb5Rm2L79GFXymsUl8iLT23f7E1M/LCYaMk7Dec6MeM7 | ||
126 | 2+bHbMa9Dff4T2PKp5VSz2pT5Xm1VeuiyKMxjY3SxddRyk3jph+8HrJ0+vdHj+JPEGBYKr5mfGYH | ||
127 | 6siAznrynky3dqa7E+toPrbw//OPCC0uXnzNvEP8y8Xv8A9Wa/vCBXO7ThjXzLDb3+oGqUeBvf1O | ||
128 | XlRfvjGFULdTzBbqsSXgpwvQHHs0IdXEkE2ZTgG6FM37NDDcPyCOZSRb/gIAAP//AwC9GyasxAQA | ||
129 | AA== | ||
130 | headers: | ||
131 | Cache-Control: ['no-cache, no-store'] | ||
132 | Content-Encoding: [gzip] | ||
133 | Content-Type: [application/json; charset=utf-8] | ||
134 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
135 | Vary: ['Accept-Encoding, Origin'] | ||
136 | X-Content-Type-Options: [nosniff] | ||
137 | X-Download-Options: [noopen] | ||
138 | X-Frame-Options: [SAMEORIGIN] | ||
139 | X-Permitted-Cross-Domain-Policies: [none] | ||
140 | X-Request-Id: [ae14d39d-fe87-49ff-8072-5e43f83ef722] | ||
141 | X-Runtime: ['0.109924'] | ||
142 | X-XSS-Protection: [1; mode=block] | ||
143 | status: {code: 200, message: OK} | ||
144 | version: 1 | ||
diff --git a/tests/test_status.py b/tests/test_status.py index ef27f9c..32f57a4 100644 --- a/tests/test_status.py +++ b/tests/test_status.py | |||
@@ -2,6 +2,7 @@ import pytest | |||
2 | from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError | 2 | from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError |
3 | import datetime | 3 | import datetime |
4 | import pytz | 4 | import pytz |
5 | import vcr | ||
5 | 6 | ||
6 | @pytest.mark.vcr() | 7 | @pytest.mark.vcr() |
7 | def test_status(status, api): | 8 | def test_status(status, api): |
@@ -28,6 +29,8 @@ def test_status_missing(api): | |||
28 | api.status(0) | 29 | api.status(0) |
29 | 30 | ||
30 | # Messy and will only work if there is an internet connection that is decent, obviously. | 31 | # Messy and will only work if there is an internet connection that is decent, obviously. |
32 | # Also, deprecated, but still a good test (Mastodon.py tries to fake the old behaviour | ||
33 | # internally) | ||
31 | @pytest.mark.vcr() | 34 | @pytest.mark.vcr() |
32 | def test_status_card(api): | 35 | def test_status_card(api): |
33 | import time | 36 | import time |
@@ -39,6 +42,19 @@ def test_status_card(api): | |||
39 | finally: | 42 | finally: |
40 | api.status_delete(status['id']) | 43 | api.status_delete(status['id']) |
41 | 44 | ||
45 | # Old-version card api | ||
46 | def test_status_card_pre_2_9_2(api): | ||
47 | with vcr.use_cassette('test_status_card.yaml', cassette_library_dir='tests/cassettes_pre_2_9_2', record_mode='none'): | ||
48 | import time | ||
49 | status = api.status_post("http://example.org/") | ||
50 | time.sleep(5) # Card generation may take time | ||
51 | card = api.status_card(status['id']) | ||
52 | try: | ||
53 | assert card | ||
54 | finally: | ||
55 | api.status_delete(status['id']) | ||
56 | |||
57 | |||
42 | @pytest.mark.vcr() | 58 | @pytest.mark.vcr() |
43 | def test_status_context(status, api): | 59 | def test_status_context(status, api): |
44 | context = api.status_context(status['id']) | 60 | context = api.status_context(status['id']) |