def test_initialization_application(self): """Test the initialization method of the class Application""" application = Application() application.name = "name" self.assertEquals("name", application.name) application.application_type = "XXX" self.assertEquals("XXX", application.application_type)
def test_patch_execution_preprocessor(self, mock_restart_execution, mock_executor_stop, mock_executor_cancel, mock_executor_add, mock_executor_remove): """ It test the correct work of the method of canceling an execution """ # First we verify that nothing happens if launch_execution = False data = {'status': 'PEPITO'} response = self.client.patch("/api/v1/executions/100", data=json.dumps(data), content_type='application/json') self.assertEquals(409, response.status_code) self.assertEquals( 'No execution by the given id', response.json['message']) # Preparing the data for the rest of the test testbed = Testbed("name", False, "slurm", "ssh", "user@server", ['slurm']) db.session.add(testbed) db.session.commit() application = Application() application.name = "xxx" application.application_type = "XXX" db.session.add(application) db.session.commit() execution_configuration = ExecutionConfiguration() execution_configuration.testbed = testbed execution_configuration.application = application db.session.add(execution_configuration) db.session.commit() execution = Execution() execution.execution_type = Executable.__type_singularity_srun__ execution.status = Execution.__status_running__ execution.execution_configuration = execution_configuration db.session.add(execution) db.session.commit() response = self.client.patch("/api/v1/executions/" + str(execution.id) , data=json.dumps(data), content_type='application/json') self.assertEquals(409, response.status_code) self.assertEquals( 'No valid state to try to change', response.json['message']) data = {'PEPITO': 'PEPITO'} response = self.client.patch("/api/v1/executions/" + str(execution.id) , data=json.dumps(data), content_type='application/json') self.assertEquals(409, response.status_code) self.assertEquals( 'No status, remove_resource, or add_resource field in the payload', response.json['message']) data = {'status': 'CANCEL'} response = self.client.patch("/api/v1/executions/" + str(execution.id) , data=json.dumps(data), content_type='application/json') self.assertEquals(200, response.status_code) mock_executor_cancel.assert_called_with(execution, 'user@server') data = {'add_resource': ''} response = self.client.patch("/api/v1/executions/" + str(execution.id) , data=json.dumps(data), content_type='application/json') mock_executor_add.assert_called_with(execution) data = {'remove_resource': ''} response = self.client.patch("/api/v1/executions/" + str(execution.id) , data=json.dumps(data), content_type='application/json') mock_executor_remove.assert_called_with(execution) # Adding Checkpointable changes of status at ALDE level. execution.status = Execution.__status_running__ application.application_type = Application.CHECKPOINTABLE db.session.commit() data = {'status': 'STOP'} response = self.client.patch("/api/v1/executions/" + str(execution.id), data=json.dumps(data), content_type="application/json") mock_executor_stop.assert_called_with(execution) execution.status = Execution.__status_cancel__ db.session.commit() response = self.client.patch("/api/v1/executions/" + str(execution.id), data=json.dumps(data), content_type="application/json") self.assertEquals(409, response.status_code) self.assertEquals( 'Execution is not in right state', response.json['message']) # Checkpointable restart execution.status = Execution.__status_stopped__ db.session.commit() data = {'status': 'RESTART'} response = self.client.patch("/api/v1/executions/" + str(execution.id), data=json.dumps(data), content_type="application/json") mock_restart_execution.assert_called_with(execution) execution.status = Execution.__status_cancel__ db.session.commit() response = self.client.patch("/api/v1/executions/" + str(execution.id), data=json.dumps(data), content_type="application/json") self.assertEquals(409, response.status_code) self.assertEquals( 'Execution is not in right state', response.json['message'])