aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-10-12 20:13:38 +0200
committerLorenz Diener <[email protected]>2019-10-12 20:13:38 +0200
commitf421b1e4984e1811153032cb56e8fd191a0e6307 (patch)
treefa33433139c06563426246bee1bc38be1ae12ef6
parent0b952aef124af09b6ea1267aac48bea6fc12f710 (diff)
downloadmastodon.py-f421b1e4984e1811153032cb56e8fd191a0e6307.tar.gz
Add new parameter for search
-rw-r--r--mastodon/Mastodon.py14
-rw-r--r--tests/cassettes/test_search.yaml22
-rw-r--r--tests/test_search.py3
3 files changed, 25 insertions, 14 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 47f76e1..c0d4c35 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1207,7 +1207,7 @@ class Mastodon:
1207 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+") 1207 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+")
1208 1208
1209 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT) 1209 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT)
1210 def search(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None): 1210 def search(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True):
1211 """ 1211 """
1212 Fetch matching hashtags, accounts and statuses. Will perform webfinger 1212 Fetch matching hashtags, accounts and statuses. Will perform webfinger
1213 lookups if resolve is True. Full-text search is only enabled if 1213 lookups if resolve is True. Full-text search is only enabled if
@@ -1221,6 +1221,9 @@ class Mastodon:
1221 1221
1222 `offset`, `min_id` and `max_id` can be used to paginate. 1222 `offset`, `min_id` and `max_id` can be used to paginate.
1223 1223
1224 `exclude_unreviewed` can be used to restrict search results for hashtags to only
1225 those that have been reviewed by moderators. It is on by default.
1226
1224 Will use search_v1 (no tag dicts in return values) on Mastodon versions before 1227 Will use search_v1 (no tag dicts in return values) on Mastodon versions before
1225 2.4.1), search_v2 otherwise. Parameters other than resolve are only available 1228 2.4.1), search_v2 otherwise. Parameters other than resolve are only available
1226 on Mastodon 2.8.0 or above - this function will throw a MastodonVersionError 1229 on Mastodon 2.8.0 or above - this function will throw a MastodonVersionError
@@ -1250,10 +1253,12 @@ class Mastodon:
1250 return self.__api_request('GET', '/api/v1/search', params) 1253 return self.__api_request('GET', '/api/v1/search', params)
1251 1254
1252 @api_version("2.4.1", "2.8.0", __DICT_VERSION_SEARCHRESULT) 1255 @api_version("2.4.1", "2.8.0", __DICT_VERSION_SEARCHRESULT)
1253 def search_v2(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None): 1256 def search_v2(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True):
1254 """ 1257 """
1255 Identical to `search_v1()`, except in that it returns tags as 1258 Identical to `search_v1()`, except in that it returns tags as
1256 `hashtag dicts`_, has more parameters, and resolves by default. 1259 `hashtag dicts`_, has more parameters, and resolves by default.
1260
1261 For more details documentation, please see `search()`
1257 1262
1258 Returns a `search result dict`_. 1263 Returns a `search result dict`_.
1259 """ 1264 """
@@ -1261,7 +1266,10 @@ class Mastodon:
1261 params = self.__generate_params(locals()) 1266 params = self.__generate_params(locals())
1262 1267
1263 if resolve == False: 1268 if resolve == False:
1264 del params['resolve'] 1269 del params["resolve"]
1270
1271 if exclude_unreviewed == False or not self.verify_minimum_version("3.0.0", cached=True):
1272 del params["exclude_unreviewed"]
1265 1273
1266 if "result_type" in params: 1274 if "result_type" in params:
1267 params["type"] = params["result_type"] 1275 params["type"] = params["result_type"]
diff --git a/tests/cassettes/test_search.yaml b/tests/cassettes/test_search.yaml
index 56453b3..bbb88f0 100644
--- a/tests/cassettes/test_search.yaml
+++ b/tests/cassettes/test_search.yaml
@@ -8,9 +8,9 @@ interactions:
8 Connection: [keep-alive] 8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.18.4] 9 User-Agent: [python-requests/2.18.4]
10 method: GET 10 method: GET
11 uri: http://localhost:3000/api/v2/search?resolve=1&q=mastodonpy_test 11 uri: http://localhost:3000/api/v2/search?exclude_unreviewed=1&resolve=1&q=mastodonpy_test
12 response: 12 response:
13 body: {string: '{"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","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,"last_status_at":"2019-10-11T21:49:22.805Z","emojis":[],"fields":[]},{"id":"1234567890123457","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":true,"bot":false,"created_at":"2019-06-22T23:11:52.445Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test_2","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":0,"last_status_at":null,"emojis":[],"fields":[]}],"statuses":[],"hashtags":[]}'} 13 body: {string: '{"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","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":1,"statuses_count":2,"last_status_at":"2019-10-11T21:50:54.637Z","emojis":[],"fields":[]},{"id":"1234567890123457","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":true,"bot":false,"created_at":"2019-06-22T23:11:52.445Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test_2","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":0,"last_status_at":null,"emojis":[],"fields":[]}],"statuses":[],"hashtags":[]}'}
14 headers: 14 headers:
15 Cache-Control: ['no-cache, no-store'] 15 Cache-Control: ['no-cache, no-store']
16 Content-Type: [application/json; charset=utf-8] 16 Content-Type: [application/json; charset=utf-8]
@@ -21,8 +21,8 @@ interactions:
21 X-Download-Options: [noopen] 21 X-Download-Options: [noopen]
22 X-Frame-Options: [SAMEORIGIN] 22 X-Frame-Options: [SAMEORIGIN]
23 X-Permitted-Cross-Domain-Policies: [none] 23 X-Permitted-Cross-Domain-Policies: [none]
24 X-Request-Id: [4ed49a56-2ee0-489c-822a-135ba9c9203e] 24 X-Request-Id: [e3981344-186b-487f-9ac5-1195c31679c7]
25 X-Runtime: ['0.028978'] 25 X-Runtime: ['0.031916']
26 X-XSS-Protection: [1; mode=block] 26 X-XSS-Protection: [1; mode=block]
27 content-length: ['1251'] 27 content-length: ['1251']
28 status: {code: 200, message: OK} 28 status: {code: 200, message: OK}
@@ -35,9 +35,9 @@ interactions:
35 Connection: [keep-alive] 35 Connection: [keep-alive]
36 User-Agent: [python-requests/2.18.4] 36 User-Agent: [python-requests/2.18.4]
37 method: GET 37 method: GET
38 uri: http://localhost:3000/api/v2/search?resolve=1&q=mastodonpy_test 38 uri: http://localhost:3000/api/v2/search?exclude_unreviewed=1&resolve=1&q=mastodonpy_test
39 response: 39 response:
40 body: {string: '{"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","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,"last_status_at":"2019-10-11T21:49:22.805Z","emojis":[],"fields":[]},{"id":"1234567890123457","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":true,"bot":false,"created_at":"2019-06-22T23:11:52.445Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test_2","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":0,"last_status_at":null,"emojis":[],"fields":[]}],"statuses":[],"hashtags":[]}'} 40 body: {string: '{"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","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":1,"statuses_count":2,"last_status_at":"2019-10-11T21:50:54.637Z","emojis":[],"fields":[]},{"id":"1234567890123457","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":true,"bot":false,"created_at":"2019-06-22T23:11:52.445Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test_2","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":0,"last_status_at":null,"emojis":[],"fields":[]}],"statuses":[],"hashtags":[]}'}
41 headers: 41 headers:
42 Cache-Control: ['no-cache, no-store'] 42 Cache-Control: ['no-cache, no-store']
43 Content-Type: [application/json; charset=utf-8] 43 Content-Type: [application/json; charset=utf-8]
@@ -48,8 +48,8 @@ interactions:
48 X-Download-Options: [noopen] 48 X-Download-Options: [noopen]
49 X-Frame-Options: [SAMEORIGIN] 49 X-Frame-Options: [SAMEORIGIN]
50 X-Permitted-Cross-Domain-Policies: [none] 50 X-Permitted-Cross-Domain-Policies: [none]
51 X-Request-Id: [b9c4a547-27f6-4b55-9830-73a4e65d55da] 51 X-Request-Id: [5e62a49c-ac34-4759-8265-ffee054f1ca2]
52 X-Runtime: ['0.026422'] 52 X-Runtime: ['0.024392']
53 X-XSS-Protection: [1; mode=block] 53 X-XSS-Protection: [1; mode=block]
54 content-length: ['1251'] 54 content-length: ['1251']
55 status: {code: 200, message: OK} 55 status: {code: 200, message: OK}
@@ -62,7 +62,7 @@ interactions:
62 Connection: [keep-alive] 62 Connection: [keep-alive]
63 User-Agent: [python-requests/2.18.4] 63 User-Agent: [python-requests/2.18.4]
64 method: GET 64 method: GET
65 uri: http://localhost:3000/api/v2/search?resolve=1&q=mastodonpy_test&type=statuses 65 uri: http://localhost:3000/api/v2/search?exclude_unreviewed=1&resolve=1&q=mastodonpy_test&type=statuses
66 response: 66 response:
67 body: {string: '{"accounts":[],"statuses":[],"hashtags":[]}'} 67 body: {string: '{"accounts":[],"statuses":[],"hashtags":[]}'}
68 headers: 68 headers:
@@ -75,8 +75,8 @@ interactions:
75 X-Download-Options: [noopen] 75 X-Download-Options: [noopen]
76 X-Frame-Options: [SAMEORIGIN] 76 X-Frame-Options: [SAMEORIGIN]
77 X-Permitted-Cross-Domain-Policies: [none] 77 X-Permitted-Cross-Domain-Policies: [none]
78 X-Request-Id: [bea1135c-ef57-4e75-bbeb-c472c77273b6] 78 X-Request-Id: [10deaa1f-2a07-40d0-ab06-cbd50df93eb7]
79 X-Runtime: ['0.016913'] 79 X-Runtime: ['0.017407']
80 X-XSS-Protection: [1; mode=block] 80 X-XSS-Protection: [1; mode=block]
81 content-length: ['43'] 81 content-length: ['43']
82 status: {code: 200, message: OK} 82 status: {code: 200, message: OK}
diff --git a/tests/test_search.py b/tests/test_search.py
index a8ab33a..19d2ad4 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -15,6 +15,9 @@ def test_search(api):
15 assert len(results["accounts"]) == 0 15 assert len(results["accounts"]) == 0
16 16
17def test_search_pre_2_9_2(api): 17def test_search_pre_2_9_2(api):
18 api.mastodon_major = 2
19 api.mastodon_minor = 9
20 api.mastodon_patch = 1
18 with vcr.use_cassette('test_search.yaml', cassette_library_dir='tests/cassettes_pre_2_9_2', record_mode='none'): 21 with vcr.use_cassette('test_search.yaml', cassette_library_dir='tests/cassettes_pre_2_9_2', record_mode='none'):
19 results = api.search_v1('mastodonpy_test') 22 results = api.search_v1('mastodonpy_test')
20 assert isinstance(results, dict) 23 assert isinstance(results, dict)
Powered by cgit v1.2.3 (git 2.41.0)