<s> import testlib <EOL> import logging <EOL> import splunklib . client as client <EOL> class RoleTestCase ( testlib . SDKTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RoleTestCase , self ) . setUp ( ) <EOL> self . role_name = testlib . tmpname ( ) <EOL> self . role = self . service . roles . create ( self . role_name ) <EOL> def tearDown ( self ) : <EOL> super ( RoleTestCase , self ) . tearDown ( ) <EOL> for role in self . service . roles : <EOL> if role . name . startswith ( '<STR_LIT>' ) : <EOL> self . service . roles . delete ( role . name ) <EOL> def check_role ( self , role ) : <EOL> self . check_entity ( role ) <EOL> capabilities = role . service . capabilities <EOL> for capability in role . content . capabilities : <EOL> self . assertTrue ( capability in capabilities ) <EOL> def test_read ( self ) : <EOL> for role in self . service . roles : <EOL> self . check_role ( role ) <EOL> role . refresh ( ) <EOL> self . check_role ( role ) <EOL> def test_read_case_insensitive ( self ) : <EOL> for role in self . service . roles : <EOL> a = self . service . roles [ role . name . upper ( ) ] <EOL> b = self . service . roles [ role . name . lower ( ) ] <EOL> self . assertEqual ( a . name , b . name ) <EOL> def test_create ( self ) : <EOL> self . assertTrue ( self . role_name in self . service . roles ) <EOL> self . check_entity ( self . role ) <EOL> def test_delete ( self ) : <EOL> self . assertTrue ( self . role_name in self . service . roles ) <EOL> self . service . roles . delete ( self . role_name ) <EOL> self . assertFalse ( self . role_name in self . service . roles ) <EOL> self . assertRaises ( client . HTTPError , self . role . refresh ) <EOL> def test_grant_and_revoke ( self ) : <EOL> self . assertFalse ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . role . grant ( '<STR_LIT>' ) <EOL> self . role . refresh ( ) <EOL> self . assertTrue ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . assertFalse ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . role . grant ( '<STR_LIT>' ) <EOL> self . role . refresh ( ) <EOL> self . assertTrue ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . assertTrue ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . role . revoke ( '<STR_LIT>' ) <EOL> self . role . refresh ( ) <EOL> self . assertFalse ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . assertTrue ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . role . revoke ( '<STR_LIT>' ) <EOL> self . role . refresh ( ) <EOL> self . assertFalse ( '<STR_LIT>' in self . role . capabilities ) <EOL> self . assertFalse ( '<STR_LIT>' in self . role . capabilities ) <EOL> def test_invalid_grant ( self ) : <EOL> self . assertRaises ( client . NoSuchCapability , self . role . grant , '<STR_LIT>' ) <EOL> def test_invalid_revoke ( self ) : <EOL> self . assertRaises ( client . NoSuchCapability , self . role . revoke , '<STR_LIT>' ) <EOL> def test_revoke_capability_not_granted ( self ) : <EOL> self . role . revoke ( '<STR_LIT>' ) <EOL> def test_update ( self ) : <EOL> kwargs = { } <EOL> if '<STR_LIT:user>' in self . role [ '<STR_LIT>' ] : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT:user>' ] <EOL> if self . role [ '<STR_LIT>' ] is not None : <EOL> kwargs [ '<STR_LIT>' ] = int ( self . role [ '<STR_LIT>' ] ) + <NUM_LIT:1> <EOL> self . role . update ( ** kwargs ) <EOL> self . role . refresh ( ) <EOL> self . assertEqual ( self . role [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( int ( self . role [ '<STR_LIT>' ] ) , kwargs [ '<STR_LIT>' ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> unittest . main ( ) </s>
