def post_source_copy(source_uuid: SourceId, metric_uuid: MetricId, database: Database): """Add a copy of the source to the metric (new in v3).""" data_model = latest_datamodel(database) reports = latest_reports(database) source = SourceData(data_model, reports, source_uuid) target = MetricData(data_model, reports, metric_uuid) target.metric["sources"][(source_copy_uuid := uuid())] = copy_source(source.source, source.datamodel) user = sessions.user(database) target.report["delta"] = dict( uuids=[ target.report_uuid, target.subject_uuid, target.metric_uuid, source_copy_uuid ], email=user["email"], description= f"{user['user']} copied the source '{source.source_name}' of metric " f"'{source.metric_name}' of subject '{source.subject_name}' from report '{source.report_name}' to " f"metric '{target.metric_name}' of subject '{target.subject_name}' in report " f"'{target.report_name}'.") result = insert_new_report(database, target.report) result["new_source_uuid"] = source_copy_uuid return result
def post_source_copy(source_uuid: SourceId, metric_uuid: MetricId, database: Database): """Add a copy of the source to the metric (new in v3).""" data_model = latest_datamodel(database) reports = latest_reports(database) source = SourceData(data_model, reports, source_uuid) target = MetricData(data_model, reports, metric_uuid) target.metric["sources"][(source_copy_uuid := uuid())] = copy_source(source.source, source.datamodel) delta_description = ( f"{{user}} copied the source '{source.source_name}' of metric '{source.metric_name}' of subject " f"'{source.subject_name}' from report '{source.report_name}' to metric '{target.metric_name}' of subject " f"'{target.subject_name}' in report '{target.report_name}'." ) uuids = [target.report_uuid, target.subject_uuid, target.metric_uuid, source_copy_uuid] result = insert_new_report(database, delta_description, (target.report, uuids)) result["new_source_uuid"] = source_copy_uuid return result
def test_copy_without_name(self): """Test that the copy name is based on the data model if the original source doesn't have a name.""" self.source["name"] = "" source_copy = copy_source(self.source, self.data_model) self.assertEqual("Source type (copy)", source_copy["name"])
def test_copy_without_name_change(self): """Test that the copy name can be left unchanged.""" source_copy = copy_source(self.source, self.data_model, change_name=False) self.assertEqual("Source", source_copy["name"])
def test_copy_name(self): """Test that the copy name is changed.""" source_copy = copy_source(self.source, self.data_model) self.assertEqual("Source (copy)", source_copy["name"])