Пример #1
0
 def test_does_not_affect_current_members(self):
     with self.subTest("Membership ends in future"):
         self.s1.until = timezone.now().replace(year=2019, month=9, day=1)
         self.s1.save()
         processed = services.execute_data_minimisation(True)
         self.assertEqual(len(processed), 1)
     with self.subTest("Never ending membership"):
         self.s1.until = None
         self.s1.save()
         processed = services.execute_data_minimisation(True)
         self.assertEqual(len(processed), 1)
         self.s1.until = timezone.now().replace(year=2018, month=9, day=1)
         self.s1.save()
     with self.subTest("Newer year membership after expired one"):
         m = Membership.objects.create(
             user=self.m1,
             type=Membership.MEMBER,
             since=timezone.now().replace(year=2018, month=9, day=10),
             until=timezone.now().replace(year=2019, month=8, day=31),
         )
         processed = services.execute_data_minimisation(True)
         self.assertEqual(len(processed), 1)
         m.delete()
     with self.subTest("Newer study membership after expired one"):
         m = Membership.objects.create(
             user=self.m1,
             type=Membership.MEMBER,
             since=timezone.now().replace(year=2018, month=9, day=10),
             until=None,
         )
         processed = services.execute_data_minimisation(True)
         self.assertEqual(len(processed), 1)
         m.delete()
Пример #2
0
 def test_dry_run(self):
     with self.subTest("With dry_run=True"):
         services.execute_data_minimisation(True)
         self.m1.refresh_from_db()
         self.assertEqual(self.m1.profile.student_number, "s1234567")
     with self.subTest("With dry_run=False"):
         services.execute_data_minimisation(False)
         self.m1.refresh_from_db()
         self.assertIsNone(self.m1.profile.student_number)
Пример #3
0
    def test_removes_after_31_days_or_no_membership(self):
        with self.subTest("Deletes after 31 days"):
            processed = services.execute_data_minimisation(True)
            self.assertEqual(len(processed), 2)
            self.assertEqual(processed[0], self.m1)

        with self.subTest("Deletes after 31 days"):
            self.s1.until = timezone.now().replace(year=2018, month=11, day=1)
            self.s1.save()
            processed = services.execute_data_minimisation(True)
            self.assertEqual(len(processed), 1)

        with self.subTest("Deletes when no memberships"):
            self.s1.delete()
            processed = services.execute_data_minimisation(True)
            self.assertEqual(len(processed), 2)
Пример #4
0
 def minimise_data(self, request, queryset):
     processed = len(
         services.execute_data_minimisation(members=Member.objects.filter(
             pk__in=queryset)))
     if processed == 0:
         self.message_user(
             request,
             _("Data minimisation could not be executed "
               "for the selected user(s)."),
             messages.ERROR,
         )
     else:
         self.message_user(
             request,
             _("Data minimisation was executed "
               "for {} user(s).").format(processed),
             messages.SUCCESS,
         )
Пример #5
0
 def test_provided_queryset(self):
     processed = services.execute_data_minimisation(True,
                                                    members=Member.objects)
     self.assertEqual(len(processed), 2)
     self.assertEqual(processed[0], self.m1)
Пример #6
0
 def handle(self, *args, **options):
     processed = services.execute_data_minimisation(options["dry-run"])
     for p in processed:
         self.stdout.write("Removed data for {}".format(p))