def test_archive_all_for_person(self) -> None: """ Archive all should archive the given consents then bulk create new unset consents. """ terms = Term.objects.active() self.assertNotEqual(len(terms), 0) person1 = Person.objects.create(personal="Harry", family="Potter", email="*****@*****.**") person2 = Person.objects.create( personal="Ron", family="Weasley", email="*****@*****.**", username="******", ) # both people consent to all terms self.person_consent_active_terms(person1) self.person_consent_active_terms(person2) active_consents = Consent.objects.active() self.assertEqual( len( active_consents.filter(person=person1, term_option__isnull=False)), len(terms), ) self.assertEqual( len( active_consents.filter(person=person2, term_option__isnull=False)), len(terms), ) Consent.archive_all_for_person(person1) active_consents = Consent.objects.active() # All consents for person1 is archived. And a new unset consent is active self.assertEqual( len( active_consents.filter(person=person1, term_option__isnull=False)), 0) self.assertEqual( len( active_consents.filter(person=person1, term_option__isnull=True)), len(terms), ) # person2 consents remain unchanged self.assertEqual( len( active_consents.filter(person=person2, term_option__isnull=False)), len(terms), )
def unset_consents_on_person_archive(sender, **kwargs) -> None: person = kwargs["person"] Consent.archive_all_for_person(person=person)