def test_get_configuration_by_id(self): """Test case for get_configuration_by_id Finds configuration by ID and checks that response time is acceptable # noqa: E501 """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_CFG # Start monitoring response time start = time.clock() # Add a new test configuration (to be searched later) api_response = api_instance.add_configuration(cfg) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Start monitoring response time start = time.clock() # SEARCHES THE CONFIGURATION BY ID (main purpose of the test) api_instance.get_configuration_by_id(api_response.id) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time))
def test_add_not_valid_configuration(self): """Test case for add_not_valid_configuration Adds a new not valid configuration and checks that response time is acceptable and that error code is returned """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = swagger_client.NewConfiguration(name="GoogleSettings", value=4) # Start monitoring response time start = time.clock() # Add a new test configuration try: api_instance.add_configuration(cfg) except swagger_client.rest.ApiException as excp: if excp.status != 400: raise excp else: request_time = time.clock() - start # End monitoring response time self.assertLessEqual( request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Check if the error returned is the one expected self.assertEqual(excp.status, 400) return raise Exception("Configuration should not be added")
def test_get_configuration_by_not_existing_id(self): """Test case for get_configuration_by_not_existing_id Finds configuration by not existing ID and checks that there is error code and that response time is acceptable # noqa: E501 """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) # Start monitoring response time start = time.clock() try: # SEARCHES THE CONFIGURATION BY ID (main purpose of the test) api_instance.get_configuration_by_id(str(uuid.uuid4())) except swagger_client.rest.ApiException as excp: if excp.status != 404: raise excp else: # End monitoring response time request_time = time.clock() - start self.assertLessEqual( request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Check if the error returned is the one expected self.assertEqual(excp.status, 404) return raise Exception("Configuration should not be found")
def test_load_performance_spec_by_find_configuration_by_name(self): """Test case for max load performance and find_configuration_by_name Adds API_MIN_RESPONSE_TIME_REQ_NO configuration by name and checks that response time is acceptable (within (API_MIN_RESPONSE_TIME_) then search for configurations by name """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_UNIQUE_CFG api_response = {} values_to_add = 400 # Start monitoring response time time_elapsed = 0.0 # Add a new test configurations (to be searched later) for index in range(values_to_add): start = time.clock() api_response = api_instance.add_configuration(cfg) time_elapsed += time.clock() - start # End monitoring response time self.assertLessEqual( time_elapsed, API_LOAD_TEST_MIN_RESPONSE_TIME / API_LOAD_TEST_MIN_RESPONSE_TIME_REQ_NO, "Request completed in {}ms".format(time_elapsed)) print("") print("### STRESS TEST RESULTS") print("") print( str(values_to_add) + " simple requests performed in: " + str(time_elapsed)) print("Required min. load: " + str(API_LOAD_TEST_MIN_RESPONSE_TIME_REQ_NO) + " req/sec") print("Actual max. load: " + str(values_to_add / time_elapsed) + " req/sec") # Start monitoring response time start = time.clock() # SEARCH THE ADDED CONFIGURATION BY NAME (main purpose of the test) api_response = api_instance.find_configuration_by_name( api_response.name) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) self.assertEqual( len(api_response), values_to_add, ("Configuration added " + str(values_to_add) + " / configurations found: " + str(len(api_response))))
def test_delete_not_existing_configuration(self): """Test case for delete_not_existing_configuration Deletes a Configuration and checks that response time is acceptable """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) # Start monitoring response time start = time.clock() # DELETE A NOT EXISTING CONFIGURATION (main purpose of the test) try: # uuid for this cfg has just been generated, so will not be found api_instance.delete_configuration(str(uuid.uuid4())) except swagger_client.rest.ApiException as excp: if excp.status != 404: raise excp else: # End monitoring response time request_time = time.clock() - start self.assertLessEqual( request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Check if the error returned is the one expected self.assertEqual(excp.status, 404) return raise Exception("Configuration should not be found")
def test_delete_not_valid_configuration(self): """Test case for delete_not_valid_configuration Deletes a Configuration and checks that response time is acceptable """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) # Start monitoring response time start = time.clock() # DELETE A NOT VALID CONFIGURATION (main purpose of the test) try: api_instance.delete_configuration("666_invalid_id_666") except swagger_client.rest.ApiException as excp: if excp.status != 400: raise excp else: # End monitoring response time request_time = time.clock() - start self.assertLessEqual( request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Check if the error returned is the one expected self.assertEqual(excp.status, 400) return raise Exception("Configuration should not be found")
def test_delete_configuration(self): """Test case for delete_configuration Deletes a Configuration and checks that response time is acceptable """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_CFG # Start monitoring response time start = time.clock() # Add a new test configuration (to be deleted later) api_response = api_instance.add_configuration(cfg) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Start monitoring response time start = time.clock() # DELETE THE ADDED CONFIGURATION (main purpose of the test) api_instance.delete_configuration(api_response.id) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time))
def test_update_not_existing_configuration(self): """Test case for update_not_existing_configuration Updates an existing configuration with not existing uuid and checks that error code are returned and that response time is acceptable """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_CFG # Start monitoring response time start = time.clock() # Add a new test configuration (to be modified later) api_response = api_instance.add_configuration(cfg) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Modifies some values of existing configuration # to create an updated invalid configuration updated_configuration = api_response updated_configuration.id = str(uuid.uuid4()) updated_configuration.value = {"answer": 42} # Start monitoring response time start = time.clock() try: # UPDATES THE ADDED CONFIGURATION (main purpose of the test) api_instance.update_configuration(updated_configuration) except swagger_client.rest.ApiException as excp: if excp.status != 404: raise excp else: # End monitoring response time request_time = time.clock() - start self.assertLessEqual( request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Check if the error returned is the one expected self.assertEqual(excp.status, 404) return raise Exception("Configuration should not be updated")
def test_add_configuration(self): """Test case for add_configuration Adds a new configuration and checks that response time is acceptable """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_CFG # Start monitoring response time start = time.clock() # Add a new test configuration api_instance.add_configuration(cfg) request_time = time.clock() - start # End monitoring response time self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time))
async def reload_api_instances(self, ctx): try: client = await self.get_api_client(ctx) self.administration_api = swagger_client.AdministrationApi(client) self.byond_api = swagger_client.ByondApi(client) self.chat_api = swagger_client.ChatApi(client) self.configuration_api = swagger_client.ConfigurationApi(client) self.dream_daemon_api = swagger_client.DreamDaemonApi(client) self.dream_maker_api = swagger_client.DreamMakerApi(client) self.home_api = swagger_client.HomeApi(client) self.instance_api = swagger_client.InstanceApi(client) self.instance_permission_set_api = swagger_client.InstancePermissionSetApi( client) self.job_api = swagger_client.JobApi(client) self.repository_api = swagger_client.RepositoryApi(client) self.transfer_api = swagger_client.TransferApi(client) self.user_api = swagger_client.UserApi(client) self.user_group_api = swagger_client.UserGroupApi(client) except Exception as err: await ctx.send(f"There was an error instantiating the APIs: {err}")
def test_update_configuration(self): """Test case for update_configuration Updates an existing configuration and checks that response time is acceptable # noqa: E501 """ # create an instance of the API class api_instance = swagger_client.ConfigurationApi( swagger_client.ApiClient()) cfg = SAMPLE_CFG # Start monitoring response time start = time.clock() # Add a new test configuration (to be modified later) api_response = api_instance.add_configuration(cfg) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time)) # Modifies some values of existing configuration # to create an updated configuration updated_configuration = api_response updated_configuration.name = "UpdatedName" updated_configuration.value = {"answer": 42} # Start monitoring response time start = time.clock() # UPDATES THE ADDED CONFIGURATION (main purpose of the test) api_instance.update_configuration(updated_configuration) # End monitoring response time request_time = time.clock() - start self.assertLessEqual(request_time, API_MAX_ALLOWED_RESPONSE_TIME, "Request completed in {}ms".format(request_time))
from __future__ import print_function import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = swagger_client.ConfigurationApi(swagger_client.ApiClient()) cfg = swagger_client.NewConfiguration( name="GoogleSettings", value={"list": 3} ) # NewConfiguration | Configuration object to be added. Duplicates are allowed. try: # Adds a new configuration api_response = api_instance.add_configuration(cfg) pprint(api_response) except ApiException as e: print("Exception when calling ConfigurationApi->add_configuration: %s\n" % e)