def test_get_current_and_upcoming_variables_test_upcomming_by_experiment_not_in_ICAT(self, mock_icat_call): mock_icat_call.return_value = [] instrument = InstrumentUtils().get_instrument("valid") variable = InstrumentVariable( instrument=instrument, name="test", value="test", is_advanced=False, type="text", experiment_reference=99999, ) variable.save() current_variables, upcoming_variables_by_run, upcoming_variables_by_experiment = InstrumentVariablesUtils().get_current_and_upcoming_variables(testInstrument) self.assertTrue(len(upcoming_variables_by_experiment) == 0, "Expecting no upcoming experiment variables to be returned")
def test_get_current_and_upcoming_variables_test_upcomming_by_experiment(self, mock_icat_call): mock_icat_call.return_value = [99999] instrument = InstrumentUtils().get_instrument("valid") variable = InstrumentVariable( instrument=instrument, name="test", value="test", is_advanced=False, type="text", experiment_reference=99999, ) variable.save() current_variables, upcoming_variables_by_run, upcoming_variables_by_experiment = InstrumentVariablesUtils().get_current_and_upcoming_variables(testInstrument) self.assertNotEqual(upcoming_variables_by_experiment, None, "Expecting some upcoming experiment variables to be returned") self.assertNotEqual(upcoming_variables_by_experiment, [], "Expecting some upcoming experiment variables to be returned") self.assertTrue(len(upcoming_variables_by_experiment) > 0, 'Expecting at least 1 upcoming experiment variable returned')
def copy_variable(self, variable): """ Return a temporary copy (unsaved) of the variable, which can be modified and then saved without modifying the original. """ return InstrumentVariable( name=variable.name, value=variable.value, is_advanced=variable.is_advanced, type=variable.type, help_text=variable.help_text, instrument=variable.instrument, experiment_reference=variable.experiment_reference, start_run=variable.start_run, tracks_script=variable.tracks_script)
def test_get_variables_for_run_experiment_reference(self): instrument = InstrumentUtils().get_instrument("valid") variable = InstrumentVariable( instrument=instrument, name="test", value="test", is_advanced=False, type="text", experiment_reference=99999, ) variable.save() experiment = Experiment(reference_number=99999) reduction_run = ReductionRun(run_number=1, instrument=instrument, experiment=experiment, run_version=1, status=StatusUtils().get_queued()) variables = InstrumentVariablesUtils().get_variables_for_run(reduction_run) self.assertNotEqual(variables, None, "Expecting some variables to be returned") self.assertNotEqual(variables, [], "Expecting some variables to be returned") self.assertTrue(len(variables) > 0, 'Expecting at least 1 variable returned') self.assertEqual(variables[0].experiment_reference, 99999, "Expecting instrument variables to match with experiment reference number")
def _create_variables(self, instrument, script, variable_dict, is_advanced): variables = [] for key, value in variable_dict.iteritems(): str_value = str(value).replace('[', '').replace(']', '') if len(str_value) > InstrumentVariable._meta.get_field( 'value').max_length: raise DataTooLong variable = InstrumentVariable( instrument=instrument, name=key, value=str_value, is_advanced=is_advanced, type=VariableUtils().get_type_string(value), start_run=0, help_text=self._get_help_text('standard_vars', key, instrument.name, script)) variables.append(variable) return variables