<s> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from django . utils . html import escape <EOL> from horizon . workflows import views <EOL> from mox3 . mox import IsA <EOL> import six <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . networks import tables as networks_tables <EOL> from openstack_dashboard . dashboards . project . networks import workflows <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . usage import quotas <EOL> INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> def form_data_subnet ( subnet , <EOL> name = None , cidr = None , ip_version = None , <EOL> gateway_ip = '<STR_LIT>' , enable_dhcp = None , <EOL> allocation_pools = None , <EOL> dns_nameservers = None , <EOL> host_routes = None ) : <EOL> def get_value ( value , default ) : <EOL> return default if value is None else value <EOL> data = { } <EOL> data [ '<STR_LIT>' ] = get_value ( name , subnet . name ) <EOL> data [ '<STR_LIT>' ] = get_value ( cidr , subnet . cidr ) <EOL> data [ '<STR_LIT>' ] = get_value ( ip_version , subnet . ip_version ) <EOL> gateway_ip = subnet . gateway_ip if gateway_ip == '<STR_LIT>' else gateway_ip <EOL> data [ '<STR_LIT>' ] = gateway_ip or '<STR_LIT>' <EOL> data [ '<STR_LIT>' ] = ( gateway_ip is None ) <EOL> data [ '<STR_LIT>' ] = get_value ( enable_dhcp , subnet . enable_dhcp ) <EOL> if data [ '<STR_LIT>' ] == <NUM_LIT:6> : <EOL> data [ '<STR_LIT>' ] = subnet . ipv6_modes <EOL> pools = get_value ( allocation_pools , subnet . allocation_pools ) <EOL> data [ '<STR_LIT>' ] = _str_allocation_pools ( pools ) <EOL> nameservers = get_value ( dns_nameservers , subnet . dns_nameservers ) <EOL> data [ '<STR_LIT>' ] = _str_dns_nameservers ( nameservers ) <EOL> routes = get_value ( host_routes , subnet . host_routes ) <EOL> data [ '<STR_LIT>' ] = _str_host_routes ( routes ) <EOL> return data <EOL> def form_data_no_subnet ( ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def _str_allocation_pools ( allocation_pools ) : <EOL> if isinstance ( allocation_pools , str ) : <EOL> return allocation_pools <EOL> return '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( pool [ '<STR_LIT:start>' ] , pool [ '<STR_LIT:end>' ] ) <EOL> for pool in allocation_pools ] ) <EOL> def _str_dns_nameservers ( dns_nameservers ) : <EOL> if isinstance ( dns_nameservers , str ) : <EOL> return dns_nameservers <EOL> return '<STR_LIT:\n>' . join ( dns_nameservers ) <EOL> def _str_host_routes ( host_routes ) : <EOL> if isinstance ( host_routes , str ) : <EOL> return host_routes <EOL> return '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( route [ '<STR_LIT>' ] , route [ '<STR_LIT>' ] ) <EOL> for route in host_routes ] ) <EOL> class NetworkStubMixin ( object ) : <EOL> def _stub_net_list ( self ) : <EOL> all_networks = self . networks . list ( ) <EOL> api . neutron . network_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> tenant_id = self . tenant . id , <EOL> shared = False ) . AndReturn ( [ <EOL> network for network in all_networks <EOL> if network [ '<STR_LIT>' ] == self . tenant . id <EOL> ] ) <EOL> api . neutron . network_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> shared = True ) . AndReturn ( [ <EOL> network for network in all_networks <EOL> if network . get ( '<STR_LIT>' ) <EOL> ] ) <EOL> api . neutron . network_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> ** { '<STR_LIT>' : True } ) . AndReturn ( [ <EOL> network for network in all_networks <EOL> if network . get ( '<STR_LIT>' ) <EOL> ] ) <EOL> class NetworkTests ( test . TestCase , NetworkStubMixin ) : <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_index ( self ) : <EOL> quota_data = self . quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> self . _stub_net_list ( ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> networks = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( networks , self . networks . list ( ) ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_index_network_list_exception ( self ) : <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> api . neutron . network_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> tenant_id = self . tenant . id , <EOL> shared = False ) . MultipleTimes ( ) . AndRaise ( self . exceptions . neutron ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:0> ) <EOL> self . assertMessageCount ( res , error = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail ( self ) : <EOL> self . _test_network_detail ( ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail_with_mac_learning ( self ) : <EOL> self . _test_network_detail ( mac_learning = True ) <EOL> def _test_network_detail ( self , mac_learning = False ) : <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> network_id = self . networks . first ( ) . id <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . subnet_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . subnets . first ( ) ] ) <EOL> api . neutron . port_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . ports . first ( ) ] ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( mac_learning ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> subnets = res . context [ '<STR_LIT>' ] . data <EOL> ports = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( subnets , [ self . subnets . first ( ) ] ) <EOL> self . assertItemsEqual ( ports , [ self . ports . first ( ) ] ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_detail_network_exception ( self ) : <EOL> self . _test_network_detail_network_exception ( ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_detail_network_exception_with_mac_learning ( self ) : <EOL> self . _test_network_detail_network_exception ( mac_learning = True ) <EOL> def _test_network_detail_network_exception ( self , mac_learning = False ) : <EOL> network_id = self . networks . first ( ) . id <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndRaise ( self . exceptions . neutron ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( mac_learning ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , args = [ network_id ] ) <EOL> res = self . client . get ( url ) <EOL> redir_url = INDEX_URL <EOL> self . assertRedirectsNoFollow ( res , redir_url ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail_subnet_exception ( self ) : <EOL> self . _test_network_detail_subnet_exception ( ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail_subnet_exception_with_mac_learning ( self ) : <EOL> self . _test_network_detail_subnet_exception ( mac_learning = True ) <EOL> def _test_network_detail_subnet_exception ( self , mac_learning = False ) : <EOL> network_id = self . networks . first ( ) . id <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . subnet_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndRaise ( self . exceptions . neutron ) <EOL> api . neutron . port_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . ports . first ( ) ] ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( mac_learning ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> subnets = res . context [ '<STR_LIT>' ] . data <EOL> ports = res . context [ '<STR_LIT>' ] . data <EOL> self . assertEqual ( len ( subnets ) , <NUM_LIT:0> ) <EOL> self . assertItemsEqual ( ports , [ self . ports . first ( ) ] ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail_port_exception ( self ) : <EOL> self . _test_network_detail_port_exception ( ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_detail_port_exception_with_mac_learning ( self ) : <EOL> self . _test_network_detail_port_exception ( mac_learning = True ) <EOL> def _test_network_detail_port_exception ( self , mac_learning = False ) : <EOL> network_id = self . networks . first ( ) . id <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:5> <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . subnet_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . subnets . first ( ) ] ) <EOL> api . neutron . port_list ( IsA ( http . HttpRequest ) , network_id = network_id ) . AndRaise ( self . exceptions . neutron ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network_id ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( mac_learning ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> subnets = res . context [ '<STR_LIT>' ] . data <EOL> ports = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( subnets , [ self . subnets . first ( ) ] ) <EOL> self . assertEqual ( len ( ports ) , <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_network_create_get ( self , <EOL> test_with_profile = False ) : <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . CreateNetwork . name ) <EOL> expected_objs = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_get_with_profile ( self ) : <EOL> self . test_network_create_get ( test_with_profile = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post ( self , <EOL> test_with_profile = False ) : <EOL> network = self . networks . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndReturn ( network ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_no_subnet ( ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_shared ( self , test_with_profile = False ) : <EOL> network = self . networks . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndReturn ( network ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_no_subnet ( ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_post_with_profile ( self ) : <EOL> self . test_network_create_post ( test_with_profile = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet ( self , <EOL> test_with_profile = False , <EOL> test_with_ipv6 = True ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False } <EOL> subnet_params = { '<STR_LIT>' : network . id , <EOL> '<STR_LIT:name>' : subnet . name , <EOL> '<STR_LIT>' : subnet . cidr , <EOL> '<STR_LIT>' : subnet . ip_version , <EOL> '<STR_LIT>' : subnet . gateway_ip , <EOL> '<STR_LIT>' : subnet . enable_dhcp } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> if not test_with_ipv6 : <EOL> subnet . ip_version = <NUM_LIT:4> <EOL> subnet_params [ '<STR_LIT>' ] = subnet . ip_version <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndReturn ( network ) <EOL> api . neutron . subnet_create ( IsA ( http . HttpRequest ) , <EOL> ** subnet_params ) . AndReturn ( subnet ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_subnet ( subnet , allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_post_with_subnet_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet ( test_with_profile = True ) <EOL> @ test . update_settings ( OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : False } ) <EOL> def test_create_network_with_ipv6_disabled ( self ) : <EOL> self . test_network_create_post_with_subnet ( test_with_ipv6 = False ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_network_exception ( self , <EOL> test_with_profile = False ) : <EOL> network = self . networks . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndRaise ( self . exceptions . neutron ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_no_subnet ( ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_post_nw_exception_w_profile ( self ) : <EOL> self . test_network_create_post_network_exception ( <EOL> test_with_profile = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_network_create_post_with_subnet_network_exception ( <EOL> self , <EOL> test_with_profile = False , <EOL> test_with_subnetpool = False , <EOL> ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndRaise ( self . exceptions . neutron ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_subnet ( subnet , allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_nw_create_post_w_subnet_nw_exception_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_network_exception ( <EOL> test_with_profile = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet_subnet_exception ( <EOL> self , <EOL> test_with_profile = False , <EOL> ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> params = { '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up } <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> params [ '<STR_LIT>' ] = net_profile_id <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . subnetpool_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . subnetpools . list ( ) ) <EOL> api . neutron . network_create ( IsA ( http . HttpRequest ) , <EOL> ** params ) . AndReturn ( network ) <EOL> api . neutron . subnet_create ( IsA ( http . HttpRequest ) , <EOL> network_id = network . id , <EOL> name = subnet . name , <EOL> cidr = subnet . cidr , <EOL> ip_version = subnet . ip_version , <EOL> gateway_ip = subnet . gateway_ip , <EOL> enable_dhcp = subnet . enable_dhcp ) . AndRaise ( self . exceptions . neutron ) <EOL> api . neutron . network_delete ( IsA ( http . HttpRequest ) , <EOL> network . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> form_data . update ( form_data_subnet ( subnet , allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_nw_create_post_w_subnet_subnet_exception_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_subnet_exception ( <EOL> test_with_profile = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet_nocidr ( self , <EOL> test_with_profile = False , <EOL> test_with_snpool = False ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . subnetpool_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . subnetpools . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> if test_with_snpool : <EOL> form_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form_data . update ( form_data_subnet ( subnet , cidr = '<STR_LIT>' , <EOL> allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertContains ( res , escape ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_nw_create_post_w_subnet_no_cidr_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_nocidr ( <EOL> test_with_profile = True ) <EOL> def test_network_create_post_with_subnet_nocidr_nosubnetpool ( self ) : <EOL> self . test_network_create_post_with_subnet_nocidr ( <EOL> test_with_snpool = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet_cidr_without_mask ( <EOL> self , <EOL> test_with_profile = False , <EOL> test_with_subnetpool = False , <EOL> ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . subnetpool_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . subnetpools . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> if test_with_subnetpool : <EOL> subnetpool = self . subnetpools . first ( ) <EOL> form_data [ '<STR_LIT>' ] = subnetpool . id <EOL> form_data [ '<STR_LIT>' ] = subnetpool . default_prefixlen <EOL> form_data . update ( form_data_subnet ( subnet , cidr = '<STR_LIT>' , <EOL> allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> expected_msg = "<STR_LIT>" <EOL> self . assertContains ( res , expected_msg ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_nw_create_post_w_subnet_cidr_without_mask_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_cidr_without_mask ( <EOL> test_with_profile = True ) <EOL> def test_network_create_post_with_subnet_cidr_without_mask_w_snpool ( self ) : <EOL> self . test_network_create_post_with_subnet_cidr_without_mask ( <EOL> test_with_subnetpool = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet_cidr_inconsistent ( <EOL> self , <EOL> test_with_profile = False , <EOL> test_with_subnetpool = False <EOL> ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . subnetpool_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . subnetpools . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> cidr = '<STR_LIT>' <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> if test_with_subnetpool : <EOL> subnetpool = self . subnetpools . first ( ) <EOL> form_data [ '<STR_LIT>' ] = subnetpool . id <EOL> form_data [ '<STR_LIT>' ] = subnetpool . default_prefixlen <EOL> form_data . update ( form_data_subnet ( subnet , cidr = cidr , <EOL> allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> expected_msg = '<STR_LIT>' <EOL> self . assertContains ( res , expected_msg ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_post_with_subnet_cidr_inconsistent_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_cidr_inconsistent ( <EOL> test_with_profile = True ) <EOL> def test_network_create_post_with_subnet_cidr_inconsistent_w_snpool ( self ) : <EOL> self . test_network_create_post_with_subnet_cidr_inconsistent ( <EOL> test_with_subnetpool = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_create_post_with_subnet_gw_inconsistent ( <EOL> self , <EOL> test_with_profile = False , <EOL> test_with_subnetpool = False , <EOL> ) : <EOL> network = self . networks . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> if test_with_profile : <EOL> net_profiles = self . net_profiles . list ( ) <EOL> net_profile_id = self . net_profiles . first ( ) . id <EOL> api . neutron . profile_list ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( net_profiles ) <EOL> api . neutron . is_extension_supported ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . subnetpool_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . subnetpools . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> gateway_ip = '<STR_LIT>' <EOL> form_data = { '<STR_LIT>' : network . name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : True } <EOL> if test_with_profile : <EOL> form_data [ '<STR_LIT>' ] = net_profile_id <EOL> if test_with_subnetpool : <EOL> subnetpool = self . subnetpools . first ( ) <EOL> form_data [ '<STR_LIT>' ] = subnetpool . id <EOL> form_data [ '<STR_LIT>' ] = subnetpool . default_prefixlen <EOL> form_data . update ( form_data_subnet ( subnet , gateway_ip = gateway_ip , <EOL> allocation_pools = [ ] ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> @ test . update_settings ( <EOL> OPENSTACK_NEUTRON_NETWORK = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_network_create_post_with_subnet_gw_inconsistent_w_profile ( self ) : <EOL> self . test_network_create_post_with_subnet_gw_inconsistent ( <EOL> test_with_profile = True ) <EOL> def test_network_create_post_with_subnet_gw_inconsistent_w_snpool ( self ) : <EOL> self . test_network_create_post_with_subnet_gw_inconsistent ( <EOL> test_with_subnetpool = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_network_update_get ( self ) : <EOL> network = self . networks . first ( ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network . id ) . AndReturn ( network ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , args = [ network . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_network_update_get_exception ( self ) : <EOL> network = self . networks . first ( ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network . id ) . AndRaise ( self . exceptions . neutron ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , args = [ network . id ] ) <EOL> res = self . client . get ( url ) <EOL> redir_url = INDEX_URL <EOL> self . assertRedirectsNoFollow ( res , redir_url ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_update_post ( self ) : <EOL> network = self . networks . first ( ) <EOL> api . neutron . network_update ( IsA ( http . HttpRequest ) , network . id , <EOL> name = network . name , <EOL> admin_state_up = network . admin_state_up , <EOL> shared = network . shared ) . AndReturn ( network ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network . id ) . AndReturn ( network ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . id , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : network . tenant_id } <EOL> url = reverse ( '<STR_LIT>' , args = [ network . id ] ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_network_update_post_exception ( self ) : <EOL> network = self . networks . first ( ) <EOL> api . neutron . network_update ( IsA ( http . HttpRequest ) , network . id , <EOL> name = network . name , <EOL> admin_state_up = network . admin_state_up , <EOL> shared = False ) . AndRaise ( self . exceptions . neutron ) <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , network . id ) . AndReturn ( network ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : network . id , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:name>' : network . name , <EOL> '<STR_LIT>' : network . admin_state_up , <EOL> '<STR_LIT>' : network . tenant_id } <EOL> url = reverse ( '<STR_LIT>' , args = [ network . id ] ) <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_network_no_subnet ( self ) : <EOL> network = self . networks . first ( ) <EOL> network . subnets = [ ] <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , <EOL> network . id , <EOL> expand_subnet = False ) . AndReturn ( network ) <EOL> self . _stub_net_list ( ) <EOL> api . neutron . network_delete ( IsA ( http . HttpRequest ) , network . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT:action>' : '<STR_LIT>' % network . id } <EOL> res = self . client . post ( INDEX_URL , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_network_with_subnet ( self ) : <EOL> network = self . networks . first ( ) <EOL> network . subnets = [ subnet . id for subnet in network . subnets ] <EOL> subnet_id = network . subnets [ <NUM_LIT:0> ] <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , <EOL> network . id , <EOL> expand_subnet = False ) . AndReturn ( network ) <EOL> self . _stub_net_list ( ) <EOL> api . neutron . subnet_delete ( IsA ( http . HttpRequest ) , subnet_id ) <EOL> api . neutron . network_delete ( IsA ( http . HttpRequest ) , network . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT:action>' : '<STR_LIT>' % network . id } <EOL> res = self . client . post ( INDEX_URL , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_network_exception ( self ) : <EOL> network = self . networks . first ( ) <EOL> network . subnets = [ subnet . id for subnet in network . subnets ] <EOL> subnet_id = network . subnets [ <NUM_LIT:0> ] <EOL> api . neutron . network_get ( IsA ( http . HttpRequest ) , <EOL> network . id , <EOL> expand_subnet = False ) . AndReturn ( network ) <EOL> self . _stub_net_list ( ) <EOL> api . neutron . subnet_delete ( IsA ( http . HttpRequest ) , subnet_id ) <EOL> api . neutron . network_delete ( IsA ( http . HttpRequest ) , network . id ) . AndRaise ( self . exceptions . neutron ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT:action>' : '<STR_LIT>' % network . id } <EOL> res = self . client . post ( INDEX_URL , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> class NetworkViewTests ( test . TestCase , NetworkStubMixin ) : <EOL> def _test_create_button_shown_when_quota_disabled ( <EOL> self , <EOL> find_button_fn ) : <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> quota_data [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> self . _stub_net_list ( ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> networks = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( networks , self . networks . list ( ) ) <EOL> button = find_button_fn ( res ) <EOL> self . assertFalse ( '<STR_LIT>' in button . classes , <EOL> "<STR_LIT>" ) <EOL> return button <EOL> def _test_create_button_disabled_when_quota_exceeded ( <EOL> self , find_button_fn , network_quota = <NUM_LIT:5> , subnet_quota = <NUM_LIT:5> , ) : <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = network_quota <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = subnet_quota <EOL> self . _stub_net_list ( ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> networks = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( networks , self . networks . list ( ) ) <EOL> button = find_button_fn ( res ) <EOL> self . assertTrue ( '<STR_LIT>' in button . classes , <EOL> "<STR_LIT>" ) <EOL> return button <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_create_button_disabled_when_quota_exceeded_index ( self ) : <EOL> networks_tables . CreateNetwork ( ) <EOL> def _find_net_button ( res ) : <EOL> return self . getAndAssertTableAction ( res , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _test_create_button_disabled_when_quota_exceeded ( _find_net_button , <EOL> network_quota = <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_subnet_create_button_disabled_when_quota_exceeded_index ( self ) : <EOL> network_id = self . networks . first ( ) . id <EOL> networks_tables . CreateSubnet ( ) <EOL> def _find_subnet_button ( res ) : <EOL> return self . getAndAssertTableRowAction ( res , '<STR_LIT>' , <EOL> '<STR_LIT>' , network_id ) <EOL> self . _test_create_button_disabled_when_quota_exceeded ( <EOL> _find_subnet_button , subnet_quota = <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_network_create_button_shown_when_quota_disabled_index ( self ) : <EOL> networks_tables . CreateNetwork ( ) <EOL> self . _test_create_button_shown_when_quota_disabled ( <EOL> lambda res : self . getAndAssertTableAction ( res , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_subnet_create_button_shown_when_quota_disabled_index ( self ) : <EOL> network_id = self . networks . first ( ) . id <EOL> def _find_subnet_button ( res ) : <EOL> return self . getAndAssertTableRowAction ( res , '<STR_LIT>' , <EOL> '<STR_LIT>' , network_id ) <EOL> self . _test_create_button_shown_when_quota_disabled ( _find_subnet_button ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_subnet_create_button_disabled_when_quota_exceeded_detail ( self ) : <EOL> network_id = self . networks . first ( ) . id <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> api . neutron . network_get ( <EOL> IsA ( http . HttpRequest ) , network_id ) . MultipleTimes ( ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . subnet_list ( <EOL> IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( self . subnets . list ( ) ) <EOL> api . neutron . port_list ( <EOL> IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . ports . first ( ) ] ) <EOL> api . neutron . is_extension_supported ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . AndReturn ( False ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> subnets = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( subnets , self . subnets . list ( ) ) <EOL> create_action = self . getAndAssertTableAction ( res , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in create_action . classes , <EOL> '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_create_button_attributes ( self ) : <EOL> create_action = self . _test_create_button_shown_when_quota_disabled ( <EOL> lambda res : self . getAndAssertTableAction ( res , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> self . assertEqual ( set ( [ '<STR_LIT>' ] ) , set ( create_action . classes ) ) <EOL> self . assertEqual ( '<STR_LIT>' , create_action . url ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> six . text_type ( create_action . verbose_name ) ) <EOL> self . assertEqual ( ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) , <EOL> create_action . policy_rules ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_create_subnet_button_attributes ( self ) : <EOL> network_id = self . networks . first ( ) . id <EOL> quota_data = self . neutron_quota_usages . first ( ) <EOL> quota_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> api . neutron . network_get ( <EOL> IsA ( http . HttpRequest ) , network_id ) . MultipleTimes ( ) . AndReturn ( self . networks . first ( ) ) <EOL> api . neutron . subnet_list ( <EOL> IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( self . subnets . list ( ) ) <EOL> api . neutron . port_list ( <EOL> IsA ( http . HttpRequest ) , network_id = network_id ) . AndReturn ( [ self . ports . first ( ) ] ) <EOL> api . neutron . is_extension_supported ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . AndReturn ( False ) <EOL> quotas . tenant_quota_usages ( <EOL> IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( quota_data ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> subnets = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( subnets , self . subnets . list ( ) ) <EOL> create_action = self . getAndAssertTableAction ( res , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( set ( [ '<STR_LIT>' ] ) , set ( create_action . classes ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> create_action . url ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> six . text_type ( create_action . verbose_name ) ) <EOL> self . assertEqual ( ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) , <EOL> create_action . policy_rules ) </s>
