aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastodon/Mastodon.py69
-rw-r--r--tests/test_bookmarks.py4
-rw-r--r--tests/test_constructor.py6
-rw-r--r--tests/test_filters.py14
-rw-r--r--tests/test_instance.py2
-rw-r--r--tests/test_media.py2
-rw-r--r--tests/test_push.py16
-rw-r--r--tests/test_streaming.py8
-rw-r--r--tests/test_timeline.py4
9 files changed, 61 insertions, 64 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index bbd06be..72eb727 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -632,7 +632,7 @@ class Mastodon:
632 self.__logged_in_id = None 632 self.__logged_in_id = None
633 633
634 # Retry version check if needed (might be required in limited federation mode) 634 # Retry version check if needed (might be required in limited federation mode)
635 if self.version_check_worked == False: 635 if not self.version_check_worked:
636 self.retrieve_mastodon_version() 636 self.retrieve_mastodon_version()
637 637
638 return response['access_token'] 638 return response['access_token']
@@ -698,7 +698,7 @@ class Mastodon:
698 params['client_id'] = self.client_id 698 params['client_id'] = self.client_id
699 params['client_secret'] = self.client_secret 699 params['client_secret'] = self.client_secret
700 700
701 if agreement == False: 701 if not agreement:
702 del params['agreement'] 702 del params['agreement']
703 703
704 # Step 1: Get a user-free token via oauth 704 # Step 1: Get a user-free token via oauth
@@ -876,13 +876,13 @@ class Mastodon:
876 876
877 params_initial = locals() 877 params_initial = locals()
878 878
879 if local == False: 879 if not local:
880 del params_initial['local'] 880 del params_initial['local']
881 881
882 if remote == False: 882 if not remote:
883 del params_initial['remote'] 883 del params_initial['remote']
884 884
885 if only_media == False: 885 if not only_media:
886 del params_initial['only_media'] 886 del params_initial['only_media']
887 887
888 if timeline == "local": 888 if timeline == "local":
@@ -1188,13 +1188,13 @@ class Mastodon:
1188 since_id = self.__unpack_id(since_id, dateconv=True) 1188 since_id = self.__unpack_id(since_id, dateconv=True)
1189 1189
1190 params = self.__generate_params(locals(), ['id']) 1190 params = self.__generate_params(locals(), ['id'])
1191 if pinned == False: 1191 if not pinned:
1192 del params["pinned"] 1192 del params["pinned"]
1193 if only_media == False: 1193 if not only_media:
1194 del params["only_media"] 1194 del params["only_media"]
1195 if exclude_replies == False: 1195 if not exclude_replies:
1196 del params["exclude_replies"] 1196 del params["exclude_replies"]
1197 if exclude_reblogs == False: 1197 if not exclude_reblogs:
1198 del params["exclude_reblogs"] 1198 del params["exclude_reblogs"]
1199 1199
1200 url = '/api/v1/accounts/{0}/statuses'.format(str(id)) 1200 url = '/api/v1/accounts/{0}/statuses'.format(str(id))
@@ -1359,7 +1359,7 @@ class Mastodon:
1359 continue 1359 continue
1360 1360
1361 filter_string = re.escape(keyword_filter["phrase"]) 1361 filter_string = re.escape(keyword_filter["phrase"])
1362 if keyword_filter["whole_word"] == True: 1362 if keyword_filter["whole_word"]:
1363 filter_string = "\\b" + filter_string + "\\b" 1363 filter_string = "\\b" + filter_string + "\\b"
1364 filter_strings.append(filter_string) 1364 filter_strings.append(filter_string)
1365 filter_re = re.compile("|".join(filter_strings), flags=re.IGNORECASE) 1365 filter_re = re.compile("|".join(filter_strings), flags=re.IGNORECASE)
@@ -1426,7 +1426,7 @@ class Mastodon:
1426 for search that are available only starting with 2.8.0 are specified. 1426 for search that are available only starting with 2.8.0 are specified.
1427 """ 1427 """
1428 if any(item is not None for item in (account_id, offset, min_id, max_id)): 1428 if any(item is not None for item in (account_id, offset, min_id, max_id)):
1429 if self.verify_minimum_version("2.8.0", cached=True) == False: 1429 if not self.verify_minimum_version("2.8.0", cached=True):
1430 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+") 1430 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+")
1431 1431
1432 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT) 1432 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT)
@@ -1455,7 +1455,7 @@ class Mastodon:
1455 1455
1456 Returns a `search result dict`_, with tags as `hashtag dicts`_. 1456 Returns a `search result dict`_, with tags as `hashtag dicts`_.
1457 """ 1457 """
1458 if self.verify_minimum_version("2.4.1", cached=True) == True: 1458 if self.verify_minimum_version("2.4.1", cached=True):
1459 return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id) 1459 return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id)
1460 else: 1460 else:
1461 self.__ensure_search_params_acceptable( 1461 self.__ensure_search_params_acceptable(
@@ -1471,7 +1471,7 @@ class Mastodon:
1471 Returns a `search result dict`_. 1471 Returns a `search result dict`_.
1472 """ 1472 """
1473 params = self.__generate_params(locals()) 1473 params = self.__generate_params(locals())
1474 if resolve == False: 1474 if not resolve:
1475 del params['resolve'] 1475 del params['resolve']
1476 return self.__api_request('GET', '/api/v1/search', params) 1476 return self.__api_request('GET', '/api/v1/search', params)
1477 1477
@@ -1489,10 +1489,10 @@ class Mastodon:
1489 account_id, offset, min_id, max_id) 1489 account_id, offset, min_id, max_id)
1490 params = self.__generate_params(locals()) 1490 params = self.__generate_params(locals())
1491 1491
1492 if resolve == False: 1492 if not resolve:
1493 del params["resolve"] 1493 del params["resolve"]
1494 1494
1495 if exclude_unreviewed == False or not self.verify_minimum_version("3.0.0", cached=True): 1495 if not exclude_unreviewed or not self.verify_minimum_version("3.0.0", cached=True):
1496 del params["exclude_unreviewed"] 1496 del params["exclude_unreviewed"]
1497 1497
1498 if "result_type" in params: 1498 if "result_type" in params:
@@ -2587,7 +2587,7 @@ class Mastodon:
2587 status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) 2587 status_ids = list(map(lambda x: self.__unpack_id(x), status_ids))
2588 2588
2589 params_initial = locals() 2589 params_initial = locals()
2590 if forward == False: 2590 if not forward:
2591 del params_initial['forward'] 2591 del params_initial['forward']
2592 2592
2593 params = self.__generate_params(params_initial) 2593 params = self.__generate_params(params_initial)
@@ -2953,7 +2953,7 @@ class Mastodon:
2953 params = self.__generate_params( 2953 params = self.__generate_params(
2954 locals(), ['remote', 'status', 'staff_only']) 2954 locals(), ['remote', 'status', 'staff_only'])
2955 2955
2956 if remote == True: 2956 if remote:
2957 params["remote"] = True 2957 params["remote"] = True
2958 2958
2959 mod_statuses = ["active", "pending", 2959 mod_statuses = ["active", "pending",
@@ -2961,7 +2961,7 @@ class Mastodon:
2961 if not status in mod_statuses: 2961 if not status in mod_statuses:
2962 raise ValueError("Invalid moderation status requested.") 2962 raise ValueError("Invalid moderation status requested.")
2963 2963
2964 if staff_only == True: 2964 if staff_only:
2965 params["staff"] = True 2965 params["staff"] = True
2966 2966
2967 for mod_status in mod_statuses: 2967 for mod_status in mod_statuses:
@@ -3073,7 +3073,7 @@ class Mastodon:
3073 if action is None: 3073 if action is None:
3074 action = "none" 3074 action = "none"
3075 3075
3076 if send_email_notification == False: 3076 if not send_email_notification:
3077 send_email_notification = None 3077 send_email_notification = None
3078 3078
3079 id = self.__unpack_id(id) 3079 id = self.__unpack_id(id)
@@ -3112,7 +3112,7 @@ class Mastodon:
3112 if target_account_id is not None: 3112 if target_account_id is not None:
3113 target_account_id = self.__unpack_id(target_account_id) 3113 target_account_id = self.__unpack_id(target_account_id)
3114 3114
3115 if resolved == False: 3115 if not resolved:
3116 resolved = None 3116 resolved = None
3117 3117
3118 params = self.__generate_params(locals()) 3118 params = self.__generate_params(locals())
@@ -3269,12 +3269,12 @@ class Mastodon:
3269 # Figure out what size to decode to 3269 # Figure out what size to decode to
3270 decode_components_x, decode_components_y = blurhash.components( 3270 decode_components_x, decode_components_y = blurhash.components(
3271 media_dict["blurhash"]) 3271 media_dict["blurhash"])
3272 if size_per_component == False: 3272 if size_per_component:
3273 decode_size_x = out_size[0]
3274 decode_size_y = out_size[1]
3275 else:
3276 decode_size_x = decode_components_x * out_size[0] 3273 decode_size_x = decode_components_x * out_size[0]
3277 decode_size_y = decode_components_y * out_size[1] 3274 decode_size_y = decode_components_y * out_size[1]
3275 else:
3276 decode_size_x = out_size[0]
3277 decode_size_y = out_size[1]
3278 3278
3279 # Decode 3279 # Decode
3280 decoded_image = blurhash.decode( 3280 decoded_image = blurhash.decode(
@@ -3584,13 +3584,12 @@ class Mastodon:
3584 response_object = None 3584 response_object = None
3585 try: 3585 try:
3586 kwargs = dict(headers=headers, files=files, timeout=self.request_timeout) 3586 kwargs = dict(headers=headers, files=files, timeout=self.request_timeout)
3587 if use_json == False: 3587 if use_json:
3588 if method == 'GET':
3589 kwargs['params'] = params
3590 else:
3591 kwargs['data'] = params
3592 else:
3593 kwargs['json'] = params 3588 kwargs['json'] = params
3589 elif method == 'GET':
3590 kwargs['params'] = params
3591 else:
3592 kwargs['data'] = params
3594 3593
3595 # Block list with exactly three entries, matching on hashes of the instance API domain 3594 # Block list with exactly three entries, matching on hashes of the instance API domain
3596 # For more information, have a look at the docs 3595 # For more information, have a look at the docs
@@ -3679,7 +3678,7 @@ class Mastodon:
3679 request_complete = False 3678 request_complete = False
3680 continue 3679 continue
3681 3680
3682 if skip_error_check == False: 3681 if not skip_error_check:
3683 if response_object.status_code == 404: 3682 if response_object.status_code == 404:
3684 ex_type = MastodonNotFoundError 3683 ex_type = MastodonNotFoundError
3685 if not error_msg: 3684 if not error_msg:
@@ -3708,7 +3707,7 @@ class Mastodon:
3708 if return_response_object: 3707 if return_response_object:
3709 return response_object 3708 return response_object
3710 3709
3711 if parse == True: 3710 if parse:
3712 try: 3711 try:
3713 response = response_object.json( 3712 response = response_object.json(
3714 object_hook=self.__json_hooks) 3713 object_hook=self.__json_hooks)
@@ -3968,10 +3967,8 @@ class Mastodon:
3968 3967
3969 param_keys = list(params.keys()) 3968 param_keys = list(params.keys())
3970 for key in param_keys: 3969 for key in param_keys:
3971 if isinstance(params[key], bool) and params[key] == False: 3970 if isinstance(params[key], bool):
3972 params[key] = '0' 3971 params[key] = '1' if params[key] else '0'
3973 if isinstance(params[key], bool) and params[key] == True:
3974 params[key] = '1'
3975 3972
3976 for key in param_keys: 3973 for key in param_keys:
3977 if params[key] is None or key in exclude: 3974 if params[key] is None or key in exclude:
diff --git a/tests/test_bookmarks.py b/tests/test_bookmarks.py
index 2e1261b..54134e9 100644
--- a/tests/test_bookmarks.py
+++ b/tests/test_bookmarks.py
@@ -4,7 +4,7 @@ import pytest
4def test_bookmarks(api, status): 4def test_bookmarks(api, status):
5 status_bookmarked = api.status_bookmark(status) 5 status_bookmarked = api.status_bookmark(status)
6 assert status_bookmarked 6 assert status_bookmarked
7 assert status_bookmarked.bookmarked == True 7 assert status_bookmarked.bookmarked
8 8
9 bookmarked_statuses = api.bookmarks() 9 bookmarked_statuses = api.bookmarks()
10 assert bookmarked_statuses 10 assert bookmarked_statuses
@@ -18,7 +18,7 @@ def test_bookmarks(api, status):
18 18
19 status_unbookmarked = api.status_unbookmark(status_bookmarked) 19 status_unbookmarked = api.status_unbookmark(status_bookmarked)
20 assert status_unbookmarked 20 assert status_unbookmarked
21 assert status_unbookmarked.bookmarked == False 21 assert not status_unbookmarked.bookmarked
22 22
23 bookmarked_statuses_2 = api.bookmarks() 23 bookmarked_statuses_2 = api.bookmarks()
24 assert bookmarked_statuses_2 is not None 24 assert bookmarked_statuses_2 is not None
diff --git a/tests/test_constructor.py b/tests/test_constructor.py
index ebc9b85..d997a5d 100644
--- a/tests/test_constructor.py
+++ b/tests/test_constructor.py
@@ -33,9 +33,9 @@ def test_constructor_missing_client_secret():
33 33
34@pytest.mark.vcr() 34@pytest.mark.vcr()
35def test_verify_version(api): 35def test_verify_version(api):
36 assert api.verify_minimum_version("2.3.3") == True 36 assert api.verify_minimum_version("2.3.3") is True
37 assert api.verify_minimum_version("9999.9999.9999") == False 37 assert api.verify_minimum_version("9999.9999.9999") is False
38 assert api.verify_minimum_version("1.0.0") == True 38 assert api.verify_minimum_version("1.0.0") is True
39 39
40def test_supported_version(api): 40def test_supported_version(api):
41 assert Mastodon.get_supported_version() \ No newline at end of file 41 assert Mastodon.get_supported_version() \ No newline at end of file
diff --git a/tests/test_filters.py b/tests/test_filters.py
index 3ffa726..d3dab8d 100644
--- a/tests/test_filters.py
+++ b/tests/test_filters.py
@@ -7,12 +7,12 @@ def test_filter_create(api):
7 with vcr.use_cassette('test_filter_create.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'): 7 with vcr.use_cassette('test_filter_create.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
8 keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = True, expires_in = None) 8 keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = True, expires_in = None)
9 try: 9 try:
10 assert(keyword_filter) 10 assert keyword_filter
11 11
12 all_filters = api.filters() 12 all_filters = api.filters()
13 assert(keyword_filter in all_filters) 13 assert keyword_filter in all_filters
14 assert(keyword_filter.irreversible == False) 14 assert keyword_filter.irreversible is False
15 assert(keyword_filter.whole_word == True) 15 assert keyword_filter.whole_word is True
16 16
17 keyword_filter_2 = api.filter(keyword_filter.id) 17 keyword_filter_2 = api.filter(keyword_filter.id)
18 assert(keyword_filter == keyword_filter_2) 18 assert(keyword_filter == keyword_filter_2)
@@ -22,9 +22,9 @@ def test_filter_create(api):
22 22
23 keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = False, expires_in = None) 23 keyword_filter = api.filter_create("anime", ['notifications'], irreversible = False, whole_word = False, expires_in = None)
24 try: 24 try:
25 assert(keyword_filter) 25 assert keyword_filter
26 assert(keyword_filter.irreversible == False) 26 assert keyword_filter.irreversible is False
27 assert(keyword_filter.whole_word == False) 27 assert keyword_filter.whole_word is False
28 28
29 all_filters = api.filters() 29 all_filters = api.filters()
30 assert(keyword_filter in all_filters) 30 assert(keyword_filter in all_filters)
diff --git a/tests/test_instance.py b/tests/test_instance.py
index 8f3f142..1fbd692 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -38,7 +38,7 @@ def test_emoji(api):
38 38
39@pytest.mark.vcr() 39@pytest.mark.vcr()
40def test_health(api): 40def test_health(api):
41 assert api.instance_health() == True 41 assert api.instance_health() is True
42 42
43@pytest.mark.vcr() 43@pytest.mark.vcr()
44def test_server_time(api): 44def test_server_time(api):
diff --git a/tests/test_media.py b/tests/test_media.py
index 9668f59..e16fb4d 100644
--- a/tests/test_media.py
+++ b/tests/test_media.py
@@ -21,7 +21,7 @@ def test_media_post_v1(api):
21 assert status 21 assert status
22 22
23 try: 23 try:
24 assert status['sensitive'] == False 24 assert status['sensitive'] is False
25 assert status['media_attachments'] 25 assert status['media_attachments']
26 assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk" 26 assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk"
27 assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5 27 assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
diff --git a/tests/test_push.py b/tests/test_push.py
index daa99c7..b815910 100644
--- a/tests/test_push.py
+++ b/tests/test_push.py
@@ -57,14 +57,14 @@ def test_push_update(api):
57 print(sub3) 57 print(sub3)
58 print(api.push_subscription()) 58 print(api.push_subscription())
59 59
60 assert sub3.alerts.follow == False 60 assert sub3.alerts.follow is False
61 assert sub3.alerts.favourite == False 61 assert sub3.alerts.favourite is False
62 assert sub3.alerts.reblog == False 62 assert sub3.alerts.reblog is False
63 assert sub3.alerts.mention == False 63 assert sub3.alerts.mention is False
64 assert sub2.alerts.follow == True 64 assert sub2.alerts.follow is True
65 assert sub2.alerts.favourite == True 65 assert sub2.alerts.favourite is True
66 assert sub2.alerts.reblog == True 66 assert sub2.alerts.reblog is True
67 assert sub2.alerts.mention == True 67 assert sub2.alerts.mention is True
68 68
69 69
70@pytest.mark.vcr(match_on=['path']) 70@pytest.mark.vcr(match_on=['path'])
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index fb60fe1..53a71ee 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -20,7 +20,7 @@ close_connections = False
20def patch_streaming(): 20def patch_streaming():
21 global streaming_is_patched 21 global streaming_is_patched
22 global close_connections 22 global close_connections
23 if streaming_is_patched == True: 23 if streaming_is_patched is True:
24 return 24 return
25 streaming_is_patched = True 25 streaming_is_patched = True
26 26
@@ -35,7 +35,7 @@ def patch_streaming():
35 response = real_connection_real_get_response(*args, **kwargs) 35 response = real_connection_real_get_response(*args, **kwargs)
36 real_body = b"" 36 real_body = b""
37 try: 37 try:
38 while close_connections == False: 38 while close_connections is False:
39 if len(select.select([response], [], [], 0.01)[0]) > 0: 39 if len(select.select([response], [], [], 0.01)[0]) > 0:
40 chunk = response.read(1) 40 chunk = response.read(1)
41 real_body += chunk 41 real_body += chunk
@@ -165,7 +165,7 @@ def test_unknown_event():
165 'data: {}', 165 'data: {}',
166 '', 166 '',
167 ]) 167 ])
168 assert listener.bla_called == True 168 assert listener.bla_called is True
169 assert listener.updates == [] 169 assert listener.updates == []
170 assert listener.notifications == [] 170 assert listener.notifications == []
171 assert listener.deletes == [] 171 assert listener.deletes == []
@@ -195,7 +195,7 @@ def test_dotted_unknown_event():
195 'data: {}', 195 'data: {}',
196 '', 196 '',
197 ]) 197 ])
198 assert listener.do_something_called == True 198 assert listener.do_something_called is True
199 assert listener.updates == [] 199 assert listener.updates == []
200 assert listener.notifications == [] 200 assert listener.notifications == []
201 assert listener.deletes == [] 201 assert listener.deletes == []
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index bc6728f..239fac3 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -60,8 +60,8 @@ def test_conversations(api, api2):
60 assert conversations 60 assert conversations
61 assert status.id in map(lambda x: x.last_status.id, conversations) 61 assert status.id in map(lambda x: x.last_status.id, conversations)
62 assert account.id in map(lambda x: x.accounts[0].id, conversations) 62 assert account.id in map(lambda x: x.accounts[0].id, conversations)
63 assert conversations[0].unread == True 63 assert conversations[0].unread is True
64 assert conversations2[0].unread == False 64 assert conversations2[0].unread is False
65 65
66@pytest.mark.vcr() 66@pytest.mark.vcr()
67def test_min_max_id(api, status): 67def test_min_max_id(api, status):
Powered by cgit v1.2.3 (git 2.41.0)