From 3417df88d9da24af96e4c3cf0917dd74cf430b9d Mon Sep 17 00:00:00 2001 From: Jingming Niu Date: Wed, 1 Mar 2017 14:37:33 -0800 Subject: [PATCH] Update video grant --- tests/unit/jwt/test_access_token.py | 30 ++++++++--------------------- twilio/jwt/access_token/grants.py | 25 ++++-------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/tests/unit/jwt/test_access_token.py b/tests/unit/jwt/test_access_token.py index 8db81ba462..b53120147c 100644 --- a/tests/unit/jwt/test_access_token.py +++ b/tests/unit/jwt/test_access_token.py @@ -6,7 +6,6 @@ from twilio.jwt.access_token import AccessToken from twilio.jwt.access_token.grants import ( - ConversationsGrant, IpMessagingGrant, SyncGrant, VoiceGrant, @@ -80,22 +79,9 @@ def test_identity(self): 'identity': 'test@twilio.com' }, decoded_token.payload['grants']) - def test_conversations_grant(self): - scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') - scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123')) - - token = scat.to_jwt() - assert_is_not_none(token) - decoded_token = AccessToken.from_jwt(token, 'secret') - self._validate_claims(decoded_token.payload) - assert_equal(1, len(decoded_token.payload['grants'])) - assert_equal({ - 'configuration_profile_sid': 'CP123' - }, decoded_token.payload['grants']['rtc']) - def test_video_grant(self): scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') - scat.add_grant(VideoGrant(configuration_profile_sid='CP123')) + scat.add_grant(VideoGrant(room='CP123')) token = scat.to_jwt() assert_is_not_none(token) @@ -103,7 +89,7 @@ def test_video_grant(self): self._validate_claims(decoded_token.payload) assert_equal(1, len(decoded_token.payload['grants'])) assert_equal({ - 'configuration_profile_sid': 'CP123' + 'room': 'CP123' }, decoded_token.payload['grants']['video']) def test_ip_messaging_grant(self): @@ -138,7 +124,7 @@ def test_sync_grant(self): def test_grants(self): scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') - scat.add_grant(ConversationsGrant()) + scat.add_grant(VideoGrant()) scat.add_grant(IpMessagingGrant()) token = scat.to_jwt() @@ -146,7 +132,7 @@ def test_grants(self): decoded_token = AccessToken.from_jwt(token, 'secret') self._validate_claims(decoded_token.payload) assert_equal(2, len(decoded_token.payload['grants'])) - assert_equal({}, decoded_token.payload['grants']['rtc']) + assert_equal({}, decoded_token.payload['grants']['video']) assert_equal({}, decoded_token.payload['grants']['ip_messaging']) def test_programmable_voice_grant(self): @@ -176,7 +162,7 @@ def test_programmable_voice_grant(self): def test_pass_grants_in_constructor(self): grants = [ - ConversationsGrant(), + VideoGrant(), IpMessagingGrant() ] scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants) @@ -187,15 +173,15 @@ def test_pass_grants_in_constructor(self): decoded_token = AccessToken.from_jwt(token, 'secret') self._validate_claims(decoded_token.payload) assert_equal(2, len(decoded_token.payload['grants'])) - assert_equal({}, decoded_token.payload['grants']['rtc']) + assert_equal({}, decoded_token.payload['grants']['video']) assert_equal({}, decoded_token.payload['grants']['ip_messaging']) def test_constructor_validates_grants(self): - grants = [ConversationsGrant, 'GrantMeAccessToEverything'] + grants = [VideoGrant, 'GrantMeAccessToEverything'] self.assertRaises(ValueError, AccessToken, ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants) def test_add_grant_validates_grant(self): scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret') - scat.add_grant(ConversationsGrant()) + scat.add_grant(VideoGrant()) self.assertRaises(ValueError, scat.add_grant, 'GrantRootAccess') diff --git a/twilio/jwt/access_token/grants.py b/twilio/jwt/access_token/grants.py index 22a7f2a87e..9636f9e3fc 100644 --- a/twilio/jwt/access_token/grants.py +++ b/twilio/jwt/access_token/grants.py @@ -48,23 +48,6 @@ def to_payload(self): return grant -class ConversationsGrant(AccessTokenGrant): - """Grant to access Twilio Conversations""" - def __init__(self, configuration_profile_sid=None): - self.configuration_profile_sid = configuration_profile_sid - - @property - def key(self): - return "rtc" - - def to_payload(self): - grant = {} - if self.configuration_profile_sid: - grant['configuration_profile_sid'] = self.configuration_profile_sid - - return grant - - class VoiceGrant(AccessTokenGrant): """Grant to access Twilio Programmable Voice""" def __init__(self, @@ -105,8 +88,8 @@ def to_payload(self): class VideoGrant(AccessTokenGrant): """Grant to access Twilio Video""" - def __init__(self, configuration_profile_sid=None): - self.configuration_profile_sid = configuration_profile_sid + def __init__(self, room=None): + self.room = room @property def key(self): @@ -114,7 +97,7 @@ def key(self): def to_payload(self): grant = {} - if self.configuration_profile_sid: - grant['configuration_profile_sid'] = self.configuration_profile_sid + if self.room: + grant['room'] = self.room return grant