def test_get_reduction_run_valid(self, mock_start_db): """ Test: A ReductionRun record is returned When: get_reduction_run is called with values that match a database record """ mock_db = Mock() mock_start_db.return_value = mock_db access.get_reduction_run('GEM', 1) mock_db.data_model.ReductionRun.objects.filter.assert_called_once()
def test_get_reduction_run_invalid(self): """ Test: None is returned When: get_reduction_run is called values not in the database """ actual = access.get_reduction_run('GEM', 0) self.assertIsNone(actual.first())
def test_get_reduction_run_valid(self): """ Test: A ReductionRun record is returned When: get_reduction_run is called with values that match a database record """ experiment, _ = self.database.data_model.Experiment.objects.get_or_create( reference_number=1231231) instrument, _ = self.database.data_model.Instrument.objects.get_or_create( name="ARMI", is_active=1, is_paused=0) status = access.get_status("q") fake_script_text = "scripttext" reduction_run = create_reduction_run_record(experiment, instrument, FakeMessage(), 0, fake_script_text, status) reduction_run.save() assert access.get_reduction_run('ARMI', 1234567).first() == reduction_run reduction_run.delete() experiment.delete() instrument.delete()
def get_location_and_rb_from_database(database_client, instrument, run_number): """ Retrieves a run's data-file location and rb_number from the auto-reduction database :param database_client: Client to access auto-reduction database :param instrument: (str) the name of the instrument associated with the run :param run_number: The run number of the data to be retrieved :return: The data file location and rb_number, or None if this information is not in the database """ if database_client is None: print("Database not connected") return None all_reduction_run_records = db.get_reduction_run(instrument, run_number) if not all_reduction_run_records: return None reduction_run_record = all_reduction_run_records.order_by( 'run_version').first() data_location = reduction_run_record.data_location.first().file_path experiment_number = reduction_run_record.experiment.reference_number return data_location, experiment_number