<s> import unittest <EOL> import warnings <EOL> from twilio import jwt <EOL> from twilio . task_router import TaskRouterCapability <EOL> class TaskRouterCapabilityTest ( unittest . TestCase ) : <EOL> def check_policy ( self , method , url , policy ) : <EOL> self . assertEqual ( url , policy [ '<STR_LIT:url>' ] ) <EOL> self . assertEqual ( method , policy [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( policy [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( { } , policy [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( { } , policy [ '<STR_LIT>' ] ) <EOL> def check_decoded ( self , decoded , account_sid , workspace_sid , channel_id , channel_sid = None ) : <EOL> self . assertEqual ( decoded [ "<STR_LIT>" ] , account_sid ) <EOL> self . assertEqual ( decoded [ "<STR_LIT>" ] , account_sid ) <EOL> self . assertEqual ( decoded [ "<STR_LIT>" ] , workspace_sid ) <EOL> self . assertEqual ( decoded [ "<STR_LIT>" ] , channel_id ) <EOL> self . assertEqual ( decoded [ "<STR_LIT:version>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( decoded [ "<STR_LIT>" ] , channel_id ) <EOL> if '<STR_LIT>' in decoded . keys ( ) : <EOL> self . assertEqual ( decoded [ '<STR_LIT>' ] , channel_sid ) <EOL> if '<STR_LIT>' in decoded . keys ( ) : <EOL> self . assertEqual ( decoded [ '<STR_LIT>' ] , channel_sid ) <EOL> def test_workspace_default ( self ) : <EOL> account_sid = "<STR_LIT>" <EOL> auth_token = "<STR_LIT>" <EOL> workspace_sid = "<STR_LIT>" <EOL> channel_id = "<STR_LIT>" <EOL> capability = TaskRouterCapability ( account_sid , auth_token , workspace_sid , channel_id ) <EOL> capability . generate_token ( ) <EOL> token = capability . generate_token ( ) <EOL> self . assertNotEqual ( None , token ) <EOL> decoded = jwt . decode ( token , auth_token ) <EOL> self . assertNotEqual ( None , decoded ) <EOL> self . check_decoded ( decoded , account_sid , workspace_sid , channel_id ) <EOL> policies = decoded [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( policies ) , <NUM_LIT:3> ) <EOL> for method , url , policy in [ <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:0> ] ) , <EOL> ( '<STR_LIT:POST>' , "<STR_LIT>" , policies [ <NUM_LIT:1> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:2> ] ) , <EOL> ] : <EOL> yield self . check_policy , method , url , policy <EOL> def test_worker_default ( self ) : <EOL> account_sid = "<STR_LIT>" <EOL> auth_token = "<STR_LIT>" <EOL> workspace_sid = "<STR_LIT>" <EOL> worker_sid = "<STR_LIT>" <EOL> capability = TaskRouterCapability ( account_sid , auth_token , workspace_sid , worker_sid ) <EOL> capability . generate_token ( ) <EOL> token = capability . generate_token ( ) <EOL> self . assertNotEqual ( None , token ) <EOL> decoded = jwt . decode ( token , auth_token ) <EOL> self . assertNotEqual ( None , decoded ) <EOL> self . check_decoded ( decoded , account_sid , workspace_sid , worker_sid , worker_sid ) <EOL> policies = decoded [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( policies ) , <NUM_LIT:6> ) <EOL> for method , url , policy in [ <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:0> ] ) , <EOL> ( '<STR_LIT:POST>' , "<STR_LIT>" , policies [ <NUM_LIT:1> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:2> ] ) <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:3> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:4> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:5> ] ) <EOL> ] : <EOL> yield self . check_policy , method , url , policy <EOL> def test_task_queue_default ( self ) : <EOL> account_sid = "<STR_LIT>" <EOL> auth_token = "<STR_LIT>" <EOL> workspace_sid = "<STR_LIT>" <EOL> taskqueue_sid = "<STR_LIT>" <EOL> capability = TaskRouterCapability ( account_sid , auth_token , workspace_sid , taskqueue_sid ) <EOL> capability . generate_token ( ) <EOL> token = capability . generate_token ( ) <EOL> self . assertNotEqual ( None , token ) <EOL> decoded = jwt . decode ( token , auth_token ) <EOL> self . assertNotEqual ( None , decoded ) <EOL> self . check_decoded ( decoded , account_sid , workspace_sid , taskqueue_sid , taskqueue_sid ) <EOL> policies = decoded [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( policies ) , <NUM_LIT:3> ) <EOL> for method , url , policy in [ <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:0> ] ) , <EOL> ( '<STR_LIT:POST>' , "<STR_LIT>" , policies [ <NUM_LIT:1> ] ) <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:2> ] ) <EOL> ] : <EOL> yield self . check_policy , method , url , policy <EOL> def test_deprecated_worker ( self ) : <EOL> account_sid = "<STR_LIT>" <EOL> auth_token = "<STR_LIT>" <EOL> workspace_sid = "<STR_LIT>" <EOL> worker_sid = "<STR_LIT>" <EOL> capability = TaskRouterCapability ( account_sid , auth_token , workspace_sid , worker_sid ) <EOL> capability . generate_token ( ) <EOL> token = capability . generate_token ( ) <EOL> self . assertNotEqual ( None , token ) <EOL> decoded = jwt . decode ( token , auth_token ) <EOL> self . assertNotEqual ( None , decoded ) <EOL> self . check_decoded ( decoded , account_sid , workspace_sid , worker_sid , worker_sid ) <EOL> policies = decoded [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( policies ) , <NUM_LIT:6> ) <EOL> for method , url , policy in [ <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:0> ] ) , <EOL> ( '<STR_LIT:POST>' , "<STR_LIT>" , policies [ <NUM_LIT:1> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:2> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:3> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:4> ] ) , <EOL> ( '<STR_LIT:GET>' , "<STR_LIT>" , policies [ <NUM_LIT:5> ] ) <EOL> ] : <EOL> yield self . check_policy , method , url , policy <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( "<STR_LIT>" ) <EOL> capability . allow_worker_fetch_attributes ( ) <EOL> assert len ( w ) == <NUM_LIT:1> <EOL> assert issubclass ( w [ - <NUM_LIT:1> ] . category , DeprecationWarning ) <EOL> assert "<STR_LIT>" in str ( w [ - <NUM_LIT:1> ] . message ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( "<STR_LIT>" ) <EOL> capability . allow_worker_activity_updates ( ) <EOL> assert len ( w ) == <NUM_LIT:1> <EOL> assert issubclass ( w [ - <NUM_LIT:1> ] . category , DeprecationWarning ) <EOL> assert "<STR_LIT>" in str ( w [ - <NUM_LIT:1> ] . message ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( "<STR_LIT>" ) <EOL> capability . allow_task_reservation_updates ( ) <EOL> assert len ( w ) == <NUM_LIT:1> <EOL> assert issubclass ( w [ - <NUM_LIT:1> ] . category , DeprecationWarning ) <EOL> assert "<STR_LIT>" in str ( w [ - <NUM_LIT:1> ] . message ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
