diff --git a/evap/evaluation/management/commands/anonymize.py b/evap/evaluation/management/commands/anonymize.py index 682434ef1f..0d45bcfa3c 100644 --- a/evap/evaluation/management/commands/anonymize.py +++ b/evap/evaluation/management/commands/anonymize.py @@ -16,6 +16,7 @@ Contribution, Course, CourseType, + Evaluation, Program, RatingAnswerCounter, Semester, @@ -69,7 +70,7 @@ def anonymize_data(self): self.anonymize_evaluations() self.anonymize_questionnaires() self.anonymize_answers(lorem_ipsum) - + self.anonymize_staff_notes(lorem_ipsum) self.stdout.write("") self.stdout.write("Done.") @@ -276,6 +277,13 @@ def anonymize_answers(self, lorem_ipsum): finally: self.stdout.ending = "\n" + def anonymize_staff_notes(self, lorem_ipsum): + self.stdout.write("Replacing staff notes with fake ones...") + for evaluation in Evaluation.objects.all(): + if evaluation.staff_notes != "": + evaluation.staff_notes = self.lorem(evaluation.staff_notes, lorem_ipsum) + evaluation.save() + # Returns a string with the same number of lorem ipsum words as the given text @staticmethod def lorem(text, lorem_ipsum): diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index 8c57d62f8f..bdb6b2bb9a 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -89,6 +89,7 @@ def setUpTestData(cls): course=cls.course, name_de="Wie man Software testet", name_en="Testing your software", + staff_notes="This evaluation has dropout answers", ) baker.make( Evaluation, @@ -180,6 +181,10 @@ def test_user_with_password(self): with self.assertRaises(AssertionError): management.call_command("anonymize", stdout=StringIO()) + def test_staff_notes_are_anonymized(self): + management.call_command("anonymize", stdout=StringIO()) + self.assertEqual(Evaluation.objects.get(id=self.evaluation.id).staff_notes, "Lorem ipsum dolor sit amet,") + class TestRefreshResultsCacheCommand(TestCase): def test_calls_cache_results(self):