<s> from testtools import TestCase <EOL> from kmip . core . attributes import PrivateKeyUniqueIdentifier <EOL> from kmip . core . enums import AuthenticationSuite <EOL> from kmip . core . enums import ConformanceClause <EOL> from kmip . core . enums import CredentialType <EOL> from kmip . core . enums import ResultStatus as ResultStatusEnum <EOL> from kmip . core . enums import ResultReason as ResultReasonEnum <EOL> from kmip . core . enums import Operation as OperationEnum <EOL> from kmip . core . enums import QueryFunction as QueryFunctionEnum <EOL> from kmip . core . factories . attributes import AttributeFactory <EOL> from kmip . core . factories . credentials import CredentialFactory <EOL> from kmip . core . factories . secrets import SecretFactory <EOL> from kmip . core . messages . messages import RequestBatchItem <EOL> from kmip . core . messages . messages import ResponseBatchItem <EOL> from kmip . core . messages . messages import ResponseMessage <EOL> from kmip . core . messages . contents import Operation <EOL> from kmip . core . messages . contents import ResultStatus <EOL> from kmip . core . messages . contents import ResultReason <EOL> from kmip . core . messages . contents import ResultMessage <EOL> from kmip . core . messages . contents import ProtocolVersion <EOL> from kmip . core . messages . payloads . create_key_pair import CreateKeyPairRequestPayload , CreateKeyPairResponsePayload <EOL> from kmip . core . messages . payloads . discover_versions import DiscoverVersionsRequestPayload , DiscoverVersionsResponsePayload <EOL> from kmip . core . messages . payloads import get_attribute_list <EOL> from kmip . core . messages . payloads . query import QueryRequestPayload , QueryResponsePayload <EOL> from kmip . core . messages . payloads . rekey_key_pair import RekeyKeyPairRequestPayload , RekeyKeyPairResponsePayload <EOL> from kmip . core . misc import Offset <EOL> from kmip . core . misc import QueryFunction <EOL> from kmip . core . misc import ServerInformation <EOL> from kmip . core . misc import VendorIdentification <EOL> from kmip . core . objects import CommonTemplateAttribute <EOL> from kmip . core . objects import PrivateKeyTemplateAttribute <EOL> from kmip . core . objects import PublicKeyTemplateAttribute <EOL> from kmip . services . kmip_client import KMIPProxy <EOL> from kmip . services . results import CreateKeyPairResult <EOL> from kmip . services . results import DiscoverVersionsResult <EOL> from kmip . services . results import GetAttributeListResult <EOL> from kmip . services . results import OperationResult <EOL> from kmip . services . results import QueryResult <EOL> from kmip . services . results import RekeyKeyPairResult <EOL> import kmip . core . utils as utils <EOL> import mock <EOL> import os <EOL> import socket <EOL> import ssl <EOL> class TestKMIPClient ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestKMIPClient , self ) . setUp ( ) <EOL> self . attr_factory = AttributeFactory ( ) <EOL> self . cred_factory = CredentialFactory ( ) <EOL> self . secret_factory = SecretFactory ( ) <EOL> self . client = KMIPProxy ( ) <EOL> KMIP_PORT = <NUM_LIT> <EOL> CA_CERTS_PATH = os . path . normpath ( os . path . join ( os . path . dirname ( <EOL> os . path . abspath ( __file__ ) ) , '<STR_LIT>' ) ) <EOL> self . mock_client = KMIPProxy ( host = "<STR_LIT>" , <EOL> port = KMIP_PORT , ca_certs = CA_CERTS_PATH ) <EOL> self . mock_client . socket = mock . MagicMock ( ) <EOL> self . mock_client . socket . connect = mock . MagicMock ( ) <EOL> self . mock_client . socket . close = mock . MagicMock ( ) <EOL> def tearDown ( self ) : <EOL> super ( TestKMIPClient , self ) . tearDown ( ) <EOL> def test_build_credential ( self ) : <EOL> username = '<STR_LIT:username>' <EOL> password = '<STR_LIT:password>' <EOL> cred_type = CredentialType . USERNAME_AND_PASSWORD <EOL> self . client . username = username <EOL> self . client . password = password <EOL> credential = self . client . _build_credential ( ) <EOL> message = utils . build_er_error ( credential . __class__ , '<STR_LIT:type>' , <EOL> cred_type , <EOL> credential . credential_type . value , <EOL> '<STR_LIT:value>' ) <EOL> self . assertEqual ( CredentialType . USERNAME_AND_PASSWORD , <EOL> credential . credential_type . value , <EOL> message ) <EOL> message = utils . build_er_error ( <EOL> credential . __class__ , '<STR_LIT:type>' , username , <EOL> credential . credential_value . username . value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( username , credential . credential_value . username . value , <EOL> message ) <EOL> message = utils . build_er_error ( <EOL> credential . __class__ , '<STR_LIT:type>' , password , <EOL> credential . credential_value . password . value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( password , credential . credential_value . password . value , <EOL> message ) <EOL> def test_build_credential_no_username ( self ) : <EOL> username = None <EOL> password = '<STR_LIT:password>' <EOL> self . client . username = username <EOL> self . client . password = password <EOL> exception = self . assertRaises ( ValueError , <EOL> self . client . _build_credential ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( exception ) ) <EOL> def test_build_credential_no_password ( self ) : <EOL> username = '<STR_LIT:username>' <EOL> password = None <EOL> self . client . username = username <EOL> self . client . password = password <EOL> exception = self . assertRaises ( ValueError , <EOL> self . client . _build_credential ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( exception ) ) <EOL> def test_build_credential_no_creds ( self ) : <EOL> self . client . username = None <EOL> self . client . password = None <EOL> credential = self . client . _build_credential ( ) <EOL> self . assertEqual ( None , credential ) <EOL> def _test_build_create_key_pair_batch_item ( self , common , private , public ) : <EOL> batch_item = self . client . _build_create_key_pair_batch_item ( <EOL> common_template_attribute = common , <EOL> private_key_template_attribute = private , <EOL> public_key_template_attribute = public ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( RequestBatchItem , batch_item ) <EOL> self . assertIsInstance ( batch_item , RequestBatchItem , msg ) <EOL> operation = batch_item . operation <EOL> msg = base . format ( Operation , operation ) <EOL> self . assertIsInstance ( operation , Operation , msg ) <EOL> operation_enum = operation . value <EOL> msg = base . format ( OperationEnum . CREATE_KEY_PAIR , operation_enum ) <EOL> self . assertEqual ( OperationEnum . CREATE_KEY_PAIR , operation_enum , msg ) <EOL> payload = batch_item . request_payload <EOL> msg = base . format ( CreateKeyPairRequestPayload , payload ) <EOL> self . assertIsInstance ( payload , CreateKeyPairRequestPayload , msg ) <EOL> common_observed = payload . common_template_attribute <EOL> private_observed = payload . private_key_template_attribute <EOL> public_observed = payload . public_key_template_attribute <EOL> msg = base . format ( common , common_observed ) <EOL> self . assertEqual ( common , common_observed , msg ) <EOL> msg = base . format ( private , private_observed ) <EOL> self . assertEqual ( private , private_observed , msg ) <EOL> msg = base . format ( public , public_observed ) <EOL> self . assertEqual ( public , public_observed ) <EOL> def test_build_create_key_pair_batch_item_with_input ( self ) : <EOL> self . _test_build_create_key_pair_batch_item ( <EOL> CommonTemplateAttribute ( ) , <EOL> PrivateKeyTemplateAttribute ( ) , <EOL> PublicKeyTemplateAttribute ( ) ) <EOL> def test_build_create_key_pair_batch_item_no_input ( self ) : <EOL> self . _test_build_create_key_pair_batch_item ( None , None , None ) <EOL> def _test_build_rekey_key_pair_batch_item ( self , uuid , offset , common , <EOL> private , public ) : <EOL> batch_item = self . client . _build_rekey_key_pair_batch_item ( <EOL> private_key_uuid = uuid , offset = offset , <EOL> common_template_attribute = common , <EOL> private_key_template_attribute = private , <EOL> public_key_template_attribute = public ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( RequestBatchItem , batch_item ) <EOL> self . assertIsInstance ( batch_item , RequestBatchItem , msg ) <EOL> operation = batch_item . operation <EOL> msg = base . format ( Operation , operation ) <EOL> self . assertIsInstance ( operation , Operation , msg ) <EOL> operation_enum = operation . value <EOL> msg = base . format ( OperationEnum . REKEY_KEY_PAIR , operation_enum ) <EOL> self . assertEqual ( OperationEnum . REKEY_KEY_PAIR , operation_enum , msg ) <EOL> payload = batch_item . request_payload <EOL> msg = base . format ( RekeyKeyPairRequestPayload , payload ) <EOL> self . assertIsInstance ( payload , RekeyKeyPairRequestPayload , msg ) <EOL> private_key_uuid_observed = payload . private_key_uuid <EOL> offset_observed = payload . offset <EOL> common_observed = payload . common_template_attribute <EOL> private_observed = payload . private_key_template_attribute <EOL> public_observed = payload . public_key_template_attribute <EOL> msg = base . format ( uuid , private_key_uuid_observed ) <EOL> self . assertEqual ( uuid , private_key_uuid_observed , msg ) <EOL> msg = base . format ( offset , offset_observed ) <EOL> self . assertEqual ( offset , offset_observed , msg ) <EOL> msg = base . format ( common , common_observed ) <EOL> self . assertEqual ( common , common_observed , msg ) <EOL> msg = base . format ( private , private_observed ) <EOL> self . assertEqual ( private , private_observed , msg ) <EOL> msg = base . format ( public , public_observed ) <EOL> self . assertEqual ( public , public_observed ) <EOL> def test_build_rekey_key_pair_batch_item_with_input ( self ) : <EOL> self . _test_build_rekey_key_pair_batch_item ( <EOL> PrivateKeyUniqueIdentifier ( ) , Offset ( ) , <EOL> CommonTemplateAttribute ( ) , <EOL> PrivateKeyTemplateAttribute ( ) , <EOL> PublicKeyTemplateAttribute ( ) ) <EOL> def test_build_rekey_key_pair_batch_item_no_input ( self ) : <EOL> self . _test_build_rekey_key_pair_batch_item ( <EOL> None , None , None , None , None ) <EOL> def _test_build_query_batch_item ( self , query_functions ) : <EOL> batch_item = self . client . _build_query_batch_item ( query_functions ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( RequestBatchItem , batch_item ) <EOL> self . assertIsInstance ( batch_item , RequestBatchItem , msg ) <EOL> operation = batch_item . operation <EOL> msg = base . format ( Operation , operation ) <EOL> self . assertIsInstance ( operation , Operation , msg ) <EOL> operation_enum = operation . value <EOL> msg = base . format ( OperationEnum . QUERY , operation_enum ) <EOL> self . assertEqual ( OperationEnum . QUERY , operation_enum , msg ) <EOL> payload = batch_item . request_payload <EOL> if query_functions is None : <EOL> query_functions = list ( ) <EOL> msg = base . format ( QueryRequestPayload , payload ) <EOL> self . assertIsInstance ( payload , QueryRequestPayload , msg ) <EOL> query_functions_observed = payload . query_functions <EOL> self . assertEqual ( query_functions , query_functions_observed ) <EOL> def test_build_query_batch_item_with_input ( self ) : <EOL> self . _test_build_query_batch_item ( <EOL> [ QueryFunction ( QueryFunctionEnum . QUERY_OBJECTS ) ] ) <EOL> def test_build_query_batch_item_without_input ( self ) : <EOL> self . _test_build_query_batch_item ( None ) <EOL> def _test_build_discover_versions_batch_item ( self , protocol_versions ) : <EOL> batch_item = self . client . _build_discover_versions_batch_item ( <EOL> protocol_versions ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( RequestBatchItem , batch_item ) <EOL> self . assertIsInstance ( batch_item , RequestBatchItem , msg ) <EOL> operation = batch_item . operation <EOL> msg = base . format ( Operation , operation ) <EOL> self . assertIsInstance ( operation , Operation , msg ) <EOL> operation_enum = operation . value <EOL> msg = base . format ( OperationEnum . DISCOVER_VERSIONS , operation_enum ) <EOL> self . assertEqual ( OperationEnum . DISCOVER_VERSIONS , operation_enum , msg ) <EOL> payload = batch_item . request_payload <EOL> if protocol_versions is None : <EOL> protocol_versions = list ( ) <EOL> msg = base . format ( DiscoverVersionsRequestPayload , payload ) <EOL> self . assertIsInstance ( payload , DiscoverVersionsRequestPayload , msg ) <EOL> observed = payload . protocol_versions <EOL> msg = base . format ( protocol_versions , observed ) <EOL> self . assertEqual ( protocol_versions , observed , msg ) <EOL> def test_build_discover_versions_batch_item_with_input ( self ) : <EOL> protocol_versions = [ ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ] <EOL> self . _test_build_discover_versions_batch_item ( protocol_versions ) <EOL> def test_build_discover_versions_batch_item_no_input ( self ) : <EOL> protocol_versions = None <EOL> self . _test_build_discover_versions_batch_item ( protocol_versions ) <EOL> def test_build_get_attribute_list_batch_item ( self ) : <EOL> uid = '<STR_LIT>' <EOL> batch_item = self . client . _build_get_attribute_list_batch_item ( uid ) <EOL> self . assertIsInstance ( batch_item , RequestBatchItem ) <EOL> self . assertIsInstance ( batch_item . operation , Operation ) <EOL> self . assertEqual ( <EOL> OperationEnum . GET_ATTRIBUTE_LIST , batch_item . operation . value ) <EOL> self . assertIsInstance ( <EOL> batch_item . request_payload , <EOL> get_attribute_list . GetAttributeListRequestPayload ) <EOL> self . assertEqual ( uid , batch_item . request_payload . uid ) <EOL> def test_process_batch_items ( self ) : <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . CREATE_KEY_PAIR ) , <EOL> response_payload = CreateKeyPairResponsePayload ( ) ) <EOL> response = ResponseMessage ( batch_items = [ batch_item , batch_item ] ) <EOL> results = self . client . _process_batch_items ( response ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( list , results ) <EOL> self . assertIsInstance ( results , list , msg ) <EOL> msg = "<STR_LIT>" + base . format ( <NUM_LIT:2> , len ( results ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( results ) , msg ) <EOL> for result in results : <EOL> msg = base . format ( CreateKeyPairResult , result ) <EOL> self . assertIsInstance ( result , CreateKeyPairResult , msg ) <EOL> def test_process_batch_items_no_batch_items ( self ) : <EOL> response = ResponseMessage ( batch_items = [ ] ) <EOL> results = self . client . _process_batch_items ( response ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( list , results ) <EOL> self . assertIsInstance ( results , list , msg ) <EOL> msg = "<STR_LIT>" + base . format ( <NUM_LIT:0> , len ( results ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( results ) , msg ) <EOL> def test_process_batch_item_with_error ( self ) : <EOL> result_status = ResultStatus ( ResultStatusEnum . OPERATION_FAILED ) <EOL> result_reason = ResultReason ( ResultReasonEnum . INVALID_MESSAGE ) <EOL> result_message = ResultMessage ( "<STR_LIT:message>" ) <EOL> batch_item = ResponseBatchItem ( <EOL> result_status = result_status , <EOL> result_reason = result_reason , <EOL> result_message = result_message ) <EOL> response = ResponseMessage ( batch_items = [ batch_item ] ) <EOL> results = self . client . _process_batch_items ( response ) <EOL> base = "<STR_LIT>" <EOL> msg = "<STR_LIT>" + base . format ( <NUM_LIT:1> , len ( results ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( results ) , msg ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( result , OperationResult ) <EOL> self . assertEqual ( result . result_status , result_status ) <EOL> self . assertEqual ( result . result_reason , result_reason ) <EOL> self . assertEqual ( result . result_message . value , "<STR_LIT:message>" ) <EOL> def test_get_batch_item_processor ( self ) : <EOL> base = "<STR_LIT>" <EOL> expected = self . client . _process_create_key_pair_batch_item <EOL> observed = self . client . _get_batch_item_processor ( <EOL> OperationEnum . CREATE_KEY_PAIR ) <EOL> msg = base . format ( expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> expected = self . client . _process_rekey_key_pair_batch_item <EOL> observed = self . client . _get_batch_item_processor ( <EOL> OperationEnum . REKEY_KEY_PAIR ) <EOL> msg = base . format ( expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> self . assertRaisesRegexp ( ValueError , "<STR_LIT>" , <EOL> self . client . _get_batch_item_processor , <EOL> <NUM_LIT> ) <EOL> expected = self . client . _process_get_attribute_list_batch_item <EOL> observed = self . client . _get_batch_item_processor ( <EOL> OperationEnum . GET_ATTRIBUTE_LIST ) <EOL> self . assertEqual ( expected , observed ) <EOL> def _test_equality ( self , expected , observed ) : <EOL> msg = "<STR_LIT>" . format ( expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> def test_process_create_key_pair_batch_item ( self ) : <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . CREATE_KEY_PAIR ) , <EOL> response_payload = CreateKeyPairResponsePayload ( ) ) <EOL> result = self . client . _process_create_key_pair_batch_item ( batch_item ) <EOL> msg = "<STR_LIT>" . format ( CreateKeyPairResult , result ) <EOL> self . assertIsInstance ( result , CreateKeyPairResult , msg ) <EOL> def test_process_rekey_key_pair_batch_item ( self ) : <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . REKEY_KEY_PAIR ) , <EOL> response_payload = RekeyKeyPairResponsePayload ( ) ) <EOL> result = self . client . _process_rekey_key_pair_batch_item ( batch_item ) <EOL> msg = "<STR_LIT>" . format ( RekeyKeyPairResult , result ) <EOL> self . assertIsInstance ( result , RekeyKeyPairResult , msg ) <EOL> def _test_process_query_batch_item ( <EOL> self , <EOL> operations , <EOL> object_types , <EOL> vendor_identification , <EOL> server_information , <EOL> application_namespaces , <EOL> extension_information ) : <EOL> payload = QueryResponsePayload ( <EOL> operations , <EOL> object_types , <EOL> vendor_identification , <EOL> server_information , <EOL> application_namespaces , <EOL> extension_information ) <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . QUERY ) , <EOL> response_payload = payload ) <EOL> result = self . client . _process_query_batch_item ( batch_item ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( QueryResult , result ) <EOL> self . assertIsInstance ( result , QueryResult , msg ) <EOL> if operations is None : <EOL> operations = list ( ) <EOL> if object_types is None : <EOL> object_types = list ( ) <EOL> if application_namespaces is None : <EOL> application_namespaces = list ( ) <EOL> if extension_information is None : <EOL> extension_information = list ( ) <EOL> self . _test_equality ( operations , result . operations ) <EOL> self . _test_equality ( object_types , result . object_types ) <EOL> self . _test_equality ( <EOL> vendor_identification , result . vendor_identification ) <EOL> self . _test_equality ( server_information , result . server_information ) <EOL> self . _test_equality ( <EOL> application_namespaces , result . application_namespaces ) <EOL> self . _test_equality ( <EOL> extension_information , result . extension_information ) <EOL> def test_process_query_batch_item_with_results ( self ) : <EOL> self . _test_process_query_batch_item ( <EOL> list ( ) , <EOL> list ( ) , <EOL> VendorIdentification ( ) , <EOL> ServerInformation ( ) , <EOL> list ( ) , <EOL> list ( ) ) <EOL> def test_process_query_batch_item_without_results ( self ) : <EOL> self . _test_process_query_batch_item ( None , None , None , None , None , None ) <EOL> def _test_process_discover_versions_batch_item ( self , protocol_versions ) : <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . DISCOVER_VERSIONS ) , <EOL> response_payload = DiscoverVersionsResponsePayload ( <EOL> protocol_versions ) ) <EOL> result = self . client . _process_discover_versions_batch_item ( batch_item ) <EOL> base = "<STR_LIT>" <EOL> msg = base . format ( DiscoverVersionsResult , result ) <EOL> self . assertIsInstance ( result , DiscoverVersionsResult , msg ) <EOL> if protocol_versions is None : <EOL> protocol_versions = list ( ) <EOL> msg = base . format ( protocol_versions , result . protocol_versions ) <EOL> self . assertEqual ( protocol_versions , result . protocol_versions , msg ) <EOL> def test_process_discover_versions_batch_item_with_results ( self ) : <EOL> protocol_versions = [ ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ] <EOL> self . _test_process_discover_versions_batch_item ( protocol_versions ) <EOL> def test_process_discover_versions_batch_item_no_results ( self ) : <EOL> protocol_versions = None <EOL> self . _test_process_discover_versions_batch_item ( protocol_versions ) <EOL> def test_process_get_attribute_list_batch_item ( self ) : <EOL> uid = '<STR_LIT>' <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> payload = get_attribute_list . GetAttributeListResponsePayload ( <EOL> uid = uid , attribute_names = names ) <EOL> batch_item = ResponseBatchItem ( <EOL> operation = Operation ( OperationEnum . GET_ATTRIBUTE_LIST ) , <EOL> response_payload = payload ) <EOL> result = self . client . _process_get_attribute_list_batch_item ( batch_item ) <EOL> self . assertIsInstance ( result , GetAttributeListResult ) <EOL> self . assertEqual ( uid , result . uid ) <EOL> self . assertEqual ( names , result . names ) <EOL> def test_host_list_import_string ( self ) : <EOL> """<STR_LIT>""" <EOL> host_list_string = '<STR_LIT>' <EOL> host_list_expected = [ '<STR_LIT:127.0.0.1>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . client . _set_variables ( host = host_list_string , <EOL> port = None , keyfile = None , certfile = None , <EOL> cert_reqs = None , ssl_version = None , <EOL> ca_certs = None , <EOL> do_handshake_on_connect = False , <EOL> suppress_ragged_eofs = None , username = None , <EOL> password = None , timeout = None ) <EOL> self . assertEqual ( host_list_expected , self . client . host_list ) <EOL> def test_host_is_invalid_input ( self ) : <EOL> """<STR_LIT>""" <EOL> host = <NUM_LIT> <EOL> expected_error = TypeError <EOL> kwargs = { '<STR_LIT:host>' : host , '<STR_LIT:port>' : None , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : None , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , '<STR_LIT:username>' : None , <EOL> '<STR_LIT:password>' : None , '<STR_LIT>' : None } <EOL> self . assertRaises ( expected_error , self . client . _set_variables , <EOL> ** kwargs ) <EOL> @ mock . patch . object ( KMIPProxy , '<STR_LIT>' ) <EOL> def test_open_server_conn_failover_fail ( self , mock_create_socket ) : <EOL> """<STR_LIT>""" <EOL> mock_create_socket . return_value = mock . MagicMock ( ) <EOL> self . mock_client . socket . connect . side_effect = [ Exception , Exception ] <EOL> self . assertRaises ( Exception , self . mock_client . open ) <EOL> @ mock . patch . object ( KMIPProxy , '<STR_LIT>' ) <EOL> def test_open_server_conn_failover_succeed ( self , mock_create_socket ) : <EOL> """<STR_LIT>""" <EOL> mock_create_socket . return_value = mock . MagicMock ( ) <EOL> self . mock_client . socket . connect . side_effect = [ Exception , None ] <EOL> self . mock_client . open ( ) <EOL> self . assertEqual ( '<STR_LIT>' , self . mock_client . host ) <EOL> def test_socket_ssl_wrap ( self ) : <EOL> """<STR_LIT>""" <EOL> sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . client . _create_socket ( sock ) <EOL> self . assertEqual ( ssl . SSLSocket , type ( self . client . socket ) ) <EOL> class TestClientProfileInformation ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestClientProfileInformation , self ) . setUp ( ) <EOL> self . client = KMIPProxy ( ) <EOL> self . conformance_clauses = [ ConformanceClause . DISCOVER_VERSIONS ] <EOL> self . authentication_suites = [ AuthenticationSuite . BASIC ] <EOL> self . client . conformance_clauses = self . conformance_clauses <EOL> self . client . authentication_suites = self . authentication_suites <EOL> def tearDown ( self ) : <EOL> super ( TestClientProfileInformation , self ) . tearDown ( ) <EOL> def test_get_supported_conformance_clauses ( self ) : <EOL> """<STR_LIT>""" <EOL> conformance_clauses = self . client . get_supported_conformance_clauses ( ) <EOL> self . assertEqual ( self . conformance_clauses , conformance_clauses ) <EOL> def test_get_supported_authentication_suites ( self ) : <EOL> """<STR_LIT>""" <EOL> auth_suites = self . client . get_supported_authentication_suites ( ) <EOL> self . assertEqual ( self . authentication_suites , auth_suites ) <EOL> def test_is_conformance_clause_supported_with_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> clause = ConformanceClause . DISCOVER_VERSIONS <EOL> supported = self . client . is_conformance_clause_supported ( clause ) <EOL> self . assertTrue ( supported ) <EOL> def test_is_conformance_clause_supported_with_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> clause = ConformanceClause . BASELINE <EOL> supported = self . client . is_conformance_clause_supported ( clause ) <EOL> self . assertFalse ( supported ) <EOL> def test_is_authentication_suite_supported_with_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> suite = AuthenticationSuite . BASIC <EOL> supported = self . client . is_authentication_suite_supported ( suite ) <EOL> self . assertTrue ( supported ) <EOL> def test_is_authentication_suite_supported_with_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> suite = AuthenticationSuite . TLS12 <EOL> supported = self . client . is_authentication_suite_supported ( suite ) <EOL> self . assertFalse ( supported ) <EOL> def test_is_profile_supported ( self ) : <EOL> """<STR_LIT>""" <EOL> supported = self . client . is_profile_supported ( <EOL> ConformanceClause . DISCOVER_VERSIONS , <EOL> AuthenticationSuite . BASIC ) <EOL> self . assertTrue ( supported ) <EOL> def test_is_profile_supported_with_invalid_conformance_clause ( self ) : <EOL> """<STR_LIT>""" <EOL> supported = self . client . is_profile_supported ( <EOL> ConformanceClause . BASELINE , <EOL> AuthenticationSuite . BASIC ) <EOL> self . assertFalse ( supported ) <EOL> def test_is_profile_supported_with_invalid_authentication_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> supported = self . client . is_profile_supported ( <EOL> ConformanceClause . DISCOVER_VERSIONS , <EOL> AuthenticationSuite . TLS12 ) <EOL> self . assertFalse ( supported ) <EOL> def test_is_profile_supported_with_invalid_profile_components ( self ) : <EOL> """<STR_LIT>""" <EOL> supported = self . client . is_profile_supported ( <EOL> ConformanceClause . BASELINE , <EOL> AuthenticationSuite . TLS12 ) <EOL> self . assertFalse ( supported ) </s>
