Skip to content

Commit 762e02d

Browse files
committed
Add PushNotifications class with constructor validation
1 parent 9aef568 commit 762e02d

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

pusher_push_notifications/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Pusher Push Notifications Python server SDK"""
2+
3+
import six
4+
5+
6+
class PushNotifications(object):
7+
"""Pusher Push Notifications API client
8+
This client class can be used to publish notifications to the Pusher
9+
Push Notifications service"""
10+
11+
def __init__(self, instance_id, secret_key):
12+
if not isinstance(instance_id, six.string_types):
13+
raise TypeError('instance_id must be a string')
14+
if not isinstance(secret_key, six.string_types):
15+
raise TypeError('secret_key must be a string')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
six==1.10.0

tests/test_example.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/test_push_notifications.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Unit tests for Pusher Push Notifications Python server SDK"""
2+
3+
import unittest
4+
5+
from pusher_push_notifications import PushNotifications
6+
7+
8+
class TestPushNotifications(unittest.TestCase):
9+
def test_constructor_should_accept_valid_params(self):
10+
PushNotifications(
11+
instance_id='1234',
12+
secret_key='1234',
13+
)
14+
15+
def test_constructor_should_fail_if_instance_id_not_string(self):
16+
with self.assertRaises(TypeError):
17+
PushNotifications(
18+
instance_id=False,
19+
secret_key='1234',
20+
)
21+
22+
def test_constructor_should_fail_if_secret_key_not_string(self):
23+
with self.assertRaises(TypeError):
24+
PushNotifications(
25+
instance_id='1234',
26+
secret_key=False,
27+
)

0 commit comments

Comments
 (0)