def test_email(self): self.email: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL) self.email.save() self.email._anonymize_obj(base_encryption_key=self.base_encryption_key) anon_email: Email = Email.objects.get(pk=self.email.pk) assert_not_equal(anon_email.email, CUSTOMER__EMAIL)
def test_renew_legal_reason_related(self): related_email: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL) related_email.save() related_email2: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL2) related_email2.save() related_email3: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL3) related_email3.save() legal = LegalReason.objects.create_consent(EMAIL_SLUG, self.customer) legal.expire() anon_legal = LegalReason.objects.get(pk=legal.pk) anon_legal.renew() anon_customer = Customer.objects.get(pk=self.customer.pk) assert_equal(anon_customer.primary_email_address, CUSTOMER__EMAIL) self.assertAnonymizedDataNotExists(anon_customer, "primary_email_address") # make sure only data we want were anonymized assert_equal(anon_customer.first_name, CUSTOMER__FIRST_NAME) self.assertAnonymizedDataNotExists(anon_customer, "first_name") anon_related_email: Email = Email.objects.get(pk=related_email.pk) assert_equal(anon_related_email.email, CUSTOMER__EMAIL) self.assertAnonymizedDataNotExists(anon_related_email, "email") anon_related_email2: Email = Email.objects.get(pk=related_email2.pk) assert_equal(anon_related_email2.email, CUSTOMER__EMAIL2) self.assertAnonymizedDataNotExists(anon_related_email2, "email") anon_related_email3: Email = Email.objects.get(pk=related_email3.pk) assert_equal(anon_related_email3.email, CUSTOMER__EMAIL3) self.assertAnonymizedDataNotExists(anon_related_email3, "email")
def test_anonymization_field_matrix_related_all(self): related_email: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL) related_email.save() self.customer._anonymize_obj(fields=('first_name', ('emails', '__ALL__'))) anon_customer: Customer = Customer.objects.get(pk=self.customer.pk) assert_not_equal(anon_customer.first_name, CUSTOMER__FIRST_NAME) self.assertAnonymizedDataExists(anon_customer, 'first_name') assert_equal(anon_customer.last_name, CUSTOMER__LAST_NAME) self.assertAnonymizedDataNotExists(anon_customer, 'last_name') anon_related_email: Email = Email.objects.get(pk=related_email.pk) assert_not_equal(anon_related_email.email, CUSTOMER__EMAIL) self.assertAnonymizedDataExists(anon_related_email, 'email')
def test_email_purpose_related(self): LegalReason.objects.create_consent(EMAIL_SLUG, self.customer) related_email: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL) related_email.save() EmailsPurpose().anonymize_obj(obj=self.customer, fields=("primary_email_address", )) anon_customer = Customer.objects.get(pk=self.customer.pk) assert_equal(anon_customer.primary_email_address, CUSTOMER__EMAIL) self.assertAnonymizedDataNotExists(anon_customer, 'primary_email_address') anon_related_email: Email = Email.objects.get(pk=related_email.pk) assert_equal(anon_related_email.email, CUSTOMER__EMAIL) self.assertAnonymizedDataNotExists(anon_related_email, 'email')
def test_purpose_should_be_set_only_to_the_right_source_model(self): LegalReason.objects.create_consent(FACEBOOK_SLUG, self.customer) with assert_raises(KeyError): LegalReason.objects.create_consent( FACEBOOK_SLUG, Email(customer=self.customer, email=CUSTOMER__EMAIL))
def test_legal_reason_hardcore(self): related_email: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL) related_email.save() related_email2: Email = Email(customer=self.customer, email=CUSTOMER__EMAIL2) related_email2.save() account: Account = Account(customer=self.customer, number=ACCOUNT__NUMBER, owner=ACCOUNT__OWNER) account.save() payment: Payment = Payment(account=account, value=self.fake.pydecimal(left_digits=8, right_digits=2, positive=True)) payment.save() LegalReason.objects.create_consent(FIRST_AND_LAST_NAME_SLUG, self.customer) LegalReason.objects.create_consent(EMAIL_SLUG, self.customer) LegalReason.objects.create_consent(ACCOUNT_SLUG, self.customer) legal = LegalReason.objects.create_consent(EVERYTHING_SLUG, self.customer) legal.expire() anon_customer: Customer = Customer.objects.get(pk=self.customer.pk) anon_related_email: Email = Email.objects.get(pk=related_email.pk) anon_related_email2: Email = Email.objects.get(pk=related_email2.pk) anon_account: Account = Account.objects.get(pk=account.pk) anon_payment: Payment = Payment.objects.get(pk=payment.pk) # Customer - partialy anonymized assert_equal(anon_customer.first_name, CUSTOMER__FIRST_NAME) self.assertAnonymizedDataNotExists(anon_customer, 'first_name') assert_equal(anon_customer.last_name, CUSTOMER__LAST_NAME) self.assertAnonymizedDataNotExists(anon_customer, 'last_name') assert_not_equal(anon_customer.primary_email_address, CUSTOMER__EMAIL) self.assertAnonymizedDataExists(anon_customer, 'primary_email_address') assert_not_equal(anon_customer.birth_date, CUSTOMER__BIRTH_DATE) self.assertAnonymizedDataExists(anon_customer, 'birth_date') assert_not_equal(anon_customer.personal_id, CUSTOMER__PERSONAL_ID) self.assertAnonymizedDataExists(anon_customer, 'personal_id') assert_not_equal(anon_customer.phone_number, CUSTOMER__PHONE_NUMBER) self.assertAnonymizedDataExists(anon_customer, 'phone_number') assert_not_equal(anon_customer.facebook_id, CUSTOMER__FACEBOOK_ID) self.assertAnonymizedDataExists(anon_customer, 'facebook_id') assert_not_equal(anon_customer.last_login_ip, CUSTOMER__IP) self.assertAnonymizedDataExists(anon_customer, 'last_login_ip') # Email - not anonymized assert_equal(anon_related_email.email, CUSTOMER__EMAIL) self.assertAnonymizedDataNotExists(anon_related_email, 'email') assert_equal(anon_related_email2.email, CUSTOMER__EMAIL2) self.assertAnonymizedDataNotExists(anon_related_email2, 'email') # Account - not anonymized assert_equal(anon_account.number, ACCOUNT__NUMBER) self.assertAnonymizedDataNotExists(anon_account, "number") assert_equal(anon_account.owner, ACCOUNT__OWNER) self.assertAnonymizedDataNotExists(anon_account, "owner") # Payment - fully anonymized assert_not_equal(anon_payment.value, payment.value) self.assertAnonymizedDataExists(anon_payment, "value") assert_not_equal(anon_payment.date, payment.date) self.assertAnonymizedDataExists(anon_payment, "date")