<s> import sys <EOL> import unittest <EOL> from libcloud . compute . base import Node <EOL> from libcloud . compute . types import NodeState <EOL> from libcloud . loadbalancer . base import Member , Algorithm <EOL> from libcloud . loadbalancer . drivers . slb import SLBDriver , SLBLoadBalancerHttpListener , SLBLoadBalancerHttpsListener , SLBLoadBalancerTcpListener , SLBLoadBalancerUdpListener <EOL> from libcloud . loadbalancer . types import State <EOL> from libcloud . test . file_fixtures import LoadBalancerFileFixtures <EOL> from libcloud . test import MockHttpTestCase <EOL> from libcloud . test . secrets import LB_SLB_PARAMS <EOL> from libcloud . utils . py3 import httplib <EOL> class SLBDriverTestCases ( unittest . TestCase ) : <EOL> region = LB_SLB_PARAMS [ <NUM_LIT:2> ] <EOL> def setUp ( self ) : <EOL> SLBMockHttp . test = self <EOL> SLBDriver . connectionCls . conn_classes = ( None , <EOL> SLBMockHttp ) <EOL> SLBMockHttp . type = None <EOL> SLBMockHttp . use_param = '<STR_LIT>' <EOL> self . driver = SLBDriver ( * LB_SLB_PARAMS ) <EOL> def test_list_protocols ( self ) : <EOL> protocols = self . driver . list_protocols ( ) <EOL> self . assertEqual ( <NUM_LIT:4> , len ( protocols ) ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:http>' , '<STR_LIT>' ] <EOL> diff = set ( expected ) - set ( protocols ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( diff ) ) <EOL> def test_list_balancers ( self ) : <EOL> balancers = self . driver . list_balancers ( ) <EOL> self . assertEqual ( len ( balancers ) , <NUM_LIT:1> ) <EOL> balancer = balancers [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , balancer . id ) <EOL> self . assertEqual ( '<STR_LIT:abc>' , balancer . name ) <EOL> self . assertEqual ( State . RUNNING , balancer . state ) <EOL> self . assertEqual ( '<STR_LIT>' , balancer . ip ) <EOL> self . assertTrue ( balancer . port is None ) <EOL> self . assertEqual ( self . driver , balancer . driver ) <EOL> expected_extra = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . _validate_extras ( expected_extra , balancer . extra ) <EOL> def _validate_extras ( self , expected , actual ) : <EOL> self . assertTrue ( actual is not None ) <EOL> for key , value in iter ( expected . items ( ) ) : <EOL> self . assertTrue ( key in actual ) <EOL> self . assertEqual ( value , actual [ key ] , ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> { '<STR_LIT:key>' : key , <EOL> '<STR_LIT>' : value , <EOL> '<STR_LIT>' : actual [ key ] } ) ) <EOL> def test_list_balancers_with_ids ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . balancer_ids = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> balancers = self . driver . list_balancers ( <EOL> ex_balancer_ids = self . balancer_ids ) <EOL> self . assertTrue ( balancers is not None ) <EOL> def test_list_balancers_with_ex_filters ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . ex_filters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> balancers = self . driver . list_balancers ( ex_filters = self . ex_filters ) <EOL> self . assertTrue ( balancers is not None ) <EOL> def test_get_balancer ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . assertEqual ( balancer . id , '<STR_LIT>' ) <EOL> self . assertEqual ( balancer . name , '<STR_LIT:abc>' ) <EOL> self . assertEqual ( balancer . state , State . RUNNING ) <EOL> def test_destroy_balancer ( self ) : <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . assertTrue ( self . driver . destroy_balancer ( balancer ) ) <EOL> def test_create_balancer ( self ) : <EOL> self . name = '<STR_LIT>' <EOL> self . port = <NUM_LIT> <EOL> self . protocol = '<STR_LIT:http>' <EOL> self . algorithm = Algorithm . WEIGHTED_ROUND_ROBIN <EOL> self . extra = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . members = [ Member ( '<STR_LIT>' , None , None ) ] <EOL> balancer = self . driver . create_balancer ( name = self . name , port = self . port , <EOL> protocol = self . protocol , <EOL> algorithm = self . algorithm , <EOL> members = self . members , <EOL> ** self . extra ) <EOL> self . assertEqual ( balancer . name , self . name ) <EOL> self . assertEqual ( balancer . port , self . port ) <EOL> self . assertEqual ( balancer . state , State . UNKNOWN ) <EOL> def test_create_balancer_no_port_exception ( self ) : <EOL> self . assertRaises ( AttributeError , self . driver . create_balancer , <EOL> None , None , '<STR_LIT:http>' , Algorithm . WEIGHTED_ROUND_ROBIN , <EOL> None ) <EOL> def test_create_balancer_unsupport_protocol_exception ( self ) : <EOL> self . assertRaises ( AttributeError , self . driver . create_balancer , <EOL> None , <NUM_LIT> , '<STR_LIT>' , Algorithm . WEIGHTED_ROUND_ROBIN , <EOL> None ) <EOL> def test_create_balancer_multiple_member_ports_exception ( self ) : <EOL> members = [ Member ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) , <EOL> Member ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) ] <EOL> self . assertRaises ( AttributeError , self . driver . create_balancer , <EOL> None , <NUM_LIT> , '<STR_LIT:http>' , Algorithm . WEIGHTED_ROUND_ROBIN , <EOL> members ) <EOL> def test_create_balancer_bandwidth_value_error ( self ) : <EOL> self . assertRaises ( AttributeError , self . driver . create_balancer , <EOL> None , <NUM_LIT> , '<STR_LIT:http>' , Algorithm . WEIGHTED_ROUND_ROBIN , <EOL> None , ex_bandwidth = '<STR_LIT>' ) <EOL> def test_create_balancer_paybybandwidth_without_bandwidth_exception ( self ) : <EOL> self . assertRaises ( AttributeError , self . driver . create_balancer , <EOL> None , <NUM_LIT> , '<STR_LIT:http>' , Algorithm . WEIGHTED_ROUND_ROBIN , <EOL> None , ex_internet_charge_type = '<STR_LIT>' ) <EOL> def test_balancer_list_members ( self ) : <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> members = balancer . list_members ( ) <EOL> self . assertEqual ( len ( members ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( members [ <NUM_LIT:0> ] . balancer , balancer ) <EOL> self . assertEqual ( '<STR_LIT>' , members [ <NUM_LIT:0> ] . id ) <EOL> def test_balancer_list_listeners ( self ) : <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> listeners = self . driver . ex_list_listeners ( balancer ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( listeners ) ) <EOL> listener = listeners [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , listener . port ) <EOL> def test_balancer_detach_member ( self ) : <EOL> self . balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . member = Member ( '<STR_LIT>' , None , None ) <EOL> self . assertTrue ( self . balancer . detach_member ( self . member ) ) <EOL> def test_balancer_attach_compute_node ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . node = Node ( id = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> state = NodeState . RUNNING , <EOL> public_ips = [ '<STR_LIT>' ] , private_ips = [ '<STR_LIT>' ] , <EOL> driver = self . driver ) <EOL> member = self . driver . balancer_attach_compute_node ( <EOL> self . balancer , self . node ) <EOL> self . assertEqual ( self . node . id , member . id ) <EOL> self . assertEqual ( self . node . public_ips [ <NUM_LIT:0> ] , member . ip ) <EOL> self . assertEqual ( self . balancer . port , member . port ) <EOL> def test_ex_create_listener ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . backend_port = <NUM_LIT> <EOL> self . protocol = '<STR_LIT:http>' <EOL> self . algorithm = Algorithm . WEIGHTED_ROUND_ROBIN <EOL> self . bandwidth = <NUM_LIT:1> <EOL> self . extra = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertTrue ( self . driver . ex_create_listener ( self . balancer , <EOL> self . backend_port , <EOL> self . protocol , <EOL> self . algorithm , <EOL> self . bandwidth , <EOL> ** self . extra ) ) <EOL> def test_ex_create_listener_override_port ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . backend_port = <NUM_LIT> <EOL> self . protocol = '<STR_LIT:http>' <EOL> self . algorithm = Algorithm . WEIGHTED_ROUND_ROBIN <EOL> self . bandwidth = <NUM_LIT:1> <EOL> self . extra = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> self . assertTrue ( self . driver . ex_create_listener ( self . balancer , <EOL> self . backend_port , <EOL> self . protocol , <EOL> self . algorithm , <EOL> self . bandwidth , <EOL> ** self . extra ) ) <EOL> def test_ex_start_listener ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . port = <NUM_LIT> <EOL> self . assertTrue ( self . driver . ex_start_listener ( balancer , self . port ) ) <EOL> def test_ex_stop_listener ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> balancer = self . driver . get_balancer ( balancer_id = '<STR_LIT>' ) <EOL> self . port = <NUM_LIT> <EOL> self . assertTrue ( self . driver . ex_stop_listener ( balancer , self . port ) ) <EOL> def test_ex_upload_certificate ( self ) : <EOL> self . name = '<STR_LIT>' <EOL> self . cert = '<STR_LIT>' <EOL> self . key = '<STR_LIT>' <EOL> certificate = self . driver . ex_upload_certificate ( self . name , self . cert , <EOL> self . key ) <EOL> self . assertEqual ( self . name , certificate . name ) <EOL> self . assertEqual ( '<STR_LIT>' , certificate . fingerprint ) <EOL> def test_ex_list_certificates ( self ) : <EOL> certs = self . driver . ex_list_certificates ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( certs ) ) <EOL> cert = certs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , cert . id ) <EOL> self . assertEqual ( '<STR_LIT>' , cert . name ) <EOL> self . assertEqual ( '<STR_LIT>' , cert . fingerprint ) <EOL> def test_ex_list_certificates_ids ( self ) : <EOL> SLBMockHttp . type = '<STR_LIT>' <EOL> self . cert_ids = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> certs = self . driver . ex_list_certificates ( certificate_ids = self . cert_ids ) <EOL> self . assertTrue ( certs is not None ) <EOL> def test_ex_delete_certificate ( self ) : <EOL> self . cert_id = '<STR_LIT>' <EOL> self . assertTrue ( self . driver . ex_delete_certificate ( self . cert_id ) ) <EOL> def test_ex_set_certificate_name ( self ) : <EOL> self . cert_id = '<STR_LIT>' <EOL> self . cert_name = '<STR_LIT>' <EOL> self . assertTrue ( self . driver . ex_set_certificate_name ( self . cert_id , <EOL> self . cert_name ) ) <EOL> class SLBMockHttp ( MockHttpTestCase ) : <EOL> fixtures = LoadBalancerFileFixtures ( '<STR_LIT>' ) <EOL> def _DescribeLoadBalancers ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _list_balancers_ids_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> params = { '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( self . test . balancer_ids ) } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _list_balancers_filters_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> params = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _get_balancer_DescribeLoadBalancers ( self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> return self . _DescribeLoadBalancers ( method , url , body , headers ) <EOL> def _DeleteLoadBalancer ( self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _DescribeLoadBalancerAttribute ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _CreateLoadBalancer ( self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : self . test . name } <EOL> balancer_keys = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> for key in balancer_keys : <EOL> params [ key ] = str ( self . test . extra [ balancer_keys [ key ] ] ) <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _AddBackendServers ( self , method , url , body , headers ) : <EOL> _id = self . test . members [ <NUM_LIT:0> ] . id <EOL> self . assertTrue ( "<STR_LIT>" in url and _id in url ) <EOL> self . assertTrue ( "<STR_LIT>" in url and "<STR_LIT:100>" in url ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _CreateLoadBalancerHTTPListener ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _StartLoadBalancerListener ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _RemoveBackendServers ( self , method , url , body , headers ) : <EOL> _id = self . test . member . id <EOL> servers_json = '<STR_LIT>' % _id <EOL> params = { '<STR_LIT>' : self . test . balancer . id , <EOL> '<STR_LIT>' : servers_json } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _attach_compute_node_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _attach_compute_node_AddBackendServers ( self , method , url , body , <EOL> headers ) : <EOL> _id = self . test . node . id <EOL> self . assertTrue ( "<STR_LIT>" in url and _id in url ) <EOL> self . assertTrue ( "<STR_LIT>" in url and "<STR_LIT:100>" in url ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _create_listener_CreateLoadBalancerHTTPListener ( self , method , url , <EOL> body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . balancer . id , <EOL> '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : str ( self . test . balancer . port ) , <EOL> '<STR_LIT>' : str ( self . test . backend_port ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _create_listener_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _create_listener_override_port_CreateLoadBalancerHTTPListener ( <EOL> self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . balancer . id , <EOL> '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : str ( self . test . extra [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : str ( self . test . backend_port ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _create_listener_override_port_DescribeLoadBalancers ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _start_listener_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> return self . _DescribeLoadBalancers ( method , url , body , headers ) <EOL> def _start_listener_StartLoadBalancerListener ( self , method , url , body , <EOL> headers ) : <EOL> params = { '<STR_LIT>' : str ( self . test . port ) } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> return self . _StartLoadBalancerListener ( method , url , body , headers ) <EOL> def _stop_listener_DescribeLoadBalancers ( self , method , url , body , <EOL> headers ) : <EOL> return self . _DescribeLoadBalancers ( method , url , body , headers ) <EOL> def _stop_listener_StopLoadBalancerListener ( self , method , url , body , <EOL> headers ) : <EOL> params = { '<STR_LIT>' : str ( self . test . port ) } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> return self . _StartLoadBalancerListener ( method , url , body , headers ) <EOL> def _UploadServerCertificate ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _DescribeServerCertificates ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _list_certificates_ids_DescribeServerCertificates ( self , method , url , <EOL> body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( self . test . cert_ids ) } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _DeleteServerCertificate ( self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : self . test . cert_id } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _SetServerCertificateName ( self , method , url , body , headers ) : <EOL> params = { '<STR_LIT>' : self . test . region , <EOL> '<STR_LIT>' : self . test . cert_id , <EOL> '<STR_LIT>' : self . test . cert_name } <EOL> self . assertUrlContainsQueryParams ( url , params ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> class AssertDictMixin ( object ) : <EOL> def assert_dict_equals ( self , expected , actual ) : <EOL> expected_keys = set ( expected . keys ( ) ) <EOL> actual_keys = set ( actual . keys ( ) ) <EOL> self . assertEqual ( len ( expected_keys ) , len ( actual_keys ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( expected_keys - actual_keys ) ) <EOL> for key in expected : <EOL> self . assertEqual ( expected [ key ] , actual [ key ] ) <EOL> class SLBLoadBalancerHttpListenerTestCase ( unittest . TestCase , AssertDictMixin ) : <EOL> def setUp ( self ) : <EOL> self . listener = SLBLoadBalancerHttpListener . create ( <EOL> <NUM_LIT> , <NUM_LIT> , Algorithm . WEIGHTED_ROUND_ROBIN , <NUM_LIT:1> , <EOL> extra = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> def test_get_required_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assert_dict_equals ( expected , <EOL> self . listener . get_required_params ( ) ) <EOL> def test_get_optional_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assert_dict_equals ( expected , self . listener . get_optional_params ( ) ) <EOL> def test_repr ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in str ( self . listener ) ) <EOL> class SLBLoadBalancerHttpsListenerTestCase ( unittest . TestCase , AssertDictMixin ) : <EOL> def setUp ( self ) : <EOL> self . listener = SLBLoadBalancerHttpsListener . create ( <EOL> <NUM_LIT> , <NUM_LIT> , Algorithm . WEIGHTED_ROUND_ROBIN , <NUM_LIT:1> , <EOL> extra = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> def test_get_required_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assert_dict_equals ( expected , <EOL> self . listener . get_required_params ( ) ) <EOL> def test_get_optional_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assert_dict_equals ( expected , self . listener . get_optional_params ( ) ) <EOL> class SLBLoadBalancerTcpListenerTestCase ( unittest . TestCase , AssertDictMixin ) : <EOL> def setUp ( self ) : <EOL> self . listener = SLBLoadBalancerTcpListener . create ( <EOL> <NUM_LIT> , <NUM_LIT> , Algorithm . WEIGHTED_ROUND_ROBIN , <NUM_LIT:1> , <EOL> extra = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> def test_get_required_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> self . assert_dict_equals ( expected , <EOL> self . listener . get_required_params ( ) ) <EOL> def test_get_optional_params ( self ) : <EOL> expected = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assert_dict_equals ( expected , self . listener . get_optional_params ( ) ) <EOL> class SLBLoadBalancerUdpListenerTestCase ( unittest . TestCase , AssertDictMixin ) : <EOL> def setUp ( self ) : <EOL> self . listener = SLBLoadBalancerUdpListener . create ( <EOL> <NUM_LIT> , <NUM_LIT> , Algorithm . WEIGHTED_ROUND_ROBIN , <NUM_LIT:1> , <EOL> extra = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> ) <EOL> def test_get_required_params ( self ) : <EOL> expected = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> self . assert_dict_equals ( expected , <EOL> self . listener . get_required_params ( ) ) <EOL> def test_get_optional_params ( self ) : <EOL> expected = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . assert_dict_equals ( expected , self . listener . get_optional_params ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( unittest . main ( ) ) </s>
