From 4560f53103b51133aba527c54c4f001627fba55b Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Mon, 19 Dec 2016 10:46:58 -0200 Subject: [PATCH] Fix tests. --- flask_pusher.py | 10 +++++----- tests.py | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/flask_pusher.py b/flask_pusher.py index ab9d58e..d491ad9 100644 --- a/flask_pusher.py +++ b/flask_pusher.py @@ -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() @@ -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): diff --git a/tests.py b/tests.py index 4998afa..b710c19 100644 --- a/tests.py +++ b/tests.py @@ -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" @@ -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)