def test_get_environment_status(self): """Test that it is possible to get status from an environment. Approval criteria: - It shall be possible to get status from environment that is being checked out. Test steps: 1. Store a PENDING environment request in a celery task. 2. Send a status request for that environment. 3. Verify that the status for the environment was returned. """ task_id = "d9689ea5-837b-48c1-87b1-3de122b3f2fe" database = FakeDatabase() request = FakeRequest() request.fake_params = {"id": task_id} response = FakeResponse() test_result = {"this": "is", "results": ":)"} test_status = "PENDING" self.logger.info( "STEP: Store a PENDING environment request in a celery task.") celery_worker = FakeCelery(task_id, test_status, test_result) self.logger.info("STEP: Send a status request for that environment.") environment = Webserver(database, celery_worker) environment.on_get(request, response) self.logger.info( "STEP: Verify that the status for the environment was returned.") self.assertEqual(response.status, falcon.HTTP_200) self.assertDictEqual(response.media, { "status": test_status, "result": test_result })
def test_get_from_request(self): """Test that it is possible to get all parameters from request. Approval criteria: - It shall be possible to get parameters from request. Data driven repetitions: - Repeat for the following parameters: ["id", "release", "suite_id"] Test steps: 1. For each parameter: 1.1: Call the function to get the parameter. 1.2: Verify that the parameter is correct. """ requests = ( ("id", get_environment_id), ("release", get_release_id), ("suite_id", get_suite_id), ) self.logger.info("STEP: For each parameter:") for parameter, func in requests: test_value = f"testing_{parameter}" request = FakeRequest() request.fake_params[parameter] = test_value self.logger.info("STEP: Call the function to get the parameter %r", parameter) response_value = func(request) self.logger.info("STEP: Verify that the parameter is correct.") self.assertEqual(response_value, test_value)
def test_get_environment(self, get_environment_mock): """Test that it is possible to get environments from the environment provider. Approval criteria: - It shall be possible to get an environment from the environment provider. Note: - This test is mocked due to not wanting to run celery tasks. Test steps: 1. Send a request for an environment. 2. Verify that the environment provider gets an environment. """ task_id = "f3286e6e-946c-4510-a935-abd7c7bdbe17" database = FakeDatabase() get_environment_mock.delay.return_value = Task(task_id) celery_worker = FakeCelery(task_id, "", {}) suite_id = "ca950c50-03d3-4a3c-8507-b4229dd3f8ea" request = FakeRequest() request.fake_params = {"suite_id": suite_id} response = FakeResponse() self.logger.info("STEP: Send a request for an environment.") environment = Webserver(database, celery_worker) environment.on_post(request, response) self.logger.info( "STEP: Verify that the environment provider gets an environment.") self.assertEqual(response.media, { "result": "success", "data": { "id": task_id } }) get_environment_mock.delay.assert_called_once_with(suite_id)
def test_get(self): """Test that it is possible to get a sub suite from the sub suite endpoint. Approval criteria: - The sub suite endpoint shall return a sub suite if one exists. Test steps: 1. Add a sub suite to the database. 2. Send a fake request to the sub suite endpoint. 3. Verify that the sub suite endpoint responds with a sub suite. """ self.logger.info("STEP: Add a sub suite to the database.") database = FakeDatabase() suite_id = "thetestiestofsuites" sub_suite = {"test": "suite"} database.write(suite_id, json.dumps(sub_suite)) self.logger.info( "STEP: Send a fake request to the sub suite endpoint.") request = FakeRequest() request.fake_params["id"] = suite_id response = FakeResponse() SubSuite(database).on_get(request, response) self.logger.info( "STEP: Verify that the sub suite endpoint responds with a sub suite." ) self.assertDictEqual(response.fake_responses.get("media"), sub_suite)
def test_execution_space_provider(self): """Test that the register backend can return execution space provider. Approval criteria: - The register backend shall be able to get the execution space provider from request parameters. Test steps: 1. Get execution space provider from request via the register backend. 2. Verify that the backend returns the correct execution space provider. """ request = FakeRequest() test_execution_space_provider = {"execution_space": {"id": "providertest"}} request.fake_params["execution_space_provider"] = test_execution_space_provider self.logger.info( "STEP: Get execution space provider from request via the register backend." ) response_execution_space_provider = get_execution_space_provider(request) self.logger.info( "STEP: Verify that the backend returns the correct execution space provider." ) self.assertDictEqual( test_execution_space_provider, response_execution_space_provider )
def test_suite_id_missing(self): """Test that the subsuite backend raises bad request if id is missing. Approval criteria: - The subsuite backend shall raise falcon.HTTPBadRequest if ID is missing. Test steps: 1. Get Suite ID from request via the suite id function. 2. Verify that the suite id function raises falcon.HTTPBadRequest. """ request = FakeRequest() request.fake_params["id"] = None self.logger.info("STEP: Get Suite ID from request via the suite id function.") self.logger.info( "STEP: Verify that the suite id function raises falcon.HTTPBadRequest." ) with self.assertRaises(falcon.HTTPBadRequest): suite_id(request)
def test_suite_id(self): """Test that the subsuite backend can return suite IDs. Approval criteria: - The subsuite backend shall be able to get the suite ID from request parameters. Test steps: 1. Get Suite ID from request via the suite id function. 2. Verify that the suite id function return the correct ID. """ request = FakeRequest() test_id = "thisismytestid" request.fake_params["id"] = test_id self.logger.info( "STEP: Get Suite ID from request via the suite id function.") response_id = get_id(request) self.logger.info( "STEP: Verify that the suite id function return the correct ID.") self.assertEqual(test_id, response_id)
def test_suite_id(self): """Test that the configure backend can return suite id. Approval criteria: - The configure backend shall be able to get the suite id from request. Test steps: 1. Get suite id from request via the configure backend. 2. Verify that the backend returns the correct suite id. """ request = FakeRequest() test_suite_id = "b58415d4-2f39-4ab0-8763-7277e18f9606" request.fake_params["suite_id"] = test_suite_id self.logger.info( "STEP: Get suite id from request via the configure backend.") response_suite_id = get_suite_id(request) self.logger.info( "STEP: Verify that the backend returns the correct suite id.") self.assertEqual(test_suite_id, response_suite_id)
def test_dataset(self): """Test that the configure backend can return dataset. Approval criteria: - The configure backend shall be able to get the dataset from request. Test steps: 1. Get dataset from request via the configure backend. 2. Verify that the backend returns the correct dataset. """ request = FakeRequest() test_dataset = {"test_dataset": "my ultimate dataset"} request.fake_params["dataset"] = json.dumps(test_dataset) self.logger.info( "STEP: Get dataset from request via the configure backend.") response_dataset = get_dataset(request) self.logger.info( "STEP: Verify that the backend returns the correct dataset.") self.assertDictEqual(test_dataset, response_dataset)
def test_get_no_id(self): """Test that the sub suite endpoint fails when sub suite was not found. Approval criteria: - The sub suite endpoint shall raise a HTTPNotFound exception when no suite is found. Test steps: 1. Send a fake request to the sub suite endpoint. 2. Verify that the sub suite endpoint responds with HTTPNotFound. """ self.logger.info( "STEP: Send a fake request to the sub suite endpoint.") request = FakeRequest() request.fake_params["id"] = "thisonedoesnotexist" response = FakeResponse() self.logger.info( "STEP: Verify that the sub suite endpoint responds with HTTPNotFound." ) with self.assertRaises(falcon.HTTPNotFound): SubSuite(FakeDatabase).on_get(request, response)
def test_suite_id_media_is_none(self): """Test that the configure backend returns the result of get_param if media is not set. Approval criteria: - The configure backend shall return the value of get_param if media is None. Test steps: 1. Get suite id from request via the configure backend without media. 2. Verify that the backend returns the suite id. """ request = FakeRequest() request.force_media_none = True test_suite_id = "b58415d4-2f39-4ab0-8763-7277e18f9606" request.fake_params["suite_id"] = test_suite_id self.logger.info( "STEP: Get suite id from request via the configure backend without media." ) response_suite_id = get_suite_id(request) self.logger.info("STEP: Verify that the backend returns the suite id.") self.assertEqual(test_suite_id, response_suite_id)
def test_iut_provider_id(self): """Test that the configure backend can return IUT provider id. Approval criteria: - The configure backend shall be able to get the IUT provider id from request. Test steps: 1. Get IUT provider id from request via the configure backend. 2. Verify that the backend returns the correct iut provider id. """ request = FakeRequest() test_provider_id = "test_iut_provider" request.fake_params["iut_provider"] = test_provider_id self.logger.info( "STEP: Get IUT provider id from request via the configure backend." ) response_provider_id = get_iut_provider_id(request) self.logger.info( "STEP: Verify that the backend returns the correct iut provider id." ) self.assertEqual(test_provider_id, response_provider_id)
def test_dataset_none(self): """Test that the configure backend returns None if dataset is not set. Approval criteria: - The configure backend shall return None if dataset is not in request. Test steps: 1. Get dataset from request via the configure backend. 2. Verify that the backend returns None. """ self.logger.info( "STEP: Get dataset from request via the configure backend.") response = get_dataset(FakeRequest()) self.logger.info("STEP: Verify that the backend returns None.") self.assertIsNone(response)
def test_log_area_provider_id_none(self): """Test that the configure backend returns None if log area provider id is not set. Approval criteria: - The configure backend shall return None if log area provider is not in request. Test steps: 1. Get log area provider from request via the configure backend. 2. Verify that the backend returns None. """ self.logger.info( "STEP: Get log area provider id from request via the configure backend." ) response = get_log_area_provider_id(FakeRequest()) self.logger.info("STEP: Verify that the backend returns None.") self.assertIsNone(response)
def test_iut_provider_none(self): """Test that the register backend returns None if IUT provider is not set. Approval criteria: - The register backend shall return None if IUT provider is not in request. Test steps: 1. Get IUT provider from request via the register backend. 2. Verify that the backend returns None. """ request = FakeRequest() self.logger.info( "STEP: Get IUT provider from request via the register backend." ) response_iut_provider = get_iut_provider(request) self.logger.info("STEP: Verify that the backend returns None.") self.assertIsNone(response_iut_provider)
def test_register_no_providers(self): """Test that it is not possible to register no providers. Approval criteria: - It shall not be possible to register no providers. Test steps: 1. Send a register request with no providers. 2. Verify that a 400 Bad Request is returned. """ fake_database = FakeDatabase() fake_request = FakeRequest() fake_response = FakeResponse() self.logger.info("STEP: Send a register request with no providers.") with self.assertRaises(falcon.HTTPBadRequest): self.logger.info( "STEP: Verify that a 400 Bad Request is returned.") Register(fake_database).on_post(fake_request, fake_response)
def test_get_configuration_no_suite_id(self): """Test that it is not possible to get a configuration without suite id. Approval criteria: - The configure endpoint shall return BadRequest when missing suite id. Test steps: 1. Send a GET request to the configure endpoint without suite id. 2. Verify that a BadRequest is returned. """ database = FakeDatabase() response = FakeResponse() request = FakeRequest() self.logger.info( "STEP: Send a GET request to the configure endpoint without suite id." ) with self.assertRaises(falcon.HTTPBadRequest): self.logger.info("STEP: Verify that a BadRequest is returned.") Configure(database).on_get(request, response)
def test_register_all_providers(self): """Test that it is possible to register providers via the register endpoint Approval criteria: - It shall be possible to register providers using the endpoint. Test steps: 1. Send a register request for new providers. 2. Verify that the new providers were registered in the database. """ fake_database = FakeDatabase() test_iut_provider = { "iut": { "id": "iut_provider_test", "list": { "available": [], "possible": [] }, } } test_execution_space_provider = { "execution_space": { "id": "execution_space_provider_test", "list": { "available": [{ "identifier": "123" }], "possible": [] }, } } test_log_area_provider = { "log": { "id": "log_area_provider_test", "list": { "available": [], "possible": [] }, } } fake_request = FakeRequest() fake_request.fake_params = { "iut_provider": json.dumps(test_iut_provider), "execution_space_provider": json.dumps(test_execution_space_provider), "log_area_provider": json.dumps(test_log_area_provider), } fake_response = FakeResponse() self.logger.info("STEP: Send a register request for new providers.") Register(fake_database).on_post(fake_request, fake_response) self.logger.info( "STEP: Verify that the new providers were registered in the database." ) self.assertEqual(fake_response.fake_responses.get("status"), falcon.HTTP_204) stored_execution_space_provider = json.loads( fake_database.reader.hget( "EnvironmentProvider:ExecutionSpaceProviders", "execution_space_provider_test", )) self.assertDictEqual( stored_execution_space_provider, test_execution_space_provider, ) stored_log_area_provider = json.loads( fake_database.reader.hget("EnvironmentProvider:LogAreaProviders", "log_area_provider_test")) self.assertDictEqual(stored_log_area_provider, test_log_area_provider) stored_iut_provider = json.loads( fake_database.reader.hget("EnvironmentProvider:IUTProviders", "iut_provider_test")) self.assertDictEqual(stored_iut_provider, test_iut_provider)
def test_get_configuration(self): """Test that it is possible to get a stored configuration. Approval criteria: - It shall be possible to get a stored configuration. Test steps: 1. Store a configuration in the database. 2. Send a GET request to the configure endpoint. 3. Verify that the configuration is the same as in the database. """ database = FakeDatabase() test_suite_id = "5ef5a01c-8ff9-448d-9ac5-21836a2fa6ff" test_dataset = {"dataset": "test"} test_iut_provider = { "iut": { "id": "iut_provider_test", "list": { "available": [], "possible": [] }, } } test_execution_space_provider = { "execution_space": { "id": "execution_space_provider_test", "list": { "available": [{ "identifier": "123" }], "possible": [] }, } } test_log_area_provider = { "log": { "id": "log_area_provider_test", "list": { "available": [], "possible": [] }, } } self.logger.info("STEP: Store a configuration in the database.") database.writer.hset(f"EnvironmentProvider:{test_suite_id}", "Dataset", json.dumps(test_dataset)) database.writer.hset( f"EnvironmentProvider:{test_suite_id}", "IUTProvider", json.dumps(test_iut_provider), ) database.writer.hset( f"EnvironmentProvider:{test_suite_id}", "ExecutionSpaceProvider", json.dumps(test_execution_space_provider), ) database.writer.hset( f"EnvironmentProvider:{test_suite_id}", "LogAreaProvider", json.dumps(test_log_area_provider), ) response = FakeResponse() request = FakeRequest() request.fake_params["suite_id"] = test_suite_id self.logger.info("STEP: Send a GET request to the configure endpoint.") Configure(database).on_get(request, response) self.logger.info( "STEP: Verify that the configuration is the same as in the database." ) self.assertEqual(response.status, falcon.HTTP_200) self.assertDictEqual(response.media.get("iut_provider", {}), test_iut_provider["iut"]) self.assertDictEqual(response.media.get("log_area_provider", {}), test_log_area_provider["log"]) self.assertDictEqual( response.media.get("execution_space_provider", {}), test_execution_space_provider["execution_space"], ) self.assertDictEqual(response.media.get("dataset", {}), test_dataset)
def test_configure_missing_parameters(self): """Test that it is not possible to configure the environment provider without providers. Approval criteria: - It shall not be possible to configure the environment provider when missing parameters. Test steps: 1. Store some providers in the database. 2. For each parameter: 2.1. Send a configure request missing that parameter. 2.2. Verify that it was not possible to configure. """ database = FakeDatabase() test_iut_provider = { "iut": { "id": "iut_provider_test", "list": { "available": [], "possible": [] }, } } test_execution_space_provider = { "execution_space": { "id": "execution_space_provider_test", "list": { "available": [{ "identifier": "123" }], "possible": [] }, } } test_log_area_provider = { "log": { "id": "log_area_provider_test", "list": { "available": [], "possible": [] }, } } self.logger.info("STEP: Store some providers in the database.") database.writer.hset( "EnvironmentProvider:ExecutionSpaceProviders", test_execution_space_provider["execution_space"]["id"], json.dumps(test_execution_space_provider), ) database.writer.hset( "EnvironmentProvider:IUTProviders", test_iut_provider["iut"]["id"], json.dumps(test_iut_provider), ) database.writer.hset( "EnvironmentProvider:LogAreaProviders", test_log_area_provider["log"]["id"], json.dumps(test_log_area_provider), ) response = FakeResponse() request = FakeRequest() test_params = { "iut_provider": test_iut_provider["iut"]["id"], "execution_space_provider": test_execution_space_provider["execution_space"]["id"], "log_area_provider": test_log_area_provider["log"]["id"], "dataset": {}, } self.logger.info("STEP: For each parameter:") for parameter in ( "iut_provider", "log_area_provider", "execution_space_provider", "dataset", "suite_id", ): self.logger.info("Missing parameter: %s", parameter) # Make sure we get a new suite id for each test. # that way we don't have to clear the database every time. test_suite_id = str(uuid4()) test_params["suite_id"] = test_suite_id request.fake_params = test_params.copy() request.fake_params.pop(parameter) self.logger.info( "STEP: Send a configure request missing that parameter.") with self.assertRaises(falcon.HTTPBadRequest): Configure(database).on_post(request, response) self.logger.info( "STEP: Verify that it was not possible to configure.") self.assertIsNone( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "IUTProvider")) self.assertIsNone( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "ExecutionSpaceProvider")) self.assertIsNone( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "LogAreaProvider")) self.assertIsNone( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "Dataset"))
def test_configure(self): """Test that it is possible to configure the environment provider for a suite. Approval criteria: - It shall be possible to configure the environment provider. - The configure endpoint shall return with the configured IUT, execution space & log area provider. Test steps: 1. Store some providers in the database. 2. Send a configure request to use those providers. 3. Verify that the configuration matches the providers in database. """ database = FakeDatabase() test_iut_provider = { "iut": { "id": "iut_provider_test", "list": { "available": [], "possible": [] }, } } test_execution_space_provider = { "execution_space": { "id": "execution_space_provider_test", "list": { "available": [{ "identifier": "123" }], "possible": [] }, } } test_log_area_provider = { "log": { "id": "log_area_provider_test", "list": { "available": [], "possible": [] }, } } test_suite_id = "2a4cb06d-4ebf-4aaa-a53b-1293194827d8" self.logger.info("STEP: Store some providers in the database.") database.writer.hset( "EnvironmentProvider:ExecutionSpaceProviders", test_execution_space_provider["execution_space"]["id"], json.dumps(test_execution_space_provider), ) database.writer.hset( "EnvironmentProvider:IUTProviders", test_iut_provider["iut"]["id"], json.dumps(test_iut_provider), ) database.writer.hset( "EnvironmentProvider:LogAreaProviders", test_log_area_provider["log"]["id"], json.dumps(test_log_area_provider), ) response = FakeResponse() request = FakeRequest() request.fake_params = { "iut_provider": test_iut_provider["iut"]["id"], "execution_space_provider": test_execution_space_provider["execution_space"]["id"], "log_area_provider": test_log_area_provider["log"]["id"], "dataset": {}, "suite_id": test_suite_id, } self.logger.info( "STEP: Send a configure request to use those providers.") Configure(database).on_post(request, response) self.logger.info( "STEP: Verify that the configuration matches the providers in database." ) self.assertEqual(response.status, falcon.HTTP_200) stored_iut_provider = json.loads( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "IUTProvider")) self.assertDictEqual(stored_iut_provider, test_iut_provider) stored_execution_space_provider = json.loads( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "ExecutionSpaceProvider")) self.assertDictEqual(stored_execution_space_provider, test_execution_space_provider) stored_log_area_provider = json.loads( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "LogAreaProvider")) self.assertDictEqual(stored_log_area_provider, test_log_area_provider) stored_dataset = json.loads( database.reader.hget(f"EnvironmentProvider:{test_suite_id}", "Dataset")) self.assertDictEqual(stored_dataset, {})
def test_release_environment(self): """Test that it is possible to release an environment. Approval criteria: - It shall be possible to release an environment. Test steps: 1. Store an environment i celery task. 2. Send a release request for that environment. 3. Verify that the environment was released. """ database = FakeDatabase() test_iut_provider = { "iut": { "id": "iut_provider_test", "list": { "available": [], "possible": [] }, } } test_execution_space_provider = { "execution_space": { "id": "execution_space_provider_test", "list": { "available": [{ "identifier": "123" }], "possible": [] }, } } test_log_area_provider = { "log": { "id": "log_area_provider_test", "list": { "available": [], "possible": [] }, } } database.writer.hset( "EnvironmentProvider:ExecutionSpaceProviders", test_execution_space_provider["execution_space"]["id"], json.dumps(test_execution_space_provider), ) database.writer.hset( "EnvironmentProvider:IUTProviders", test_iut_provider["iut"]["id"], json.dumps(test_iut_provider), ) database.writer.hset( "EnvironmentProvider:LogAreaProviders", test_log_area_provider["log"]["id"], json.dumps(test_log_area_provider), ) task_id = "d9689ea5-837b-48c1-87b1-3de122b3f2fe" request = FakeRequest() request.fake_params = {"release": task_id} response = FakeResponse() iut = {"id": "test_iut", "provider_id": test_iut_provider["iut"]["id"]} executor = { "id": "test_executor", "provider_id": test_execution_space_provider["execution_space"]["id"], } log_area = { "id": "test_log_area", "provider_id": test_log_area_provider["log"]["id"], } self.logger.info("STEP: Store an environment i celery task.") test_status = "SUCCESS" worker = FakeCelery( task_id, test_status, { "suites": [{ "iut": iut, "executor": executor, "log_area": log_area, }] }, ) self.logger.info("STEP: Send a release request for that environment.") environment = Webserver(database, worker) environment.on_get(request, response) self.logger.info("STEP: Verify that the environment was released.") self.assertDictEqual(response.media, {"status": test_status}) self.assertIsNone(worker.results.get(task_id))