aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-06-05 22:52:18 +0200
committerLorenz Diener <[email protected]>2018-06-05 22:52:18 +0200
commit01e52ccd8fe9dda667e0a7cc1a872a0437a10c8e (patch)
tree4e09dc579d8bdad23cda0a19a45937a8b19f48c4 /mastodon
parent18c6b3b90ff8bd607df18af86d092ac1205ffbf7 (diff)
downloadmastodon.py-01e52ccd8fe9dda667e0a7cc1a872a0437a10c8e.tar.gz
Add push tests
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py59
1 files changed, 37 insertions, 22 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 1830036..a649349 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -70,6 +70,7 @@ def api_version(created_ver, last_changed_ver, return_value_ver):
70 if major > self.mastodon_major: 70 if major > self.mastodon_major:
71 raise MastodonVersionError("Version check failed (Need version " + version + ")") 71 raise MastodonVersionError("Version check failed (Need version " + version + ")")
72 elif major == self.mastodon_major and minor > self.mastodon_minor: 72 elif major == self.mastodon_major and minor > self.mastodon_minor:
73 print(self.mastodon_minor)
73 raise MastodonVersionError("Version check failed (Need version " + version + ")") 74 raise MastodonVersionError("Version check failed (Need version " + version + ")")
74 elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch: 75 elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch:
75 raise MastodonVersionError("Version check failed (Need version " + version + ")") 76 raise MastodonVersionError("Version check failed (Need version " + version + ")")
@@ -1510,9 +1511,9 @@ class Mastodon:
1510 # Writing data: Push subscriptions 1511 # Writing data: Push subscriptions
1511 ### 1512 ###
1512 @api_version("2.4.0", "2.4.0", __DICT_VERSION_PUSH) 1513 @api_version("2.4.0", "2.4.0", __DICT_VERSION_PUSH)
1513 def push_subscription_set(self, endpoint, encrypt_params, follow_events=False, 1514 def push_subscription_set(self, endpoint, encrypt_params, follow_events=None,
1514 favourite_events=False, reblog_events=False, 1515 favourite_events=None, reblog_events=None,
1515 mention_events=False): 1516 mention_events=None):
1516 """ 1517 """
1517 Sets up or modifies the push subscription the logged-in user has for this app. 1518 Sets up or modifies the push subscription the logged-in user has for this app.
1518 1519
@@ -1537,24 +1538,24 @@ class Mastodon:
1537 'subscription[keys][auth]': push_auth_b64 1538 'subscription[keys][auth]': push_auth_b64
1538 } 1539 }
1539 1540
1540 if follow_events == True: 1541 if follow_events != None:
1541 params['data[alerts][follow]'] = True 1542 params['data[alerts][follow]'] = follow_events
1542 1543
1543 if favourite_events == True: 1544 if favourite_events != None:
1544 params['data[alerts][favourite]'] = True 1545 params['data[alerts][favourite]'] = favourite_events
1545 1546
1546 if reblog_events == True: 1547 if reblog_events != None:
1547 params['data[alerts][reblog]'] = True 1548 params['data[alerts][reblog]'] = reblog_events
1548 1549
1549 if mention_events == True: 1550 if mention_events != None:
1550 params['data[alerts][mention]'] = True 1551 params['data[alerts][mention]'] = mention_events
1551 1552
1552 return self.__api_request('POST', '/api/v1/push/subscription', params) 1553 return self.__api_request('POST', '/api/v1/push/subscription', params)
1553 1554
1554 @api_version("2.4.0", "2.4.0", __DICT_VERSION_PUSH) 1555 @api_version("2.4.0", "2.4.0", __DICT_VERSION_PUSH)
1555 def push_subscription_update(self, endpoint, encrypt_params, follow_events=False, 1556 def push_subscription_update(self, follow_events=None,
1556 favourite_events=False, reblog_events=False, 1557 favourite_events=None, reblog_events=None,
1557 mention_events=False): 1558 mention_events=None):
1558 """ 1559 """
1559 Modifies what kind of events the app wishes to subscribe to. 1560 Modifies what kind of events the app wishes to subscribe to.
1560 1561
@@ -1562,17 +1563,17 @@ class Mastodon:
1562 """ 1563 """
1563 params = {} 1564 params = {}
1564 1565
1565 if follow_events == True: 1566 if follow_events != None:
1566 params['data[alerts][follow]'] = True 1567 params['data[alerts][follow]'] = follow_events
1567 1568
1568 if favourite_events == True: 1569 if favourite_events != None:
1569 params['data[alerts][favourite]'] = True 1570 params['data[alerts][favourite]'] = favourite_events
1570 1571
1571 if reblog_events == True: 1572 if reblog_events != None:
1572 params['data[alerts][reblog]'] = True 1573 params['data[alerts][reblog]'] = reblog_events
1573 1574
1574 if mention_events == True: 1575 if mention_events != None:
1575 params['data[alerts][mention]'] = True 1576 params['data[alerts][mention]'] = mention_events
1576 1577
1577 return self.__api_request('PUT', '/api/v1/push/subscription', params) 1578 return self.__api_request('PUT', '/api/v1/push/subscription', params)
1578 1579
@@ -1798,6 +1799,19 @@ class Mastodon:
1798 return json_object 1799 return json_object
1799 1800
1800 @staticmethod 1801 @staticmethod
1802 def __json_truefalse_parse(json_object):
1803 """
1804 Parse 'True' / 'False' strings in certain known fields
1805 """
1806 for key in ('follow', 'favourite', 'reblog', 'mention'):
1807 if (key in json_object and isinstance(json_object[key], six.text_type)):
1808 if json_object[key] == 'True':
1809 json_object[key] = True
1810 if json_object[key] == 'False':
1811 json_object[key] = False
1812 return json_object
1813
1814 @staticmethod
1801 def __json_strnum_to_bignum(json_object): 1815 def __json_strnum_to_bignum(json_object):
1802 """ 1816 """
1803 Converts json string numerals to native python bignums. 1817 Converts json string numerals to native python bignums.
@@ -1815,6 +1829,7 @@ class Mastodon:
1815 def __json_hooks(json_object): 1829 def __json_hooks(json_object):
1816 json_object = Mastodon.__json_strnum_to_bignum(json_object) 1830 json_object = Mastodon.__json_strnum_to_bignum(json_object)
1817 json_object = Mastodon.__json_date_parse(json_object) 1831 json_object = Mastodon.__json_date_parse(json_object)
1832 json_object = Mastodon.__json_truefalse_parse(json_object)
1818 json_object = Mastodon.__json_allow_dict_attrs(json_object) 1833 json_object = Mastodon.__json_allow_dict_attrs(json_object)
1819 return json_object 1834 return json_object
1820 1835
Powered by cgit v1.2.3 (git 2.41.0)