Exemple #1
0
def post_subject_copy(subject_uuid: SubjectId, report_uuid: ReportId, database: Database):
    """Add a copy of the subject to the report (new in v3)."""
    data_model = latest_datamodel(database)
    reports = latest_reports(database)
    source = SubjectData(data_model, reports, subject_uuid)
    target = ReportData(data_model, reports, report_uuid)
    target.report["subjects"][(subject_copy_uuid := uuid())] = copy_subject(source.subject, source.datamodel)
    user = sessions.user(database)
    target.report["delta"] = dict(
        uuids=[target.report_uuid, subject_copy_uuid], email=user["email"],
        description=f"{user['user']} copied the subject '{source.subject_name}' from report " \
                    f"'{source.report_name}' to report '{target.report_name}'.")
    result = insert_new_report(database, target.report)
    result["new_subject_uuid"] = subject_copy_uuid
    return result
Exemple #2
0
def post_subject_copy(subject_uuid: SubjectId, report_uuid: ReportId,
                      database: Database):
    """Add a copy of the subject to the report (new in v3)."""
    data_model = latest_datamodel(database)
    reports = latest_reports(database)
    source = SubjectData(data_model, reports, subject_uuid)
    target = ReportData(data_model, reports, report_uuid)
    target.report["subjects"][(subject_copy_uuid :=
                               uuid())] = copy_subject(source.subject,
                                                       source.datamodel)
    delta_description = (
        f"{{user}} copied the subject '{source.subject_name}' from report "
        f"'{source.report_name}' to report '{target.report_name}'.")
    uuids = [target.report_uuid, subject_copy_uuid]
    result = insert_new_report(database, delta_description,
                               (target.report, uuids))
    result["new_subject_uuid"] = subject_copy_uuid
    return result
Exemple #3
0
 def test_copy_without_name_change(self):
     """Test that the copy name can be left unchanged."""
     subject_copy = copy_subject(self.subject,
                                 self.data_model,
                                 change_name=False)
     self.assertEqual("Subject", subject_copy["name"])
Exemple #4
0
 def test_copy_without_name(self):
     """Test that the copy name is based on the data model if the original subject doesn't have a name."""
     self.subject["name"] = ""
     subject_copy = copy_subject(self.subject, self.data_model)
     self.assertEqual("Subject type (copy)", subject_copy["name"])
Exemple #5
0
 def test_copy_name(self):
     """Test that the copy name is changed."""
     subject_copy = copy_subject(self.subject, self.data_model)
     self.assertEqual("Subject (copy)", subject_copy["name"])
Exemple #6
0
 def test_copy_metrics(self):
     """Test that the metrics are copied too."""
     subject_copy = copy_subject(self.subject, self.data_model)
     self.assertEqual("Metric",
                      list(subject_copy["metrics"].values())[0]["name"])