Suppose that I want to write a test to make sure that a permission does not exist. I want the following test to pass (instead it gives an error):
from django.test import TestCase
from django.contrib.auth.models import Permission
class TestPermission(TestCase):
def test_existence_of_permission(self):
self.assertIsNone(Permission.objects.get(codename='a_non_existant_permission'))
This gives me the following error:
django.contrib.auth.models.DoesNotExist: Permission matching query does not exist.
How can I test the non-existence of this permission?