Skip to content
Closed
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
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev
- "3.5"
- "3.5-dev"
- "3.6"
- "3.6-dev"
- "3.7-dev"
- "nightly"
# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"python.unitTest.pyTestArgs": [
"tests"
],
"python.unitTest.unittestEnabled": false,
"python.unitTest.nosetestsEnabled": false,
"python.unitTest.pyTestEnabled": true,
"python.pythonPath": "/anaconda3/envs/pypo_dev/bin/python"
}
9 changes: 1 addition & 8 deletions pypushover/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ def send(url, data_out=None, get_method=False):
if ret_dict['status'] == 0:
raise PushoverError(ret_dict['errors'])

if 'X-Limit-App-Limit' in res.headers:
ret_dict['app_limit'] = res.headers['X-Limit-App-Limit']
if 'X-Limit-App-Remaining' in res.headers:
ret_dict['app_remaining'] = res.headers['X-Limit-App-Remaining']
if 'X-Limit-App-Reset' in res.headers:
ret_dict['app_reset'] = res.headers['X-Limit-App-Reset']

return ret_dict

except decode_error as e:
except decode_error:
res.raise_for_status()


9 changes: 5 additions & 4 deletions pypushover/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
stored on the Pushover servers are then stored into the `messages` property. These messages are a list of
dictionaries with items as [defined in the Pushover API](https://pushover.net/api/client#download).

>>> cm.retrieve_message()
>>> cm.retrieve_messages()
>>> for msg in cm.messages:
... print(msg['message'])

Expand All @@ -55,7 +55,7 @@
API guidelines](https://pushover.net/api/client#p2). Once the user has acknowledged the message, using the
`acknowledge_message` method passing in the emergency messages `receipt`.

>>> cm.retrieve_message()
>>> cm.retrieve_messages()
>>> for msg in cm.messages:
... print(msg['message'])
... if msg['priority'] == py_po.PRIORITIES.EMERGENCY:
Expand Down Expand Up @@ -166,7 +166,7 @@ def register_device(self, name):
self.__device_id__ = self.latest_response_dict['id']
return self.__device_id__

def retrieve_message(self):
def retrieve_messages(self):
"""
Retrieves messages stored on the Pushover servers and saves them into the `messages` property.
"""
Expand All @@ -189,6 +189,7 @@ def clear_server_messages(self):
}

self.latest_response_dict = send(self._del_message_url.format(device_id=self.__device_id__), params)
self.messages = []

def acknowledge_message(self, receipt):
"""
Expand Down Expand Up @@ -261,7 +262,7 @@ def _on_ws_message(self, ws, message):
pass

elif message == "!":
self.retrieve_message()
self.retrieve_messages()
if self.__on_msg_receipt__:
self.__on_msg_receipt__(self.messages)

Expand Down
17 changes: 12 additions & 5 deletions pypushover/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class _User(object):

This class is generated dynamically based on the response from the Pushover servers.
"""

def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k + '_key' if k == 'user' else k, v)
Expand All @@ -123,6 +124,7 @@ class _Group(object):

This class is generated dynamically based on the response from the Pushover servers.
"""

def __init__(self, **kwargs):
self.users = None
for k, v in kwargs.items():
Expand Down Expand Up @@ -173,7 +175,8 @@ def add_user(self, user, device=None, memo=None):
:return: A dictionary representing the json response.
"""

self.latest_response_dict = add_user(self._app_token, self._group_key, user, device=device, memo=memo)
self.latest_response_dict = add_user(
self._app_token, self._group_key, user, device=device, memo=memo)
self.__update_group()
return self.latest_response_dict

Expand All @@ -184,7 +187,8 @@ def remove_user(self, user):
:return: A dictionary representing the json response.
"""

self.latest_response_dict = remove_user(self._app_token, self._group_key, user)
self.latest_response_dict = remove_user(
self._app_token, self._group_key, user)
self.__update_group()
return self.latest_response_dict

Expand All @@ -195,7 +199,8 @@ def disable_user(self, user):
:return: A dictionary representing the json response.
"""

self.latest_response_dict = disable_user(self._app_token, self._group_key, user)
self.latest_response_dict = disable_user(
self._app_token, self._group_key, user)
self.__update_group()
return self.latest_response_dict

