<s> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from mox3 . mox import IgnoreArg <EOL> from mox3 . mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . dashboards . identity . groups import constants <EOL> GROUPS_INDEX_URL = reverse ( constants . GROUPS_INDEX_URL ) <EOL> GROUP_CREATE_URL = reverse ( constants . GROUPS_CREATE_URL ) <EOL> GROUP_UPDATE_URL = reverse ( constants . GROUPS_UPDATE_URL , args = [ <NUM_LIT:1> ] ) <EOL> GROUP_MANAGE_URL = reverse ( constants . GROUPS_MANAGE_URL , args = [ <NUM_LIT:1> ] ) <EOL> GROUP_ADD_MEMBER_URL = reverse ( constants . GROUPS_ADD_MEMBER_URL , args = [ <NUM_LIT:1> ] ) <EOL> class GroupsViewTests ( test . BaseAdminViewTests ) : <EOL> def _get_domain_id ( self ) : <EOL> return self . request . session . get ( '<STR_LIT>' , None ) <EOL> def _get_groups ( self , domain_id ) : <EOL> if not domain_id : <EOL> groups = self . groups . list ( ) <EOL> else : <EOL> groups = [ group for group in self . groups . list ( ) <EOL> if group . domain_id == domain_id ] <EOL> return groups <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_index ( self ) : <EOL> domain_id = self . _get_domain_id ( ) <EOL> groups = self . _get_groups ( domain_id ) <EOL> api . keystone . group_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( groups ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( GROUPS_INDEX_URL ) <EOL> self . assertTemplateUsed ( res , constants . GROUPS_INDEX_VIEW_TEMPLATE ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , groups ) <EOL> if domain_id : <EOL> for group in res . context [ '<STR_LIT>' ] . data : <EOL> self . assertItemsEqual ( group . domain_id , domain_id ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_with_domain ( self ) : <EOL> domain = self . domains . get ( id = "<STR_LIT:1>" ) <EOL> self . setSessionValues ( domain_context = domain . id , <EOL> domain_context_name = domain . name ) <EOL> groups = self . _get_groups ( domain . id ) <EOL> api . keystone . get_effective_domain_id ( IgnoreArg ( ) ) . AndReturn ( domain . id ) <EOL> api . keystone . group_list ( IsA ( http . HttpRequest ) , <EOL> domain = domain . id ) . AndReturn ( groups ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( GROUPS_INDEX_URL ) <EOL> self . assertTemplateUsed ( res , constants . GROUPS_INDEX_VIEW_TEMPLATE ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , groups ) <EOL> if domain . id : <EOL> for group in res . context [ '<STR_LIT>' ] . data : <EOL> self . assertItemsEqual ( group . domain_id , domain . id ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_with_keystone_can_edit_group_false ( self ) : <EOL> domain_id = self . _get_domain_id ( ) <EOL> groups = self . _get_groups ( domain_id ) <EOL> api . keystone . group_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( groups ) <EOL> api . keystone . keystone_can_edit_group ( ) . MultipleTimes ( ) . AndReturn ( False ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( GROUPS_INDEX_URL ) <EOL> self . assertTemplateUsed ( res , constants . GROUPS_INDEX_VIEW_TEMPLATE ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , groups ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> self . assertNotContains ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_create ( self ) : <EOL> domain_id = self . _get_domain_id ( ) <EOL> group = self . groups . get ( id = "<STR_LIT:1>" ) <EOL> api . keystone . group_create ( IsA ( http . HttpRequest ) , <EOL> description = group . description , <EOL> domain_id = domain_id , <EOL> name = group . name ) . AndReturn ( group ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : group . name , <EOL> '<STR_LIT:description>' : group . description } <EOL> res = self . client . post ( GROUP_CREATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> def test_create_with_domain ( self ) : <EOL> domain = self . domains . get ( id = "<STR_LIT:1>" ) <EOL> self . setSessionValues ( domain_context = domain . id , <EOL> domain_context_name = domain . name ) <EOL> self . test_create ( ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update ( self ) : <EOL> group = self . groups . get ( id = "<STR_LIT:1>" ) <EOL> test_description = '<STR_LIT>' <EOL> api . keystone . group_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' ) . AndReturn ( group ) <EOL> api . keystone . group_update ( IsA ( http . HttpRequest ) , <EOL> description = test_description , <EOL> group_id = group . id , <EOL> name = group . name ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : group . id , <EOL> '<STR_LIT:name>' : group . name , <EOL> '<STR_LIT:description>' : test_description } <EOL> res = self . client . post ( GROUP_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_group ( self ) : <EOL> domain_id = self . _get_domain_id ( ) <EOL> group = self . groups . get ( id = "<STR_LIT:2>" ) <EOL> api . keystone . group_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( self . groups . list ( ) ) <EOL> api . keystone . group_delete ( IgnoreArg ( ) , group . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % group . id } <EOL> res = self . client . post ( GROUPS_INDEX_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , GROUPS_INDEX_URL ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_manage ( self ) : <EOL> group = self . groups . get ( id = "<STR_LIT:1>" ) <EOL> group_members = self . users . list ( ) <EOL> domain_id = self . _get_domain_id ( ) <EOL> api . keystone . group_get ( IsA ( http . HttpRequest ) , group . id ) . AndReturn ( group ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . get_effective_domain_id ( <EOL> IgnoreArg ( ) ) . AndReturn ( domain_id ) <EOL> api . keystone . user_list ( <EOL> IgnoreArg ( ) , group = group . id , domain = domain_id ) . AndReturn ( <EOL> group_members ) <EOL> else : <EOL> api . keystone . user_list ( <EOL> IgnoreArg ( ) , group = group . id ) . AndReturn ( group_members ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( GROUP_MANAGE_URL ) <EOL> self . assertTemplateUsed ( res , constants . GROUPS_MANAGE_VIEW_TEMPLATE ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , group_members ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_remove_user ( self ) : <EOL> group = self . groups . get ( id = "<STR_LIT:1>" ) <EOL> user = self . users . get ( id = "<STR_LIT:2>" ) <EOL> domain_id = self . _get_domain_id ( ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . get_effective_domain_id ( <EOL> IgnoreArg ( ) ) . AndReturn ( domain_id ) <EOL> api . keystone . user_list ( <EOL> IgnoreArg ( ) , group = group . id , domain = domain_id ) . AndReturn ( <EOL> self . users . list ( ) ) <EOL> else : <EOL> api . keystone . user_list ( <EOL> IgnoreArg ( ) , group = group . id ) . AndReturn ( self . users . list ( ) ) <EOL> api . keystone . remove_group_user ( IgnoreArg ( ) , <EOL> group_id = group . id , <EOL> user_id = user . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % user . id } <EOL> res = self . client . post ( GROUP_MANAGE_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , GROUP_MANAGE_URL ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_add_user ( self ) : <EOL> group = self . groups . get ( id = "<STR_LIT:1>" ) <EOL> user = self . users . get ( id = "<STR_LIT:2>" ) <EOL> domain_id = group . domain_id <EOL> api . keystone . get_effective_domain_id ( IgnoreArg ( ) ) . AndReturn ( domain_id ) <EOL> api . keystone . group_get ( IsA ( http . HttpRequest ) , group . id ) . AndReturn ( group ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( self . users . list ( ) ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id , group = group . id ) . AndReturn ( self . users . list ( ) [ <NUM_LIT:2> : ] ) <EOL> api . keystone . add_group_user ( IgnoreArg ( ) , <EOL> group_id = group . id , <EOL> user_id = user . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % user . id } <EOL> res = self . client . post ( GROUP_ADD_MEMBER_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , GROUP_MANAGE_URL ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) </s>
