<s> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from mox import IgnoreArg <EOL> from mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> ROLES_INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> ROLES_CREATE_URL = reverse ( '<STR_LIT>' ) <EOL> ROLES_UPDATE_URL = reverse ( '<STR_LIT>' , args = [ <NUM_LIT:1> ] ) <EOL> class RolesViewTests ( test . BaseAdminViewTests ) : <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_index ( self ) : <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( ROLES_INDEX_URL ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , self . roles . list ( ) ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_index_with_keystone_can_edit_role_false ( self ) : <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . keystone_can_edit_role ( ) . MultipleTimes ( ) . AndReturn ( False ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( ROLES_INDEX_URL ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , self . roles . list ( ) ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_create ( self ) : <EOL> role = self . roles . first ( ) <EOL> api . keystone . role_create ( IgnoreArg ( ) , role . name ) . AndReturn ( role ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : role . name } <EOL> res = self . client . post ( ROLES_CREATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_update ( self ) : <EOL> role = self . roles . first ( ) <EOL> new_role_name = '<STR_LIT>' <EOL> api . keystone . role_get ( IsA ( http . HttpRequest ) , role . id ) . AndReturn ( role ) <EOL> api . keystone . role_update ( IsA ( http . HttpRequest ) , <EOL> role . id , <EOL> new_role_name ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : role . id , <EOL> '<STR_LIT:name>' : new_role_name } <EOL> res = self . client . post ( ROLES_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_delete ( self ) : <EOL> role = self . roles . first ( ) <EOL> api . keystone . role_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . role_delete ( IsA ( http . HttpRequest ) , <EOL> role . id ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % role . id } <EOL> res = self . client . post ( ROLES_INDEX_URL , formData ) <EOL> self . assertNoFormErrors ( res ) </s>
