-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathtest_pusher.py
53 lines (42 loc) · 1.78 KB
/
test_pusher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
from __future__ import (
print_function,
unicode_literals,
absolute_import,
division)
import hashlib
import hmac
import os
import six
import unittest
from pusher.pusher import Pusher
try:
import unittest.mock as mock
except ImportError:
import mock
class TestPusher(unittest.TestCase):
def test_initialize_from_url(https://github.com/self):
self.assertRaises(TypeError, lambda: Pusher.from_url(https://github.com/4))
self.assertRaises(Exception, lambda: Pusher.from_url(https://github.com/u'httpsahsutaeh'))
pusher = Pusher.from_url(https://github.com/u'http://foo:bar@host/apps/4')
self.assertEqual(pusher._pusher_client.ssl, False)
self.assertEqual(pusher._pusher_client.key, u'foo')
self.assertEqual(pusher._pusher_client.secret, u'bar')
self.assertEqual(pusher._pusher_client.host, u'host')
self.assertEqual(pusher._pusher_client.app_id, u'4')
pusher = Pusher.from_url(https://github.com/u'https://foo:bar@host/apps/4')
self.assertEqual(pusher._pusher_client.ssl, True)
self.assertEqual(pusher._pusher_client.key, u'foo')
self.assertEqual(pusher._pusher_client.secret, u'bar')
self.assertEqual(pusher._pusher_client.host, u'host')
self.assertEqual(pusher._pusher_client.app_id, u'4')
def test_initialize_from_env(self):
with mock.patch.object(os, 'environ', new={'PUSHER_URL':'https://plah:bob@somehost/apps/42'}):
pusher = Pusher.from_env()
self.assertEqual(pusher._pusher_client.ssl, True)
self.assertEqual(pusher._pusher_client.key, u'plah')
self.assertEqual(pusher._pusher_client.secret, u'bob')
self.assertEqual(pusher._pusher_client.host, u'somehost')
self.assertEqual(pusher._pusher_client.app_id, u'42')
if __name__ == '__main__':
unittest.main()