<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 . dashboards . project . routers import tests as r_test <EOL> from openstack_dashboard . test import helpers as test <EOL> class RouterTests ( test . BaseAdminViewTests , r_test . RouterTests ) : <EOL> DASHBOARD = '<STR_LIT>' <EOL> INDEX_URL = reverse ( '<STR_LIT>' % DASHBOARD ) <EOL> DETAIL_PATH = '<STR_LIT>' % DASHBOARD <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_index ( self ) : <EOL> tenants = self . tenants . list ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' % self . DASHBOARD ) <EOL> routers = res . context [ '<STR_LIT>' ] . data <EOL> self . assertItemsEqual ( routers , self . routers . list ( ) ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) , <EOL> api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_index_router_list_exception ( self ) : <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndRaise ( self . exceptions . neutron ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' % self . DASHBOARD ) <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>' , '<STR_LIT>' ) , <EOL> api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_set_external_network_empty ( self ) : <EOL> router = self . routers . first ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( [ router ] ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ self . tenants . list ( ) , False ] ) <EOL> self . _mock_external_network_list ( alter_ids = True ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> table_data = res . context [ '<STR_LIT>' ] . data <EOL> self . assertEqual ( len ( table_data ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> table_data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' % self . DASHBOARD ) <EOL> self . assertMessageCount ( res , error = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_router_delete ( self ) : <EOL> router = self . routers . first ( ) <EOL> tenants = self . tenants . list ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> api . neutron . port_list ( IsA ( http . HttpRequest ) , <EOL> device_id = router . id , device_owner = IgnoreArg ( ) ) . AndReturn ( [ ] ) <EOL> api . neutron . router_delete ( IsA ( http . HttpRequest ) , router . id ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' + router . id } <EOL> res = self . client . post ( self . INDEX_URL , formData , follow = True ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( response = res , success = <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' + router . name , res . content ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , <EOL> api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_router_with_interface_delete ( self ) : <EOL> router = self . routers . first ( ) <EOL> ports = self . ports . list ( ) <EOL> tenants = self . tenants . list ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> api . neutron . port_list ( IsA ( http . HttpRequest ) , <EOL> device_id = router . id , device_owner = IgnoreArg ( ) ) . AndReturn ( ports ) <EOL> for port in ports : <EOL> api . neutron . router_remove_interface ( IsA ( http . HttpRequest ) , <EOL> router . id , port_id = port . id ) <EOL> api . neutron . router_delete ( IsA ( http . HttpRequest ) , router . id ) <EOL> api . neutron . router_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> search_opts = None ) . AndReturn ( self . routers . list ( ) ) <EOL> api . keystone . tenant_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ tenants , False ] ) <EOL> self . _mock_external_network_list ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' + router . id } <EOL> res = self . client . post ( self . INDEX_URL , formData , follow = True ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( response = res , success = <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' + router . name , res . content ) </s>