Expand All @@ -206,7 +211,8 @@ def enable_user(self, user):
:return: A dictionary representing the json response.
"""

self.latest_response_dict = enable_user(self._app_token, self._group_key, user)
self.latest_response_dict = enable_user(
self._app_token, self._group_key, user)
self.__update_group()
return self.latest_response_dict

Expand All @@ -217,7 +223,8 @@ def rename(self, name):
:return: A dictionary representing the json response.
"""

self.latest_response_dict = rename(self._app_token, self._group_key, name)
self.latest_response_dict = rename(
self._app_token, self._group_key, name)
self.__update_group()
return self.latest_response_dict

Expand Down
16 changes: 8 additions & 8 deletions pypushover/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

Below is an example:

>>> res = pm.send_message('Emergency Message!', priority=pypo.PRIORITIES.EMERGENCY, retry=30, expire=3600)
>>> res = pm.push_message('Emergency Message!', priority=pypo.PRIORITIES.EMERGENCY, retry=30, expire=3600)
>>> res = pypo.message.push_message(
... '<app_token>',
... '<group/user key>',
Expand Down Expand Up @@ -88,19 +88,19 @@
"""
import time

from pypushover import PRIORITIES, BaseManager, base_url, send
from pypushover import PRIORITIES, BaseManager as _BaseManager, base_url as _base_url, send as _send


_MAX_EXPIRE = 86400
_MIN_RETRY = 30

_push_url = base_url + "messages.json"
_base_receipt_url = base_url + "receipts/{receipt}"
_push_url = _base_url + "messages.json"
_base_receipt_url = _base_url + "receipts/{receipt}"
_receipt_url = _base_receipt_url + ".json"
_cancel_receipt_url = _base_receipt_url + "/cancel.json"


class MessageManager(BaseManager):
class MessageManager(_BaseManager):
"""
Manager class used to send messages and check receipts. Stores the given app_token for future use. Also stores the
latest response from the API.
Expand Down Expand Up @@ -277,7 +277,7 @@ def push_message(token, user, message, **kwargs):
if 'html' in kwargs:
data_out['html'] = int(kwargs['html'])

return send(_push_url, data_out=data_out)
return _send(_push_url, data_out=data_out)


def check_receipt(token, receipt):
Expand All @@ -289,7 +289,7 @@ def check_receipt(token, receipt):
:return:
"""
url_to_send = _receipt_url.format(receipt=receipt)
return send(url_to_send, data_out={'token': token}, get_method=True)
return _send(url_to_send, data_out={'token': token}, get_method=True)


def cancel_retries(token, receipt):
Expand All @@ -301,5 +301,5 @@ def cancel_retries(token, receipt):
:param str receipt: receipt of the message
"""
url_to_send = _cancel_receipt_url.format(receipt=receipt)
return send(url_to_send, data_out={'token': token})
return _send(url_to_send, data_out={'token': token})

4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
requests
coveralls
websocket-client
websocket-client
pytest
mock
22 changes: 17 additions & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import unittest

# The token and user key are taken from the online Pushover docs to help
# make this more real and won't work in real life.
APP_TOKEN = "KzGDORePKggMaC0QOYAMyEEuzJnyUi;"
USER_KEY = "e9e1495ec75826de5983cd1abc8031"

def get_tests():
return full_suite()


def full_suite():
from .runtests import TestBasic, TestClient, TestGroup, TestLicense, TestMessage, TestVerifcation, TestIssues
from .test_Basic import TestBasic
from .test_Client import TestClient
from .test_Groups import TestGroup
from .test_Issues import TestIssues
from .test_Messages import TestMessages
from .test_Verification import TestVerification

return unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(TestBasic),
unittest.TestLoader().loadTestsFromTestCase(TestClient),
# unittest.TestLoader().loadTestsFromTestCase(TestClient),
unittest.TestLoader().loadTestsFromTestCase(TestGroup),
unittest.TestLoader().loadTestsFromTestCase(TestMessage),
unittest.TestLoader().loadTestsFromTestCase(TestVerifcation),
unittest.TestLoader().loadTestsFromTestCase(TestIssues)
unittest.TestLoader().loadTestsFromTestCase(TestMessages),
unittest.TestLoader().loadTestsFromTestCase(TestVerification),
# unittest.TestLoader().loadTestsFromTestCase(TestIssues)
])

if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions tests/helpers/__init__.py

This file was deleted.

