Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Dec 19, 2016
1 parent 62d101d commit 4560f53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
10 changes: 5 additions & 5 deletions flask_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# any option to define my own json encoder
_pusher.pusher.json = json
except ImportError:
_pusher.json = json

def sign(key, message):
return hmac.new(key, message, hashlib.sha256).hexdigest()
Expand All @@ -35,13 +36,12 @@ class _Pusher(_pusher.Pusher):
Provide backward compatibility to `pusher>=1.6`.
"""
def __getattr__(self, attr):
try:
if hasattr(self, "_pusher_client"):
client = self._pusher_client
except AttributeError:
# call super to raise the original exception
return super(_Pusher, self).__getattr__(attr)
else:
return getattr(client, attr)
else:
# call super to raise the original exception
return getattr(super(_Pusher, self), attr)


class Pusher(object):
Expand Down
25 changes: 19 additions & 6 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def test_flask_json_patch(self):
if _json_encoder_support:
msg = u"Only pusher>=1.0,<1.1 is monkey patched"
self.skipTest(msg)
self.assertEqual(json, _pusher.pusher.json)
try:
self.assertEqual(json, _pusher.pusher.json)
except AttributeError:
self.assertEqual(json, _pusher.json)

def test_configuration(self):
self.app.config["PUSHER_HOST"] = "example.com"
Expand Down Expand Up @@ -102,11 +105,21 @@ def test_all_configurations(self):
pusher = Pusher(self.app)
with self.app.test_request_context():
self.assertIsNotNone(pusher.client)
self.assertFalse(pusher.client.ssl)
self.assertEqual(3, pusher.client.timeout)
self.assertEqual("api-eu.pusher.com", pusher.client.host)
self.assertTrue(backend.called)
self.assertEqual({"anything": True}, backend.call_args[1])

if "ssl" in argspec.args:
self.assertFalse(pusher.client.ssl)

if "timeout" in argspec.args:
self.assertEqual(3, pusher.client.timeout)

if "cluster" in argspec.args:
self.assertEqual("api-eu.pusher.com", pusher.client.host)

if "backend" in argspec.args:
self.assertTrue(backend.called)

if "backend_options" == argspec.keywords:
self.assertEqual({"anything": True}, backend.call_args[1])

def test_pusher_key_in_template(self):
Pusher(self.app)
Expand Down

0 comments on commit 4560f53

Please sign in to comment.