Skip to content

Commit cf57d23

Browse files
Merge pull request #8 from pusher/empty-string
Fail if instance_id/secret_key is empty
2 parents a2caffe + 556e027 commit cf57d23

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pusher_push_notifications/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ class PushNotifications(object):
5858
def __init__(self, instance_id, secret_key, endpoint=None):
5959
if not isinstance(instance_id, six.string_types):
6060
raise TypeError('instance_id must be a string')
61+
if instance_id == '':
62+
raise ValueError('instance_id cannot be the empty string')
63+
6164
if not isinstance(secret_key, six.string_types):
6265
raise TypeError('secret_key must be a string')
66+
if secret_key == '':
67+
raise ValueError('secret_key cannot be the empty string')
68+
6369
if (endpoint is not None
6470
and not isinstance(endpoint, six.string_types)):
6571
raise TypeError('endpoint must be a string')

tests/test_push_notifications.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def test_constructor_should_fail_if_instance_id_not_string(self):
2929
)
3030
self.assertIn('instance_id must be a string', str(e.exception))
3131

32+
def test_constructor_should_fail_if_instance_id_empty_string(self):
33+
with self.assertRaises(ValueError) as e:
34+
PushNotifications(
35+
instance_id='',
36+
secret_key='1234',
37+
)
38+
self.assertIn('instance_id cannot be the empty string', str(e.exception))
39+
3240
def test_constructor_should_fail_if_secret_key_not_string(self):
3341
with self.assertRaises(TypeError) as e:
3442
PushNotifications(
@@ -37,6 +45,14 @@ def test_constructor_should_fail_if_secret_key_not_string(self):
3745
)
3846
self.assertIn('secret_key must be a string', str(e.exception))
3947

48+
def test_constructor_should_fail_if_secret_key_empty_string(self):
49+
with self.assertRaises(ValueError) as e:
50+
PushNotifications(
51+
instance_id='1234',
52+
secret_key='',
53+
)
54+
self.assertIn('secret_key cannot be the empty string', str(e.exception))
55+
4056
def test_constructor_should_fail_if_endpoint_not_string(self):
4157
with self.assertRaises(TypeError) as e:
4258
PushNotifications(

0 commit comments

Comments
 (0)