<s> from mox import IsA <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . urlresolvers import reverse_lazy <EOL> from django import http <EOL> from horizon . workflows import views <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . dashboards . project . loadbalancers import workflows <EOL> class LoadBalancerTests ( test . TestCase ) : <EOL> class AttributeDict ( dict ) : <EOL> def __getattr__ ( self , attr ) : <EOL> return self [ attr ] <EOL> def __setattr__ ( self , attr , value ) : <EOL> self [ attr ] = value <EOL> DASHBOARD = '<STR_LIT>' <EOL> INDEX_URL = reverse_lazy ( '<STR_LIT>' % DASHBOARD ) <EOL> ADDPOOL_PATH = '<STR_LIT>' % DASHBOARD <EOL> ADDVIP_PATH = '<STR_LIT>' % DASHBOARD <EOL> ADDMEMBER_PATH = '<STR_LIT>' % DASHBOARD <EOL> ADDMONITOR_PATH = '<STR_LIT>' % DASHBOARD <EOL> POOL_DETAIL_PATH = '<STR_LIT>' % DASHBOARD <EOL> VIP_DETAIL_PATH = '<STR_LIT>' % DASHBOARD <EOL> MEMBER_DETAIL_PATH = '<STR_LIT>' % DASHBOARD <EOL> MONITOR_DETAIL_PATH = '<STR_LIT>' % DASHBOARD <EOL> UPDATEPOOL_PATH = '<STR_LIT>' % DASHBOARD <EOL> UPDATEVIP_PATH = '<STR_LIT>' % DASHBOARD <EOL> UPDATEMEMBER_PATH = '<STR_LIT>' % DASHBOARD <EOL> UPDATEMONITOR_PATH = '<STR_LIT>' % DASHBOARD <EOL> ADDASSOC_PATH = '<STR_LIT>' % DASHBOARD <EOL> DELETEASSOC_PATH = '<STR_LIT>' % DASHBOARD <EOL> def set_up_expect ( self ) : <EOL> api . lbaas . pool_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . lbaas . member_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . members . list ( ) ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . MultipleTimes ( ) . AndReturn ( self . monitors . list ( ) ) <EOL> def set_up_expect_with_exception ( self ) : <EOL> api . lbaas . pool_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndRaise ( self . exceptions . neutron ) <EOL> api . lbaas . member_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndRaise ( self . exceptions . neutron ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndRaise ( self . exceptions . neutron ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_pools ( self ) : <EOL> self . set_up_expect ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> len ( self . pools . list ( ) ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_members ( self ) : <EOL> self . set_up_expect ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL + '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> len ( self . members . list ( ) ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_monitors ( self ) : <EOL> self . set_up_expect ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL + '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> len ( self . monitors . list ( ) ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_exception_pools ( self ) : <EOL> self . set_up_expect_with_exception ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_exception_members ( self ) : <EOL> self . set_up_expect_with_exception ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL + '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index_exception_monitors ( self ) : <EOL> self . set_up_expect_with_exception ( ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . INDEX_URL + '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' <EOL> % self . DASHBOARD ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:0> ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> api . lbaas : ( '<STR_LIT>' , ) } ) <EOL> def test_add_pool_post ( self ) : <EOL> pool = self . pools . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> networks = [ { '<STR_LIT>' : [ subnet , ] } , ] <EOL> api . neutron . is_extension_supported ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . AndReturn ( True ) <EOL> api . neutron . network_list_for_tenant ( <EOL> IsA ( http . HttpRequest ) , self . tenant . id ) . AndReturn ( networks ) <EOL> api . neutron . provider_list ( IsA ( http . HttpRequest ) ) . AndReturn ( self . providers . list ( ) ) <EOL> form_data = { '<STR_LIT:name>' : pool . name , <EOL> '<STR_LIT:description>' : pool . description , <EOL> '<STR_LIT>' : pool . subnet_id , <EOL> '<STR_LIT>' : pool . protocol , <EOL> '<STR_LIT>' : pool . lb_method , <EOL> '<STR_LIT>' : pool . admin_state_up } <EOL> api . lbaas . pool_create ( <EOL> IsA ( http . HttpRequest ) , ** form_data ) . AndReturn ( pool ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( reverse ( self . ADDPOOL_PATH ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_add_pool_get ( self ) : <EOL> self . _test_add_pool_get ( ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_add_pool_get_provider_list_exception ( self ) : <EOL> self . _test_add_pool_get ( with_provider_exception = True ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_add_pool_get_without_service_type_support ( self ) : <EOL> self . _test_add_pool_get ( with_service_type = False ) <EOL> def _test_add_pool_get ( self , with_service_type = True , <EOL> with_provider_exception = False ) : <EOL> subnet = self . subnets . first ( ) <EOL> default_provider = self . providers . first ( ) [ '<STR_LIT:name>' ] <EOL> networks = [ { '<STR_LIT>' : [ subnet , ] } , ] <EOL> api . neutron . is_extension_supported ( <EOL> IsA ( http . HttpRequest ) , '<STR_LIT>' ) . AndReturn ( with_service_type ) <EOL> api . neutron . network_list_for_tenant ( <EOL> IsA ( http . HttpRequest ) , self . tenant . id ) . AndReturn ( networks ) <EOL> if with_service_type : <EOL> prov_list = api . neutron . provider_list ( IsA ( http . HttpRequest ) ) <EOL> if with_provider_exception : <EOL> prov_list . AndRaise ( self . exceptions . neutron ) <EOL> else : <EOL> prov_list . AndReturn ( self . providers . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . ADDPOOL_PATH ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . AddPool . name ) <EOL> expected_objs = [ '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> if not with_service_type : <EOL> self . assertNotContains ( res , default_provider ) <EOL> self . assertContains ( res , ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> elif with_provider_exception : <EOL> self . assertNotContains ( res , default_provider ) <EOL> self . assertContains ( res , '<STR_LIT>' ) <EOL> else : <EOL> self . assertContains ( res , default_provider ) <EOL> def test_add_vip_post ( self ) : <EOL> self . _test_add_vip_post ( ) <EOL> def test_add_vip_post_no_connection_limit ( self ) : <EOL> self . _test_add_vip_post ( with_conn_limit = False ) <EOL> def test_add_vip_post_with_diff_subnet ( self ) : <EOL> self . _test_add_vip_post ( with_diff_subnet = True ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> api . neutron : ( <EOL> '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def _test_add_vip_post ( self , with_diff_subnet = False , with_conn_limit = True ) : <EOL> vip = self . vips . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> pool = self . pools . first ( ) <EOL> networks = [ { '<STR_LIT>' : [ subnet , ] } , ] <EOL> api . lbaas . pool_get ( <EOL> IsA ( http . HttpRequest ) , pool . id ) . MultipleTimes ( ) . AndReturn ( pool ) <EOL> api . neutron . subnet_get ( <EOL> IsA ( http . HttpRequest ) , subnet . id ) . AndReturn ( subnet ) <EOL> api . neutron . network_list_for_tenant ( <EOL> IsA ( http . HttpRequest ) , self . tenant . id ) . AndReturn ( networks ) <EOL> params = { '<STR_LIT:name>' : vip . name , <EOL> '<STR_LIT:description>' : vip . description , <EOL> '<STR_LIT>' : vip . pool_id , <EOL> '<STR_LIT:address>' : vip . address , <EOL> '<STR_LIT>' : pool . subnet_id , <EOL> '<STR_LIT>' : vip . protocol_port , <EOL> '<STR_LIT>' : vip . protocol , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT:type>' ] , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : vip . admin_state_up , <EOL> } <EOL> if with_conn_limit : <EOL> params [ '<STR_LIT>' ] = vip . connection_limit <EOL> if with_diff_subnet : <EOL> params [ '<STR_LIT>' ] = vip . subnet_id <EOL> api . lbaas . vip_create ( <EOL> IsA ( http . HttpRequest ) , ** params ) . AndReturn ( vip ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { <EOL> '<STR_LIT:name>' : vip . name , <EOL> '<STR_LIT:description>' : vip . description , <EOL> '<STR_LIT>' : vip . pool_id , <EOL> '<STR_LIT:address>' : vip . address , <EOL> '<STR_LIT>' : pool . subnet_id , <EOL> '<STR_LIT>' : vip . protocol_port , <EOL> '<STR_LIT>' : vip . protocol , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT:type>' ] . lower ( ) , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : vip . admin_state_up } <EOL> if with_conn_limit : <EOL> form_data [ '<STR_LIT>' ] = vip . connection_limit <EOL> if with_diff_subnet : <EOL> params [ '<STR_LIT>' ] = vip . subnet_id <EOL> res = self . client . post ( <EOL> reverse ( self . ADDVIP_PATH , args = ( pool . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) , <EOL> api . neutron : ( <EOL> '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def test_add_vip_post_with_error ( self ) : <EOL> vip = self . vips . first ( ) <EOL> subnet = self . subnets . first ( ) <EOL> pool = self . pools . first ( ) <EOL> networks = [ { '<STR_LIT>' : [ subnet , ] } , ] <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . neutron . subnet_get ( <EOL> IsA ( http . HttpRequest ) , subnet . id ) . AndReturn ( subnet ) <EOL> api . neutron . network_list_for_tenant ( <EOL> IsA ( http . HttpRequest ) , self . tenant . id ) . AndReturn ( networks ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { <EOL> '<STR_LIT:name>' : vip . name , <EOL> '<STR_LIT:description>' : vip . description , <EOL> '<STR_LIT>' : vip . pool_id , <EOL> '<STR_LIT:address>' : vip . address , <EOL> '<STR_LIT>' : pool . subnet_id , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : vip . protocol , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT:type>' ] . lower ( ) , <EOL> '<STR_LIT>' : vip . session_persistence [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : - <NUM_LIT:2> , <EOL> '<STR_LIT>' : vip . admin_state_up } <EOL> res = self . client . post ( <EOL> reverse ( self . ADDVIP_PATH , args = ( pool . id , ) ) , form_data ) <EOL> self . assertFormErrors ( res , <NUM_LIT:2> ) <EOL> def test_add_vip_get ( self ) : <EOL> self . _test_add_vip_get ( ) <EOL> def test_add_vip_get_with_diff_subnet ( self ) : <EOL> self . _test_add_vip_get ( with_diff_subnet = True ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) , <EOL> api . neutron : ( <EOL> '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def _test_add_vip_get ( self , with_diff_subnet = False ) : <EOL> subnet = self . subnets . first ( ) <EOL> pool = self . pools . first ( ) <EOL> networks = [ { '<STR_LIT>' : [ subnet , ] } , ] <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . neutron . subnet_get ( <EOL> IsA ( http . HttpRequest ) , subnet . id ) . AndReturn ( subnet ) <EOL> api . neutron . network_list_for_tenant ( <EOL> IsA ( http . HttpRequest ) , self . tenant . id ) . AndReturn ( networks ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . ADDVIP_PATH , args = ( pool . id , ) ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . AddVip . name ) <EOL> expected_objs = [ '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> if with_diff_subnet : <EOL> self . assertNotEqual ( networks [ <NUM_LIT:0> ] , pool . subnet_id ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) } ) <EOL> def test_add_monitor_post ( self ) : <EOL> monitor = self . monitors . first ( ) <EOL> form_data = { '<STR_LIT:type>' : monitor . type , <EOL> '<STR_LIT>' : monitor . delay , <EOL> '<STR_LIT>' : monitor . timeout , <EOL> '<STR_LIT>' : monitor . max_retries , <EOL> '<STR_LIT>' : monitor . http_method , <EOL> '<STR_LIT>' : monitor . url_path , <EOL> '<STR_LIT>' : monitor . expected_codes , <EOL> '<STR_LIT>' : monitor . admin_state_up } <EOL> api . lbaas . pool_health_monitor_create ( <EOL> IsA ( http . HttpRequest ) , ** form_data ) . AndReturn ( monitor ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( reverse ( self . ADDMONITOR_PATH ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> def test_add_monitor_post_with_error ( self ) : <EOL> monitor = self . monitors . first ( ) <EOL> form_data = { '<STR_LIT:type>' : monitor . type , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:11> , <EOL> '<STR_LIT>' : monitor . http_method , <EOL> '<STR_LIT>' : monitor . url_path , <EOL> '<STR_LIT>' : monitor . expected_codes , <EOL> '<STR_LIT>' : monitor . admin_state_up } <EOL> res = self . client . post ( reverse ( self . ADDMONITOR_PATH ) , form_data ) <EOL> self . assertFormErrors ( res , <NUM_LIT:3> ) <EOL> def test_add_monitor_post_with_httpmethod_error ( self ) : <EOL> monitor = self . monitors . first ( ) <EOL> form_data = { '<STR_LIT:type>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : monitor . delay , <EOL> '<STR_LIT>' : monitor . timeout , <EOL> '<STR_LIT>' : monitor . max_retries , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : monitor . admin_state_up } <EOL> res = self . client . post ( reverse ( self . ADDMONITOR_PATH ) , form_data ) <EOL> self . assertFormErrors ( res , <NUM_LIT:3> ) <EOL> def test_add_monitor_get ( self ) : <EOL> res = self . client . get ( reverse ( self . ADDMONITOR_PATH ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . AddMonitor . name ) <EOL> expected_objs = [ '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> def test_add_member_post ( self ) : <EOL> self . _test_add_member_post ( ) <EOL> def test_add_member_post_without_weight ( self ) : <EOL> self . _test_add_member_post ( with_weight = False ) <EOL> def test_add_member_post_without_server_list ( self ) : <EOL> self . _test_add_member_post ( with_server_list = False ) <EOL> def test_add_member_post_multiple_ports ( self ) : <EOL> self . _test_add_member_post ( mult_ports = True ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> api . neutron : ( '<STR_LIT>' , ) , <EOL> api . nova : ( '<STR_LIT>' , ) } ) <EOL> def _test_add_member_post ( self , with_weight = True , with_server_list = True , <EOL> mult_ports = False ) : <EOL> member = self . members . first ( ) <EOL> server1 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> server2 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . nova . server_list ( IsA ( http . HttpRequest ) ) . AndReturn ( <EOL> [ [ server1 , server2 ] , False ] ) <EOL> if with_server_list : <EOL> pool = self . pools . list ( ) [ <NUM_LIT:1> ] <EOL> port1 = self . AttributeDict ( <EOL> { '<STR_LIT>' : [ { '<STR_LIT>' : member . address , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' } ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> api . lbaas . pool_get ( <EOL> IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> if mult_ports : <EOL> port2 = self . AttributeDict ( <EOL> { '<STR_LIT>' : [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' } ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> api . neutron . port_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> device_id = server1 . id ) . AndReturn ( [ port1 , port2 ] ) <EOL> else : <EOL> api . neutron . port_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> device_id = server1 . id ) . AndReturn ( [ port1 , ] ) <EOL> form_data = { '<STR_LIT>' : member . pool_id , <EOL> '<STR_LIT>' : member . protocol_port , <EOL> '<STR_LIT>' : [ server1 . id ] , <EOL> '<STR_LIT>' : member . admin_state_up } <EOL> if with_weight : <EOL> form_data [ '<STR_LIT>' ] = member . weight <EOL> if with_server_list : <EOL> form_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> form_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form_data [ '<STR_LIT:address>' ] = member . address <EOL> api . lbaas . member_create ( IsA ( http . HttpRequest ) , <EOL> ** form_data ) . AndReturn ( member ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( reverse ( self . ADDMEMBER_PATH ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) , <EOL> api . nova : ( '<STR_LIT>' , ) } ) <EOL> def test_add_member_post_with_error ( self ) : <EOL> member = self . members . first ( ) <EOL> server1 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> server2 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . nova . server_list ( IsA ( http . HttpRequest ) ) . AndReturn ( [ [ server1 , <EOL> server2 ] , <EOL> False ] ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { '<STR_LIT>' : member . pool_id , <EOL> '<STR_LIT:address>' : member . address , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ server1 . id ] , <EOL> '<STR_LIT>' : member . admin_state_up } <EOL> res = self . client . post ( reverse ( self . ADDMEMBER_PATH ) , form_data ) <EOL> self . assertFormErrors ( res , <NUM_LIT:2> ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) , <EOL> api . nova : ( '<STR_LIT>' , ) } ) <EOL> def test_add_member_get ( self ) : <EOL> server1 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> server2 = self . AttributeDict ( { '<STR_LIT:id>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . nova . server_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( [ [ server1 , server2 ] , False ] ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . ADDMEMBER_PATH ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . AddMember . name ) <EOL> expected_objs = [ '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_update_pool_post ( self ) : <EOL> pool = self . pools . first ( ) <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> data = { '<STR_LIT:name>' : pool . name , <EOL> '<STR_LIT:description>' : pool . description , <EOL> '<STR_LIT>' : pool . lb_method , <EOL> '<STR_LIT>' : pool . admin_state_up } <EOL> api . lbaas . pool_update ( IsA ( http . HttpRequest ) , pool . id , pool = data ) . AndReturn ( pool ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = data . copy ( ) <EOL> form_data [ '<STR_LIT>' ] = pool . id <EOL> res = self . client . post ( <EOL> reverse ( self . UPDATEPOOL_PATH , args = ( pool . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) } ) <EOL> def test_update_pool_get ( self ) : <EOL> pool = self . pools . first ( ) <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . UPDATEPOOL_PATH , args = ( pool . id , ) ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update_vip_post ( self ) : <EOL> vip = self . vips . first ( ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . lbaas . vip_get ( IsA ( http . HttpRequest ) , vip . id ) . AndReturn ( vip ) <EOL> data = { '<STR_LIT:name>' : vip . name , <EOL> '<STR_LIT:description>' : vip . description , <EOL> '<STR_LIT>' : vip . pool_id , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : vip . connection_limit , <EOL> '<STR_LIT>' : vip . admin_state_up } <EOL> api . lbaas . vip_update ( IsA ( http . HttpRequest ) , vip . id , vip = data ) . AndReturn ( vip ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = data . copy ( ) <EOL> form_data [ '<STR_LIT>' ] = vip . id <EOL> res = self . client . post ( <EOL> reverse ( self . UPDATEVIP_PATH , args = ( vip . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_update_vip_get ( self ) : <EOL> vip = self . vips . first ( ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . lbaas . vip_get ( IsA ( http . HttpRequest ) , vip . id ) . AndReturn ( vip ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . UPDATEVIP_PATH , args = ( vip . id , ) ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update_member_post ( self ) : <EOL> member = self . members . first ( ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . lbaas . member_get ( IsA ( http . HttpRequest ) , member . id ) . AndReturn ( member ) <EOL> data = { '<STR_LIT>' : member . pool_id , <EOL> '<STR_LIT>' : member . weight , <EOL> '<STR_LIT>' : member . admin_state_up } <EOL> api . lbaas . member_update ( IsA ( http . HttpRequest ) , member . id , member = data ) . AndReturn ( member ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = data . copy ( ) <EOL> form_data [ '<STR_LIT>' ] = member . id <EOL> res = self . client . post ( <EOL> reverse ( self . UPDATEMEMBER_PATH , args = ( member . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_update_member_get ( self ) : <EOL> member = self . members . first ( ) <EOL> api . lbaas . pool_list ( IsA ( http . HttpRequest ) , tenant_id = self . tenant . id ) . AndReturn ( self . pools . list ( ) ) <EOL> api . lbaas . member_get ( IsA ( http . HttpRequest ) , member . id ) . AndReturn ( member ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( <EOL> reverse ( self . UPDATEMEMBER_PATH , args = ( member . id , ) ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update_monitor_post ( self ) : <EOL> monitor = self . monitors . first ( ) <EOL> api . lbaas . pool_health_monitor_get ( IsA ( http . HttpRequest ) , monitor . id ) . AndReturn ( monitor ) <EOL> data = { '<STR_LIT>' : monitor . delay , <EOL> '<STR_LIT>' : monitor . timeout , <EOL> '<STR_LIT>' : monitor . max_retries , <EOL> '<STR_LIT>' : monitor . admin_state_up } <EOL> api . lbaas . pool_health_monitor_update ( <EOL> IsA ( http . HttpRequest ) , <EOL> monitor . id , health_monitor = data ) . AndReturn ( monitor ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = data . copy ( ) <EOL> form_data [ '<STR_LIT>' ] = monitor . id <EOL> res = self . client . post ( <EOL> reverse ( self . UPDATEMONITOR_PATH , args = ( monitor . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , ) } ) <EOL> def test_update_monitor_get ( self ) : <EOL> monitor = self . monitors . first ( ) <EOL> api . lbaas . pool_health_monitor_get ( IsA ( http . HttpRequest ) , monitor . id ) . AndReturn ( monitor ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( <EOL> reverse ( self . UPDATEMONITOR_PATH , args = ( monitor . id , ) ) ) <EOL> self . assertTemplateUsed ( <EOL> res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_add_pool_monitor_association_post ( self ) : <EOL> pool = self . pools . list ( ) [ <NUM_LIT:1> ] <EOL> monitors = self . monitors . list ( ) <EOL> monitor = self . monitors . list ( ) [ <NUM_LIT:1> ] <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> tenant_id = self . tenant . id ) . AndReturn ( monitors ) <EOL> form_data = { '<STR_LIT>' : monitor . id , <EOL> '<STR_LIT>' : pool . id , <EOL> '<STR_LIT>' : pool . health_monitors , <EOL> '<STR_LIT>' : pool . name } <EOL> api . lbaas . pool_monitor_association_create ( <EOL> IsA ( http . HttpRequest ) , ** form_data ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( <EOL> reverse ( self . ADDASSOC_PATH , args = ( pool . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_add_pool_monitor_association_get ( self ) : <EOL> pool = self . pools . first ( ) <EOL> monitors = self . monitors . list ( ) <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) , <EOL> tenant_id = self . tenant . id ) . AndReturn ( monitors ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( self . ADDASSOC_PATH , args = ( pool . id , ) ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . AddPMAssociation . name ) <EOL> expected_objs = [ '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_pool_monitor_association_post ( self ) : <EOL> pool = self . pools . first ( ) <EOL> monitors = self . monitors . list ( ) <EOL> monitor = monitors [ <NUM_LIT:0> ] <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( monitors ) <EOL> form_data = { '<STR_LIT>' : monitor . id , <EOL> '<STR_LIT>' : pool . id , <EOL> '<STR_LIT>' : pool . health_monitors , <EOL> '<STR_LIT>' : pool . name } <EOL> api . lbaas . pool_monitor_association_delete ( <EOL> IsA ( http . HttpRequest ) , ** form_data ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( <EOL> reverse ( self . DELETEASSOC_PATH , args = ( pool . id , ) ) , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , str ( self . INDEX_URL ) ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_pool_monitor_association_get ( self ) : <EOL> pool = self . pools . first ( ) <EOL> monitors = self . monitors . list ( ) <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . lbaas . pool_health_monitor_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( monitors ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( <EOL> reverse ( self . DELETEASSOC_PATH , args = ( pool . id , ) ) ) <EOL> workflow = res . context [ '<STR_LIT>' ] <EOL> self . assertTemplateUsed ( res , views . WorkflowView . template_name ) <EOL> self . assertEqual ( workflow . name , workflows . DeletePMAssociation . name ) <EOL> expected_objs = [ <EOL> '<STR_LIT>' , ] <EOL> self . assertQuerysetEqual ( workflow . steps , expected_objs ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_pool ( self ) : <EOL> self . set_up_expect ( ) <EOL> pool = self . pools . first ( ) <EOL> api . lbaas . pool_delete ( IsA ( http . HttpRequest ) , pool . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % pool . id } <EOL> res = self . client . post ( self . INDEX_URL , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_delete_vip ( self ) : <EOL> self . set_up_expect ( ) <EOL> pool = self . pools . first ( ) <EOL> vip = self . vips . first ( ) <EOL> api . lbaas . pool_get ( IsA ( http . HttpRequest ) , pool . id ) . AndReturn ( pool ) <EOL> api . lbaas . vip_delete ( IsA ( http . HttpRequest ) , vip . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % pool . id } <EOL> res = self . client . post ( self . INDEX_URL , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_member ( self ) : <EOL> self . set_up_expect ( ) <EOL> member = self . members . first ( ) <EOL> api . lbaas . member_delete ( IsA ( http . HttpRequest ) , member . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % member . id } <EOL> res = self . client . post ( self . INDEX_URL , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . lbaas : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_monitor ( self ) : <EOL> self . set_up_expect ( ) <EOL> monitor = self . monitors . first ( ) <EOL> api . lbaas . pool_health_monitor_delete ( IsA ( http . HttpRequest ) , monitor . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % monitor . id } <EOL> res = self . client . post ( self . INDEX_URL , form_data ) <EOL> self . assertNoFormErrors ( res ) </s>
