Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add VideoGrant. #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tests/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from nose.tools import assert_equal
from twilio.jwt import decode
from twilio.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant
from twilio.access_token import AccessToken, ConversationsGrant, IpMessagingGrant, VoiceGrant, VideoGrant

ACCOUNT_SID = 'AC123'
SIGNING_KEY_SID = 'SK123'
Expand Down Expand Up @@ -93,18 +93,33 @@ def test_ip_messaging_grant(self):
'push_credential_sid': 'CR123'
}, payload['grants']['ip_messaging'])

def test_video_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(VideoGrant(configuration_profile_sid='CP123'))

token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal(1, len(payload['grants']))
assert_equal({
'configuration_profile_sid': 'CP123'
}, payload['grants']['video'])

def test_grants(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant())
scat.add_grant(IpMessagingGrant())
scat.add_grant(VideoGrant())

token = str(scat)
assert_is_not_none(token)
payload = decode(token, 'secret')
self._validate_claims(payload)
assert_equal(2, len(payload['grants']))
assert_equal(3, len(payload['grants']))
assert_equal({}, payload['grants']['rtc'])
assert_equal({}, payload['grants']['ip_messaging'])
assert_equal({}, payload['grants']['video'])

def test_programmable_voice_grant(self):
grant = VoiceGrant(
Expand Down
17 changes: 17 additions & 0 deletions twilio/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ def to_payload(self):
return grant


class VideoGrant(object):
""" Grant to access Twilio Video """
def __init__(self, configuration_profile_sid=None):
self.configuration_profile_sid = configuration_profile_sid

@property
def key(self):
return "video"

def to_payload(self):
grant = {}
if self.configuration_profile_sid:
grant['configuration_profile_sid'] = self.configuration_profile_sid

return grant


class AccessToken(object):
""" Access Token used to access Twilio Resources """
def __init__(self, account_sid, signing_key_sid, secret,
Expand Down