本文整理汇总了Python中pusher.Pusher.from_url方法的典型用法代码示例。如果您正苦于以下问题:Python Pusher.from_url方法的具体用法?Python Pusher.from_url怎么用?Python Pusher.from_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pusher.Pusher
的用法示例。
在下文中一共展示了Pusher.from_url方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_webhook_bad_time
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_validate_webhook_bad_time(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
body = u'{"time_ms": 1000000}'
signature = six.text_type(hmac.new(pusher.secret.encode('utf8'), body.encode('utf8'), hashlib.sha256).hexdigest())
with mock.patch('time.time', return_value=1301):
self.assertEqual(pusher.validate_webhook(pusher.key, signature, body), None)
示例2: test_initialize_from_url
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_initialize_from_url(self):
self.assertRaises(TypeError, lambda: Pusher.from_url(4))
self.assertRaises(Exception, lambda: Pusher.from_url(u"httpsahsutaeh"))
conf = Pusher.from_url(u"http://foo:[email protected]/apps/4")
self.assertEqual(conf.ssl, False)
self.assertEqual(conf.key, u"foo")
self.assertEqual(conf.secret, u"bar")
self.assertEqual(conf.host, u"host")
self.assertEqual(conf.app_id, u"4")
conf = Pusher.from_url(u"https://foo:[email protected]/apps/4")
self.assertEqual(conf.ssl, True)
self.assertEqual(conf.key, u"foo")
self.assertEqual(conf.secret, u"bar")
self.assertEqual(conf.host, u"host")
self.assertEqual(conf.app_id, u"4")
示例3: test_authenticate_for_private_channels
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_authenticate_for_private_channels(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
expected = {
u'auth': u"foo:89955e77e1b40e33df6d515a5ecbba86a01dc816a5b720da18a06fd26f7d92ff"
}
self.assertEqual(pusher.authenticate(u'private-channel', u'345.23'), expected)
示例4: test_validate_webhook_bad_signature
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_validate_webhook_bad_signature(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
body = u'some body'
signature = u'some signature'
with mock.patch('time.time') as time_mock:
self.assertEqual(pusher.validate_webhook(pusher.key, signature, body), None)
time_mock.assert_not_called()
示例5: test_validate_webhook_bad_key
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_validate_webhook_bad_key(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
body = u'some body'
signature = six.text_type(hmac.new(pusher.secret.encode(u'utf8'), body.encode(u'utf8'), hashlib.sha256).hexdigest())
with mock.patch('time.time') as time_mock:
self.assertEqual(pusher.validate_webhook(u'badkey', signature, body), None)
time_mock.assert_not_called()
示例6: test_x_pusher_library_header
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_x_pusher_library_header(self):
conf = Pusher.from_url(u'http://key:[email protected]/apps/4')
req = Request(conf._pusher_client, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
self.assertTrue('X-Pusher-Library' in req.headers)
pusherLib = req.headers['X-Pusher-Library']
regex = r'^pusher-http-python \d+(\.\d+)+(rc\d+)?$'
if sys.version_info < (3,):
self.assertRegexpMatches(pusherLib, regex)
else:
self.assertRegex(pusherLib, regex)
示例7: test_validate_webhook_bad_types
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_validate_webhook_bad_types(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
pusher.validate_webhook(u'key', u'signature', u'body')
# These things are meant to be human readable, so enforcing being text is
# sensible.
with mock.patch('time.time') as time_mock:
self.assertRaises(TypeError, lambda: pusher.validate_webhook(4, u'signature', u'body'))
self.assertRaises(TypeError, lambda: pusher.validate_webhook(u'key', 4, u'body'))
self.assertRaises(TypeError, lambda: pusher.validate_webhook(u'key', u'signature', 4))
time_mock.assert_not_called()
示例8: test_get_signature_generation
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_get_signature_generation(self):
conf = Pusher.from_url(u'http://key:[email protected]/apps/4')
expected = {
u'auth_key': u'key',
u'auth_signature': u'5c49f04a95eedc9028b1e0e8de7c2c7ad63504a0e3b5c145d2accaef6c14dbac',
u'auth_timestamp': u'1000',
u'auth_version': u'1.0',
u'body_md5': u'd41d8cd98f00b204e9800998ecf8427e',
u'foo': u'bar'
}
with mock.patch('time.time', return_value=1000):
req = Request(conf, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
self.assertEqual(req.query_params, expected)
示例9: setUp
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def setUp(self):
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Decimal):
return str(o)
return super(JSONEncoder, self).default(o)
constants = {"NaN": 99999}
class JSONDecoder(json.JSONDecoder):
def __init__(self, **kwargs):
super(JSONDecoder, self).__init__(parse_constant=constants.__getitem__)
self.pusher = Pusher.from_url(u'http://key:[email protected]/apps/4',
json_encoder=JSONEncoder,
json_decoder=JSONDecoder)
示例10: test_post_signature_generation
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_post_signature_generation(self):
conf = Pusher.from_url(u'http://key:[email protected]/apps/4')
expected = {
u'auth_key': u'key',
u'auth_signature': u'e05fa4cafee86311746ee3981d5581a5e4e87c27bbab0aeb1059e2df5c90258b',
u'auth_timestamp': u'1000',
u'auth_version': u'1.0',
u'body_md5': u'94232c5b8fc9272f6f73a1e36eb68fcf'
}
with mock.patch('time.time', return_value=1000):
# patching this, because json can be unambiguously parsed, but not
# unambiguously generated (think whitespace).
with mock.patch('json.dumps', return_value='{"foo": "bar"}') as json_dumps_mock:
req = Request(conf, u'POST', u'/some/obscure/api', {u'foo': u'bar'})
self.assertEqual(req.query_params, expected)
json_dumps_mock.assert_called_once({u"foo": u"bar"})
示例11: test_authenticate_for_presence_channels
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_authenticate_for_presence_channels(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
custom_data = {
u'user_id': u'fred',
u'user_info': {
u'key': u'value'
}
}
expected = {
u'auth': u"foo:e80ba6439492c2113022c39297a87a948de14061cc67b5788e045645a68b8ccd",
u'channel_data': u"{\"user_id\":\"fred\",\"user_info\":{\"key\":\"value\"}}"
}
with mock.patch('json.dumps', return_value=expected[u'channel_data']) as dumps_mock:
actual = pusher.authenticate(u'presence-channel', u'345.43245', custom_data)
self.assertEqual(actual, expected)
dumps_mock.assert_called_once_with(custom_data, cls=None)
示例12: test_authenticate_types
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def test_authenticate_types(self):
pusher = Pusher.from_url(u'http://foo:[email protected]/apps/4')
self.assertRaises(TypeError, lambda: pusher.authenticate(2423, u'34554'))
self.assertRaises(TypeError, lambda: pusher.authenticate(u'plah', 234234))
self.assertRaises(ValueError, lambda: pusher.authenticate(u'::', u'345345'))
示例13: get_token
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
from little_pger import LittlePGer
from redis import StrictRedis
from pusher import Pusher
from flask import g
from flask_github import GitHub
import settings
redis = StrictRedis.from_url(settings.REDIS_URL)
pusher = Pusher.from_url(settings.PUSHER_URL)
pg = LittlePGer(settings.POSTGRESQL_URL, commit=True)
github = GitHub()
@github.access_token_getter
def get_token():
return g.github_token
示例14: setUp
# 需要导入模块: from pusher import Pusher [as 别名]
# 或者: from pusher.Pusher import from_url [as 别名]
def setUp(self):
self.pusher = Pusher.from_url(u'http://key:[email protected]/apps/4')