<s> from copy import deepcopy <EOL> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from mox import IsA <EOL> from horizon . workflows import views <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . access_and_security import api_access <EOL> from openstack_dashboard . dashboards . project . access_and_security . security_groups import tables <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . usage import quotas <EOL> INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> class AccessAndSecurityTests ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AccessAndSecurityTests , self ) . setUp ( ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> api . nova : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> api . base : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def _test_index ( self , ec2_enabled ) : <EOL> keypairs = self . keypairs . list ( ) <EOL> sec_groups = self . security_groups . list ( ) <EOL> floating_ips = self . floating_ips . list ( ) <EOL> quota_data = self . quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:10> <EOL> api . nova . server_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( [ self . servers . list ( ) , False ] ) <EOL> api . nova . keypair_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( keypairs ) <EOL> api . network . floating_ip_supported ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( True ) <EOL> api . network . tenant_floating_ip_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( floating_ips ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_groups ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> api . base . is_service_enabled ( <EOL> IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . MultipleTimes ( ) . AndReturn ( True ) <EOL> api . base . is_service_enabled ( <EOL> IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . MultipleTimes ( ) . AndReturn ( ec2_enabled ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , keypairs ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , <EOL> sec_groups ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , <EOL> floating_ips ) <EOL> if ec2_enabled : <EOL> self . assertTrue ( any ( map ( <EOL> lambda x : isinstance ( x , api_access . tables . DownloadEC2 ) , <EOL> res . context [ '<STR_LIT>' ] . get_table_actions ( ) <EOL> ) ) ) <EOL> else : <EOL> self . assertFalse ( any ( map ( <EOL> lambda x : isinstance ( x , api_access . tables . DownloadEC2 ) , <EOL> res . context [ '<STR_LIT>' ] . get_table_actions ( ) <EOL> ) ) ) <EOL> def test_index ( self ) : <EOL> self . _test_index ( ec2_enabled = True ) <EOL> def test_index_with_ec2_disabled ( self ) : <EOL> self . _test_index ( ec2_enabled = False ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_association ( self ) : <EOL> servers = [ api . nova . Server ( s , self . request ) <EOL> for s in self . servers . list ( ) ] <EOL> server3 = api . nova . Server ( self . servers . first ( ) , self . request ) <EOL> server3 . id = <NUM_LIT> <EOL> server3 . addresses = deepcopy ( server3 . addresses ) <EOL> server3 . addresses [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> servers . append ( server3 ) <EOL> targets = [ api . nova . FloatingIpTarget ( s ) for s in servers ] <EOL> api . network . tenant_floating_ip_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . floating_ips . list ( ) ) <EOL> api . network . floating_ip_target_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( targets ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> class AccessAndSecurityNeutronProxyTests ( AccessAndSecurityTests ) : <EOL> def setUp ( self ) : <EOL> super ( AccessAndSecurityNeutronProxyTests , self ) . setUp ( ) <EOL> self . floating_ips = self . floating_ips_uuid <EOL> class SecurityGroupTabTests ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SecurityGroupTabTests , self ) . setUp ( ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> api . nova : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) , <EOL> api . base : ( '<STR_LIT>' , ) } ) <EOL> def _test_create_button_disabled_when_quota_exceeded ( self , <EOL> network_enabled ) : <EOL> keypairs = self . keypairs . list ( ) <EOL> floating_ips = self . floating_ips . list ( ) <EOL> floating_pools = self . pools . list ( ) <EOL> sec_groups = self . security_groups . list ( ) <EOL> quota_data = self . quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> api . network . floating_ip_supported ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( True ) <EOL> api . network . tenant_floating_ip_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( floating_ips ) <EOL> api . network . floating_ip_pools_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( floating_pools ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_groups ) <EOL> api . nova . keypair_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( keypairs ) <EOL> api . nova . server_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( [ self . servers . list ( ) , False ] ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> api . base . is_service_enabled ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . MultipleTimes ( ) . AndReturn ( network_enabled ) <EOL> api . base . is_service_enabled ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . MultipleTimes ( ) . AndReturn ( False ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL + <EOL> "<STR_LIT>" ) <EOL> security_groups = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( security_groups , self . security_groups . list ( ) ) <EOL> create_link = tables . CreateGroup ( ) <EOL> url = create_link . get_link_url ( ) <EOL> classes = ( list ( create_link . get_default_classes ( ) ) <EOL> + list ( create_link . classes ) ) <EOL> link_name = "<STR_LIT>" % ( unicode ( create_link . verbose_name ) , <EOL> "<STR_LIT>" ) <EOL> expected_string = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( url , link_name , "<STR_LIT:U+0020>" . join ( classes ) , link_name ) <EOL> self . assertContains ( res , expected_string , html = True , <EOL> msg_prefix = "<STR_LIT>" ) <EOL> def test_create_button_disabled_when_quota_exceeded_neutron_disabled ( self ) : <EOL> self . _test_create_button_disabled_when_quota_exceeded ( False ) <EOL> def test_create_button_disabled_when_quota_exceeded_neutron_enabled ( self ) : <EOL> self . _test_create_button_disabled_when_quota_exceeded ( True ) </s>
