def run_connection_pooling_test(self, request_count, max_connections): """Sends *request_count* requests with a maximum number of connection pools equal to *max_connections*""" communicator_configuration = init_utils.create_communicator_configuration( max_connections=max_connections) with Factory.create_communicator_from_configuration( communicator_configuration) as communicator: # Create a number of runner threads that will execute send_request runner_threads = [ threading.Thread(target=self.send_request, args=(i, communicator)) for i in range(0, request_count) ] for thread in runner_threads: thread.start() self.flag.set() # wait until threads are done before closing the communicator for i in range(0, request_count - 1): runner_threads[i].join() print( "Information on concurrent use of connections for {} connection pools:" .format(max_connections)) print("(*start time*, *end time*)") for item in self.result_list: if isinstance(item, Exception): self.fail("an exception occurred in one of the threads:/n" + str(item)) else: print repr(item)
def test_multipart_form_data_upload_put_multipart_form_data_object_with_response( self): """Test a multipart/form-data PUT upload with a response""" configuration = init_utils.create_communicator_configuration() configuration.api_endpoint = 'http://httpbin.org' multipart = MultipartFormDataObject() multipart.add_file( 'file', UploadableFile('file.txt', 'file-content', 'text/plain')) multipart.add_value('value', 'Hello World') with Factory.create_communicator_from_configuration( configuration) as communicator: response = communicator.put('/put', None, None, multipart, HttpBinResponse, None) self.assertEqual(response.form['value'], 'Hello World') self.assertEqual(response.files['file'], 'file-content')
def test_multiline_header(self): """Test if the products service can function with a multiline header""" multi_line_header = " some value \r\n \n with a liberal amount of \r\n spaces " configuration = init_utils.create_communicator_configuration() meta_data_provider = MetaDataProvider( integrator="Ingenico", additional_request_headers=(RequestHeader("X-GCS-MultiLineHeader", multi_line_header), )) params = DirectoryParams() params.country_code = "NL" params.currency_code = "EUR" session = Factory.create_session_from_configuration( configuration, meta_data_provider=meta_data_provider) with Factory.create_client_from_session(session) as client: response = client.merchant(MERCHANT_ID).products().directory( 809, params) self.assertGreater(len(response.entries), 0)
def test_multipart_form_data_upload_post_multipart_form_data_object_with_binary_response( self): """Test a multipart/form-data POST upload with a binary response""" configuration = init_utils.create_communicator_configuration() configuration.api_endpoint = 'http://httpbin.org' multipart = MultipartFormDataObject() multipart.add_file( 'file', UploadableFile('file.txt', 'file-content', 'text/plain')) multipart.add_value('value', 'Hello World') with Factory.create_communicator_from_configuration( configuration) as communicator: response = communicator.post_with_binary_response( '/post', None, None, multipart, None) data = '' for chunk in response[1]: data += chunk.decode('utf-8') response = json.loads(data) self.assertEqual(response['form']['value'], 'Hello World') self.assertEqual(response['files']['file'], 'file-content')