[Django]-Checking the existence of a permission object in Django unit test

4👍

I figured this out:

I should have treatead Permission as a regular Django model.

from django.test import TestCase
from django.contrib.auth.models import Permission

class TestPermission(TestCase):
  def test_existence_of_permission(self):
    self.assertFalse(Permission.objects.filter(
      codename='a_non_existant_permission').exists())
👤HBat

Leave a comment