本文整理匯總了Python中opentok.OpenTok.signal方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenTok.signal方法的具體用法?Python OpenTok.signal怎麽用?Python OpenTok.signal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類opentok.OpenTok
的用法示例。
在下文中一共展示了OpenTok.signal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: OpenTokSignalTest
# 需要導入模塊: from opentok import OpenTok [as 別名]
# 或者: from opentok.OpenTok import signal [as 別名]
class OpenTokSignalTest(unittest.TestCase):
def setUp(self):
self.api_key = u('123456')
self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
self.opentok = OpenTok(self.api_key, self.api_secret)
self.session_id = u('SESSIONID')
@httpretty.activate
def test_signal(self):
data = {
u('type'): u('type test'),
u('data'): u('test data')
}
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/session/{1}/signal').format(self.api_key, self.session_id),
body=textwrap.dedent(u("""\
{
"type": "type test",
"data": "test data"
}""")),
status=204,
content_type=u('application/json'))
self.opentok.signal(self.session_id, data)
validate_jwt_header(self, httpretty.last_request().headers[u('x-opentok-auth')])
expect(httpretty.last_request().headers[u('user-agent')]).to(contain(u('OpenTok-Python-SDK/')+__version__))
expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json')))
# non-deterministic json encoding. have to decode to test it properly
if PY2:
body = json.loads(httpretty.last_request().body)
if PY3:
body = json.loads(httpretty.last_request().body.decode('utf-8'))
expect(body).to(have_key(u('type'), u('type test')))
expect(body).to(have_key(u('data'), u('test data')))
@httpretty.activate
def test_signal_with_connection_id(self):
data = {
u('type'): u('type test'),
u('data'): u('test data')
}
connection_id = u('da9cb410-e29b-4c2d-ab9e-fe65bf83fcaf')
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/session/{1}/connection/{2}/signal').format(self.api_key, self.session_id, connection_id),
body=textwrap.dedent(u("""\
{
"type": "type test",
"data": "test data"
}""")),
status=204,
content_type=u('application/json'))
self.opentok.signal(self.session_id, data, connection_id)
validate_jwt_header(self, httpretty.last_request().headers[u('x-opentok-auth')])
expect(httpretty.last_request().headers[u('user-agent')]).to(contain(u('OpenTok-Python-SDK/')+__version__))
expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json')))
# non-deterministic json encoding. have to decode to test it properly
if PY2:
body = json.loads(httpretty.last_request().body)
if PY3:
body = json.loads(httpretty.last_request().body.decode('utf-8'))
expect(body).to(have_key(u('type'), u('type test')))
expect(body).to(have_key(u('data'), u('test data')))