aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-19 01:29:14 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-19 01:29:14 +0200
commitd992b9bb8c687c4ae6bff545edd303c6b58d4124 (patch)
tree1c3730c0900bc13a99ffdf0e573d9ae91c7fe5bc
parentf2282790cc7e980bba96cdadde2ab8b6af3e6095 (diff)
downloadmastodon.py-d992b9bb8c687c4ae6bff545edd303c6b58d4124.tar.gz
Add account lookup API
-rw-r--r--CHANGELOG.rst1
-rw-r--r--TODO.md2
-rw-r--r--docs/index.rst4
-rw-r--r--mastodon/Mastodon.py13
-rw-r--r--tests/cassettes/test_account_lookup.yaml232
-rw-r--r--tests/test_account.py11
6 files changed, 261 insertions, 2 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index ab2538e..da22ae1 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -6,6 +6,7 @@ v1.6.3
6------ 6------
7* Add server rules API (`instance_rules`) 7* Add server rules API (`instance_rules`)
8* Add confirmation email resend API (`email_resend_confirmation`) 8* Add confirmation email resend API (`email_resend_confirmation`)
9* Add account lookup API (`account_lookup`)
9 10
10v1.6.2 11v1.6.2
11------ 12------
diff --git a/TODO.md b/TODO.md
index 164717a..6964ea3 100644
--- a/TODO.md
+++ b/TODO.md
@@ -31,7 +31,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
31----- 31-----
32* [x] Add server rules 32* [x] Add server rules
33* [x] Add POST /api/v1/emails/confirmations to REST API 33* [x] Add POST /api/v1/emails/confirmations to REST API
34* [ ] Add GET /api/v1/accounts/lookup to REST API 34* [x] Add GET /api/v1/accounts/lookup to REST API
35* [ ] Add policy param to POST /api/v1/push/subscriptions in REST API 35* [ ] Add policy param to POST /api/v1/push/subscriptions in REST API
36* [ ] Add details to error response for POST /api/v1/accounts in REST API 36* [ ] Add details to error response for POST /api/v1/accounts in REST API
37 37
diff --git a/docs/index.rst b/docs/index.rst
index 2318a98..8b47fad 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -906,7 +906,7 @@ is specified, Mastodon.py defaults to https.
906.. automethod:: Mastodon.auth_request_url 906.. automethod:: Mastodon.auth_request_url
907.. automethod:: Mastodon.create_account 907.. automethod:: Mastodon.create_account
908.. automethod:: Mastodon.email_resend_confirmation 908.. automethod:: Mastodon.email_resend_confirmation
909 909
910Versioning 910Versioning
911---------- 911----------
912Mastodon.py will check if a certain endpoint is available before doing API 912Mastodon.py will check if a certain endpoint is available before doing API
@@ -999,6 +999,8 @@ their relationships.
999.. automethod:: Mastodon.account_followers 999.. automethod:: Mastodon.account_followers
1000.. automethod:: Mastodon.account_relationships 1000.. automethod:: Mastodon.account_relationships
1001.. automethod:: Mastodon.account_search 1001.. automethod:: Mastodon.account_search
1002.. automethod:: Mastodon.account_lists
1003.. automethod:: Mastodon.account_lookup
1002 1004
1003Reading data: Featured tags 1005Reading data: Featured tags
1004~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1006~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 629a4b2..6e5bc29 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1261,6 +1261,19 @@ class Mastodon:
1261 url = '/api/v1/accounts/{0}/lists'.format(str(id)) 1261 url = '/api/v1/accounts/{0}/lists'.format(str(id))
1262 return self.__api_request('GET', url, params) 1262 return self.__api_request('GET', url, params)
1263 1263
1264 @api_version("3.4.0", "3.4.0", __DICT_VERSION_ACCOUNT)
1265 def account_lookup(self, acct):
1266 """
1267 Look up an account from user@instance form (@instance allowed but not required for
1268 local accounts). Will only return accounts that the instance already knows about,
1269 and not do any webfinger requests. Use `account_search` if you need to resolve users
1270 through webfinger from remote.
1271
1272 Returns an `account dict`_.
1273 """
1274 return self.__api_request('GET', '/api/v1/accounts/lookup', self.__generate_params(locals()))
1275
1276
1264 ### 1277 ###
1265 # Reading data: Featured hashtags 1278 # Reading data: Featured hashtags
1266 ### 1279 ###
diff --git a/tests/cassettes/test_account_lookup.yaml b/tests/cassettes/test_account_lookup.yaml
new file mode 100644
index 0000000..01ed5f7
--- /dev/null
+++ b/tests/cassettes/test_account_lookup.yaml
@@ -0,0 +1,232 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept:
6 - '*/*'
7 Accept-Encoding:
8 - gzip, deflate
9 Authorization:
10 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
11 Connection:
12 - keep-alive
13 User-Agent:
14 - tests/v311
15 method: GET
16 uri: http://localhost:3000/api/v1/accounts/verify_credentials
17 response:
18 body:
19 string: '{"id":"109366898092282937","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-18T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","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":5,"last_status_at":"2022-11-18","noindex":false,"source":{"privacy":"public","sensitive":false,"language":null,"note":"","fields":[],"follow_requests_count":0},"emojis":[],"fields":[],"role":{"id":"-99","name":"","permissions":"65536","color":"","highlighted":false}}'
20 headers:
21 Cache-Control:
22 - no-store
23 Content-Security-Policy:
24 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
25 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
26 style-src ''self'' http://localhost:3000 ''nonce-3EN7F4MujpHoVrEZ3s8fag=='';
27 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
28 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
29 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
30 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
31 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
32 worker-src ''self'' blob: http://localhost:3000'
33 Content-Type:
34 - application/json; charset=utf-8
35 ETag:
36 - W/"dc5952ea4f0e073dc114984e11e688fe"
37 Referrer-Policy:
38 - strict-origin-when-cross-origin
39 Transfer-Encoding:
40 - chunked
41 Vary:
42 - Accept, Origin
43 X-Content-Type-Options:
44 - nosniff
45 X-Download-Options:
46 - noopen
47 X-Frame-Options:
48 - SAMEORIGIN
49 X-Permitted-Cross-Domain-Policies:
50 - none
51 X-Request-Id:
52 - b30300c0-b4d2-4d92-a447-90c4343be34f
53 X-Runtime:
54 - '0.012757'
55 X-XSS-Protection:
56 - 1; mode=block
57 status:
58 code: 200
59 message: OK
60- request:
61 body: null
62 headers:
63 Accept:
64 - '*/*'
65 Accept-Encoding:
66 - gzip, deflate
67 Authorization:
68 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
69 Connection:
70 - keep-alive
71 User-Agent:
72 - tests/v311
73 method: GET
74 uri: http://localhost:3000/api/v1/accounts/lookup?acct=kljadklajsdkljlkjlkjlkjasdasd
75 response:
76 body:
77 string: '{"error":"Record not found"}'
78 headers:
79 Cache-Control:
80 - no-store
81 Content-Security-Policy:
82 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
83 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
84 style-src ''self'' http://localhost:3000 ''nonce-K3+CoL7Djc57eXE+QOhaqw=='';
85 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
86 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
87 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
88 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
89 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
90 worker-src ''self'' blob: http://localhost:3000'
91 Content-Type:
92 - application/json; charset=utf-8
93 Referrer-Policy:
94 - strict-origin-when-cross-origin
95 Transfer-Encoding:
96 - chunked
97 Vary:
98 - Accept, Origin
99 X-Content-Type-Options:
100 - nosniff
101 X-Download-Options:
102 - noopen
103 X-Frame-Options:
104 - SAMEORIGIN
105 X-Permitted-Cross-Domain-Policies:
106 - none
107 X-Request-Id:
108 - ad639c09-6937-494b-8d8e-d07c4e57ae17
109 X-Runtime:
110 - '0.007311'
111 X-XSS-Protection:
112 - 1; mode=block
113 status:
114 code: 404
115 message: Not Found
116- request:
117 body: null
118 headers:
119 Accept:
120 - '*/*'
121 Accept-Encoding:
122 - gzip, deflate
123 Authorization:
124 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
125 Connection:
126 - keep-alive
127 User-Agent:
128 - tests/v311
129 method: GET
130 uri: http://localhost:3000/api/v1/accounts/lookup?acct=mastodonpy_test
131 response:
132 body:
133 string: '{"id":"109366898092282937","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-18T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","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":5,"last_status_at":"2022-11-18","noindex":false,"emojis":[],"fields":[]}'
134 headers:
135 Cache-Control:
136 - no-store
137 Content-Security-Policy:
138 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
139 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
140 style-src ''self'' http://localhost:3000 ''nonce-ahGApVKvUFVrZV/lQw3Ckw=='';
141 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
142 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
143 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
144 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
145 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
146 worker-src ''self'' blob: http://localhost:3000'
147 Content-Type:
148 - application/json; charset=utf-8
149 ETag:
150 - W/"38e63cb43c9359834b66f41070c8c079"
151 Referrer-Policy:
152 - strict-origin-when-cross-origin
153 Transfer-Encoding:
154 - chunked
155 Vary:
156 - Accept, Origin
157 X-Content-Type-Options:
158 - nosniff
159 X-Download-Options:
160 - noopen
161 X-Frame-Options:
162 - SAMEORIGIN
163 X-Permitted-Cross-Domain-Policies:
164 - none
165 X-Request-Id:
166 - 74fa7552-bb6c-4154-8993-aac7ede92f32
167 X-Runtime:
168 - '0.010043'
169 X-XSS-Protection:
170 - 1; mode=block
171 status:
172 code: 200
173 message: OK
174- request:
175 body: null
176 headers:
177 Accept:
178 - '*/*'
179 Accept-Encoding:
180 - gzip, deflate
181 Authorization:
182 - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN
183 Connection:
184 - keep-alive
185 User-Agent:
186 - tests/v311
187 method: GET
188 uri: http://localhost:3000/api/v1/accounts/lookup?acct=mastodonpy_test%40localhost%3A3000
189 response:
190 body:
191 string: '{"id":"109366898092282937","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-18T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","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":5,"last_status_at":"2022-11-18","noindex":false,"emojis":[],"fields":[]}'
192 headers:
193 Cache-Control:
194 - no-store
195 Content-Security-Policy:
196 - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
197 ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
198 style-src ''self'' http://localhost:3000 ''nonce-VIxMxXw1sv2+gz5VzvH8xw=='';
199 media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
200 https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
201 data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
202 ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
203 ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
204 worker-src ''self'' blob: http://localhost:3000'
205 Content-Type:
206 - application/json; charset=utf-8
207 ETag:
208 - W/"38e63cb43c9359834b66f41070c8c079"
209 Referrer-Policy:
210 - strict-origin-when-cross-origin
211 Transfer-Encoding:
212 - chunked
213 Vary:
214 - Accept, Origin
215 X-Content-Type-Options:
216 - nosniff
217 X-Download-Options:
218 - noopen
219 X-Frame-Options:
220 - SAMEORIGIN
221 X-Permitted-Cross-Domain-Policies:
222 - none
223 X-Request-Id:
224 - 772bdf24-12ae-4d4b-b4a1-ae3cd452e247
225 X-Runtime:
226 - '0.010063'
227 X-XSS-Protection:
228 - 1; mode=block
229 status:
230 code: 200
231 message: OK
232version: 1
diff --git a/tests/test_account.py b/tests/test_account.py
index 700433f..6f3b9a5 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -280,3 +280,14 @@ def test_follow_with_notify_reblog(api, api2, api3):
280 api.account_unfollow(api2_id) 280 api.account_unfollow(api2_id)
281 api3.status_delete(status1) 281 api3.status_delete(status1)
282 api2.status_delete(status2) 282 api2.status_delete(status2)
283
284@pytest.mark.vcr()
285def test_account_lookup(api, api3):
286 id = api.me().id
287 try:
288 api.account_lookup("kljadklajsdkljlkjlkjlkjasdasd")
289 assert False
290 except:
291 pass
292 assert(api.account_lookup("mastodonpy_test").id == id)
293 assert(api.account_lookup("mastodonpy_test@localhost:3000").id == id) \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)