def test_principal_cleanup_none(self): """Test that we can run a principal clean up on a tenant with no principals.""" try: clean_tenant_principals(self.tenant) except Exception: self.fail(msg='clean_tenant_principals encountered an exception') with tenant_context(self.tenant): self.assertEqual(Principal.objects.count(), 0)
def test_principal_cleanup_princpal_exists(self, mock_request): """Test that we can run a principal clean up on a tenant with an existing principal.""" with tenant_context(self.tenant): self.principal = Principal(username='******') self.principal.save() try: clean_tenant_principals(self.tenant) except Exception: self.fail(msg='clean_tenant_principals encountered an exception') with tenant_context(self.tenant): self.assertEqual(Principal.objects.count(), 1)
def test_principal_cleanup_princpal_error(self, mock_request): """Test that we can handle a principal clean up with an unexpected error from proxy.""" with tenant_context(self.tenant): self.principal = Principal(username='******') self.principal.save() try: clean_tenant_principals(self.tenant) except Exception: self.fail(msg='clean_tenant_principals encountered an exception') with tenant_context(self.tenant): self.assertEqual(Principal.objects.count(), 1)
def test_principal_cleanup_principal_not_in_group(self, mock_request): """Test that we can run a principal clean up on a tenant with a principal not in a group.""" with tenant_context(self.tenant): self.principal = Principal(username="******") self.principal.save() try: clean_tenant_principals(self.tenant) except Exception: self.fail(msg="clean_tenant_principals encountered an exception") with tenant_context(self.tenant): self.assertEqual(Principal.objects.count(), 0)