Skip to content

Commit

Permalink
Added Simplepush. Closed #10 (#15)
Browse files Browse the repository at this point in the history
* Added simplepush provider

* Added tests

* Updated readme

* Added negative test

* Revert "Added negative test"

This reverts commit 811d96f
  • Loading branch information
liiight authored Aug 28, 2017
1 parent c6caec3 commit 7dd3958
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ env:
- secure: "eKxRf8pUHoCOx1ror0VQuQ53BIR0fM0QeeYobANJjlKQNsnbY80VWilWN0Bn1532ObqynTlBUqlq8jJge4ho3emz01BBAvSDddg4/037EoP64vpNzEWxxorR8jop8rfDpbh3917Gqd8NzAOf8v4PkVJq+wB3c0DV/BE/SV6v5cdnsTa8GAJM6zQpj2Sg2kgGHoAaT37npD5q4zKTqpJT1WgAht9RJ3Od10aBT8QABz+wpUVLxg9FnthmznbgO9seeZhctTGuCSj1TAz/XQjJD8fS8XiEjhwAoTmJec58Zqk6pjhEnWV9L91Z9s4ICyN2+tnrjOSl5apo98nRZ8yappSwilLCjQ4VhlSdOCwLv/LjN2HT+XTQS/W068wuEtSkbLMoV2eE87wD86iiiIBMax9I5Kw69xYZk7kNQYzxlrBYk9lj3vlrI8YwXBnHdaIWyZlWgNSQy9vsk2ZIxSBLdeKj+z2DNBqJ3UMn636oncgPvphZBhmrbeSBS5jcc2hwdCGtcbWvRNKmKcP8xa02Nfv1zCTSW2T3IdI7XfTEX7WUwEMy1heuCgTXdm4XBT3Uemte4AOKVKgamT/6bchlo+tFBQSK6ot841GMPYftVNTjcLUlJYr5mUJkotRY6uQK/vvpBWI4eAWM58GwidG5Oi3whZiAGKl8Xv0M1SXlAuI="
# Pushover token
- secure: "i0/6+uzOG63I119PodRGXlB7edSIsNfQo5C9F/WGS45hVzdPCTfxn8pCzpd9lEaYQU5SGxp7ZdkjGfx0DjrQPxk5M352eLi1eWvEQn+S7628j//mZtYnfWk/716uKThfLP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YXB+ecOoSHrKi00/NGQ3RB3DIXqUiSvJ+008Li07NIZkvD6L/3/FCniUExZVyLzLhppmJojwmxg/Z/xPQT9zS3yYD+q2U/DEe3CsdhuvD1Rk9BZfH+DwsiN+fF9sK2kMn4EW0DtWtPyy8hDQKnXqIqv3fiPBDjZEFyhz9SQg="
script: pytest --cov=./
after_success:
codecov
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Supported providers
-------------------

- `Pushover <https://pushover.net/>`_
- `Simplepush <https://simplepush.io/>`_

In the near future
------------------
Expand Down
5 changes: 3 additions & 2 deletions notifiers/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import pushover
from . import pushover, simplepush

_all_providers = {
'pushover': pushover.Pushover
'pushover': pushover.Pushover,
'simplepush': simplepush.SimplePush
}
48 changes: 48 additions & 0 deletions notifiers/providers/simplepush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import requests

from ..core import Provider, Response


class SimplePush(Provider):
base_url = 'https://api.simplepush.io/send'
site_url = 'https://simplepush.io/'
provider_name = 'simplepush'

@property
def schema(self):
return {
'type': 'object',
'properties': {
'key': {'type': 'string',
'title': 'your user key'},
'message': {'type': 'string',
'title': 'your message'},
},
'required': ['key', 'message'],
'additionalProperties': False
}

def _prepare_data(self, data: dict):
data['msg'] = data.pop('message')
return data

def _send_notification(self, data):
status = 'Success'
errors = []
response = None
try:
response = requests.post(self.base_url, data=data)
response.raise_for_status()
except requests.RequestException as e:
status = 'Failure'
if e.response is not None:
response = e.response
errors = [response.json()['message']]
else:
errors.append(str(e))
finally:
return Response(status=status,
provider=self.provider_name,
data=data,
response=response,
errors=errors)
36 changes: 36 additions & 0 deletions tests/providers/test_simplepush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from notifiers import get_notifier
from notifiers.exceptions import BadArguments, NotificationError


class TestSimplePush(object):
"""SimplePush notifier tests
Note: These tests assume correct environs set for NOTIFIERS_SIMPLEPUSH_KEY
"""

def test_simplepush_metadata(self):
p = get_notifier('simplepush')
assert p.metadata == {'base_url': 'https://api.simplepush.io/send',
'site_url': 'https://simplepush.io/',
'provider_name': 'simplepush'}

@pytest.mark.parametrize('data, message', [
({}, 'key'),
({'key': 'foo'}, 'message'),
])
def test_simplepush_missing_required(self, data, message):
p = get_notifier('simplepush')
data['env_prefix'] = 'test'
with pytest.raises(BadArguments) as e:
p.notify(**data)
assert f'\'{message}\' is a required property' in e.value.message

@pytest.mark.online
def test_simplepush_sanity(self):
"""Successful simplepush notification"""
p = get_notifier('simplepush')
data = {'message': 'foo'}
rsp = p.notify(**data)
rsp.raise_on_errors()

0 comments on commit 7dd3958

Please sign in to comment.