31 changes: 31 additions & 0 deletions tests/responses/test_bad_verify_user_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"status_code": 200,
"headers": {
"Server": "nginx",
"Date": "Thu, 01 Nov 2018 16:43:21 GMT",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"X-Frame-Options": "SAMEORIGIN, DENY",
"X-XSS-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, X-Prototype-Version, Origin, Accept, Content-Type, X-CSRF-Token, X-Pushover-App, Authorization",
"Access-Control-Max-Age": "1728000",
"X-Limit-App-Limit": "7500",
"X-Limit-App-Remaining": "7498",
"X-Limit-App-Reset": "1543644000",
"ETag": "W/\"2b287cc51514704e37448855a4c4e855\"",
"Cache-Control": "max-age=0, private, must-revalidate",
"X-Request-Id": "774ad663-d919-4539-b237-e0c589c2a837",
"X-Runtime": "0.040146",
"Strict-Transport-Security": "max-age=31536000"
},
"json": {
"user": "invalid",
"errors": ["user key is invalid"],
"status": 0,
"request": "774ad663-d919-4539-b237-e0c589c2a837"
}
}
29 changes: 29 additions & 0 deletions tests/responses/test_good_cancel_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"status_code": 200,
"headers": {
"Server": "nginx",
"Date": "Thu, 01 Nov 2018 16:43:21 GMT",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"X-Frame-Options": "SAMEORIGIN, DENY",
"X-XSS-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, X-Prototype-Version, Origin, Accept, Content-Type, X-CSRF-Token, X-Pushover-App, Authorization",
"Access-Control-Max-Age": "1728000",
"X-Limit-App-Limit": "7500",
"X-Limit-App-Remaining": "7498",
"X-Limit-App-Reset": "1543644000",
"ETag": "W/\"2b287cc51514704e37448855a4c4e855\"",
"Cache-Control": "max-age=0, private, must-revalidate",
"X-Request-Id": "855cef21-654d-4b4c-8235-824658b464dc",
"X-Runtime": "0.040146",
"Strict-Transport-Security": "max-age=31536000"
},
"json": {
"status": 1,
"request": "855cef21-654d-4b4c-8235-824658b464dc"
}
}
37 changes: 37 additions & 0 deletions tests/responses/test_good_check_receipt_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"status_code": 200,
"headers": {
"Server": "nginx",
"Date": "Thu, 01 Nov 2018 16:43:21 GMT",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"X-Frame-Options": "SAMEORIGIN, DENY",
"X-XSS-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, X-Prototype-Version, Origin, Accept, Content-Type, X-CSRF-Token, X-Pushover-App, Authorization",
"Access-Control-Max-Age": "1728000",
"X-Limit-App-Limit": "7500",
"X-Limit-App-Remaining": "7498",
"X-Limit-App-Reset": "1543644000",
"ETag": "W/\"2b287cc51514704e37448855a4c4e855\"",
"Cache-Control": "max-age=0, private, must-revalidate",
"X-Request-Id": "73d54061-072a-4004-8190-a1991f2df844",
"X-Runtime": "0.040146",
"Strict-Transport-Security": "max-age=31536000"
},
"json": {
"status": 1,
"acknowledged": 1,
"acknowledged_at": 1541103706,
"acknowledged_by": "e9e1495ec75826de5983cd1abc8031",
"acknowledged_by_device": "krono-jpl",
"last_delivered_at": 1541103690,
"expired": 0,
"expires_at": 1541106308,
"called_back": 0,
"called_back_at": 0,
"request": "73d54061-072a-4004-8190-a1991f2df844"}
}
30 changes: 30 additions & 0 deletions tests/responses/test_good_emergency_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"status_code": 200,
"headers": {
"Server": "nginx",
"Date": "Thu, 01 Nov 2018 16:43:21 GMT",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"X-Frame-Options": "SAMEORIGIN, DENY",
"X-XSS-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, X-Prototype-Version, Origin, Accept, Content-Type, X-CSRF-Token, X-Pushover-App, Authorization",
"Access-Control-Max-Age": "1728000",
"X-Limit-App-Limit": "7500",
"X-Limit-App-Remaining": "7498",
"X-Limit-App-Reset": "1543644000",
"ETag": "W/\"2b287cc51514704e37448855a4c4e855\"",
"Cache-Control": "max-age=0, private, must-revalidate",
"X-Request-Id": "cc1cbb0a-f59c-4c20-9191-1578849e7150",
"X-Runtime": "0.040146",
"Strict-Transport-Security": "max-age=31536000"
},
"json": {
"receipt": "rbp115t2ohpuwh27gaa1jqips9y8by",
"status": 1,
"request": "cc1cbb0a-f59c-4c20-9191-1578849e7150"
}
}
Loading