Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions py_pushover/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ def push_message(self, message, **kwargs):

ret_receipt = False

# determine if client key has already been saved. If not then get argument
client_key = self._user_key
# determine if client key has already been saved. If not then get argument. Group key takes priority
client_key = self._group_key if self._group_key else self._user_key
if 'user' in kwargs:
client_key = kwargs['client']
client_key = kwargs['user']
kwargs.pop('user')

# client key required to push message
if client_key is None:
Expand Down Expand Up @@ -129,7 +130,7 @@ def push_message(token, user, message, **kwargs):
retry_val = kwargs['retry']

# 'retry' val must be a minimum of _MIN_RETRY and max of _MAX_EXPIRE
if _MAX_EXPIRE < retry_val < _MIN_RETRY:
if not (_MIN_RETRY <= retry_val <= _MAX_EXPIRE):
raise ValueError('`retry` argument must be at a minimum of {} and a maximum of {}'.format(
_MIN_RETRY, _MAX_EXPIRE
))
Expand All @@ -141,7 +142,7 @@ def push_message(token, user, message, **kwargs):
expire_val = kwargs['expire']

# 'expire' val must be a minimum of _MIN_RETRY and max of _MAX_EXPIRE
if _MAX_EXPIRE < expire_val < _MIN_RETRY:
if not(_MIN_RETRY < expire_val < _MAX_EXPIRE):
raise ValueError('`expire` argument must be at a minimum of {} and a maximum of {}'.format(
_MIN_RETRY, _MAX_EXPIRE
))
Expand Down
24 changes: 18 additions & 6 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ def setUp(self):
self.valid_pm = py_po.message.MessageManager(app_key, user_key)

def test_val_msg(self):
self.valid_pm.push_message('This should always work')
py_po.message.push_message(app_key, user_key, 'This should always work')
self.valid_pm.push_message('Testing normal push (Manager method)')
py_po.message.push_message(app_key, user_key, 'Testing normal message push (static function)')
val_pm = py_po.message.MessageManager(app_key)
val_pm.push_message('Testing Title and manual user_key', title='Success!', user=user_key)

def test_inv_msg(self):
inv_pm = py_po.message.MessageManager(app_key)
with self.assertRaises(ValueError):
inv_pm.push_message('Missin User Key')

def test_inv_emergency_msg(self):
with self.assertRaises(TypeError):
Expand All @@ -31,16 +38,21 @@ def test_inv_emergency_msg(self):

with self.assertRaises(TypeError):
self.valid_pm.push_message('Emergency', priority=py_po.PRIORITIES.EMERGENCY, expire=3600)
py_po.message.push_message('Emergency', priority=py_po.PRIORITIES.EMERGENCY, expire=3600)
py_po.message.push_message(app_key, user_key, 'Emergency', priority=py_po.PRIORITIES.EMERGENCY, expire=3600)

with self.assertRaises(ValueError):
self.valid_pm.push_message('Invalid expire', priority=py_po.PRIORITIES.EMERGENCY, expire=86500, retry=30)
py_po.message.push_message(app_key, user_key, 'Invalid retry', expire=3600, retry=20)

def test_val_emergency_msg(self):
def test_emergency_msg(self):
res = self.valid_pm.push_message("Emergency", priority=py_po.PRIORITIES.EMERGENCY, retry=30, expire=3600)
time.sleep(0.5)
self.valid_pm.check_receipt(res['receipt'])
self.assertEqual(self.valid_pm.check_receipt()['status'], 1)
self.assertEqual(self.valid_pm.check_receipt(res['receipt'])['status'], 1)
self.valid_pm.cancel_retries(res['receipt'])
res = py_po.message.push_message(app_key, user_key, 'Emergency', priority=py_po.PRIORITIES.EMERGENCY, retry=30, expire=3600)
time.sleep(0.5)
py_po.message.check_receipt(app_key, res['receipt'])
self.assertEqual(py_po.message.check_receipt(app_key, res['receipt'])['status'], 1)
py_po.message.cancel_retries(app_key, res['receipt'])


Expand Down