|
22 | 22 |
|
23 | 23 | class TestPusher(unittest.TestCase): |
24 | 24 | def test_initialize_from_url(self): |
25 | | - self.assertRaises(TypeError, lambda: Client.from_url(4)) |
26 | | - self.assertRaises(Exception, lambda: Client.from_url(u'httpsahsutaeh')) |
27 | | - |
28 | | - conf = Client.from_url(u'http://foo:bar@host/apps/4') |
29 | | - self.assertEqual(conf.ssl, False) |
30 | | - self.assertEqual(conf.key, u'foo') |
31 | | - self.assertEqual(conf.secret, u'bar') |
32 | | - self.assertEqual(conf.host, u'host') |
33 | | - self.assertEqual(conf.app_id, u'4') |
34 | | - |
35 | | - conf = Client.from_url(u'https://foo:bar@host/apps/4') |
36 | | - self.assertEqual(conf.ssl, True) |
37 | | - self.assertEqual(conf.key, u'foo') |
38 | | - self.assertEqual(conf.secret, u'bar') |
39 | | - self.assertEqual(conf.host, u'host') |
40 | | - self.assertEqual(conf.app_id, u'4') |
| 25 | + self.assertRaises(TypeError, lambda: Pusher.from_url(4)) |
| 26 | + self.assertRaises(Exception, lambda: Pusher.from_url(u'httpsahsutaeh')) |
| 27 | + |
| 28 | + pusher = Pusher.from_url(u'http://foo:bar@host/apps/4') |
| 29 | + self.assertEqual(pusher._pusher_client.ssl, False) |
| 30 | + self.assertEqual(pusher._pusher_client.key, u'foo') |
| 31 | + self.assertEqual(pusher._pusher_client.secret, u'bar') |
| 32 | + self.assertEqual(pusher._pusher_client.host, u'host') |
| 33 | + self.assertEqual(pusher._pusher_client.app_id, u'4') |
| 34 | + |
| 35 | + pusher = Pusher.from_url(u'https://foo:bar@host/apps/4') |
| 36 | + self.assertEqual(pusher._pusher_client.ssl, True) |
| 37 | + self.assertEqual(pusher._pusher_client.key, u'foo') |
| 38 | + self.assertEqual(pusher._pusher_client.secret, u'bar') |
| 39 | + self.assertEqual(pusher._pusher_client.host, u'host') |
| 40 | + self.assertEqual(pusher._pusher_client.app_id, u'4') |
41 | 41 |
|
42 | 42 | def test_initialize_from_env(self): |
43 | 43 | with mock.patch.object(os, 'environ', new={'PUSHER_URL':'https://plah:bob@somehost/apps/42'}): |
44 | 44 | pusher = Pusher.from_env() |
45 | | - self.assertEqual(pusher.ssl, True) |
46 | | - self.assertEqual(pusher.key, u'plah') |
47 | | - self.assertEqual(pusher.secret, u'bob') |
48 | | - self.assertEqual(pusher.host, u'somehost') |
49 | | - self.assertEqual(pusher.app_id, u'42') |
50 | | - |
51 | | - |
52 | | -class TestJson(unittest.TestCase): |
53 | | - def setUp(self): |
54 | | - class JSONEncoder(json.JSONEncoder): |
55 | | - def default(self, o): |
56 | | - if isinstance(o, Decimal): |
57 | | - return str(o) |
58 | | - return super(JSONEncoder, self).default(o) |
59 | | - |
60 | | - constants = {"NaN": 99999} |
61 | | - |
62 | | - class JSONDecoder(json.JSONDecoder): |
63 | | - def __init__(self, **kwargs): |
64 | | - super(JSONDecoder, self).__init__(parse_constant=constants.__getitem__) |
65 | | - |
66 | | - self.pusher_client = PusherClient.from_url(u'http://key:secret@somehost/apps/4', |
67 | | - json_encoder=JSONEncoder, |
68 | | - json_decoder=JSONDecoder) |
| 45 | + self.assertEqual(pusher._pusher_client.ssl, True) |
| 46 | + self.assertEqual(pusher._pusher_client.key, u'plah') |
| 47 | + self.assertEqual(pusher._pusher_client.secret, u'bob') |
| 48 | + self.assertEqual(pusher._pusher_client.host, u'somehost') |
| 49 | + self.assertEqual(pusher._pusher_client.app_id, u'42') |
69 | 50 |
|
70 | | - def test_custom_json_decoder(self): |
71 | | - t = 1000 * time.time() |
72 | | - body = u'{"nan": NaN, "time_ms": %f}' % t |
73 | | - signature = sign(self.pusher_client.secret, body) |
74 | | - data = self.pusher_client.validate_webhook(self.pusher_client.key, signature, body) |
75 | | - self.assertEqual({u"nan": 99999, u"time_ms": t}, data) |
76 | 51 |
|
77 | | - def test_custom_json_encoder(self): |
78 | | - expected = { |
79 | | - u'channel_data': '{"money": "1.32"}', |
80 | | - u'auth': u'key:7f2ae5922800a20b9615543ce7c8e7d1c97115d108939410825ea690f308a05f' |
81 | | - } |
82 | | - data = self.pusher_client.authenticate("presence-c1", "1.1", {"money": Decimal("1.32")}) |
83 | | - self.assertEqual(expected, data) |
| 52 | +if __name__ == '__main__': |
| 53 | + unittest.main() |
0 commit comments