# Path: protector/models.py
# class GenericGlobalPerm(models.Model):
#     """
#         This model is for defining template-like permissions
#         e.g. Every blog moderator could edit his blog
#     """
#     content_type = models.ForeignKey(
#         ContentType, related_name='global_perms', verbose_name=_('content type'),
#         on_delete=models.CASCADE, null=True
#     )
#     roles = models.IntegerField(verbose_name=_('roles'), default=DEFAULT_ROLE)
#     permission = models.ForeignKey(
#         to=Permission, verbose_name=_('permission'), on_delete=models.CASCADE
#     )
# 
#     class Meta:
#         verbose_name = _('global group permission')
#         verbose_name_plural = _('global group permissions')
#         unique_together = ('content_type', 'permission')


from django.test import TestCase
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.test.utils import override_settings
from test_app.models import TestPost
from protector.models import GenericGlobalPerm

TestUser = get_user_model()


@override_settings(
    DISABLE_GENERIC_PERMISSION_CACHE=True
)
class AutoMemberTest(TestCase):

    def setUp(self):
        self.test_user = TestUser.objects.create(
            username='test1', email='test@test.com'
        )
        self.test_user2 = TestUser.objects.create(
            username='test2', email='test2@test.com'
        )
        self.test_user3 = TestUser.objects.create(
            username='test3', email='test3@test.com'
        )
        self.post = TestPost.objects.create(
            author=self.test_user
        )
        self.manage_post_perm = Permission.objects.get(
            content_type__app_label='test_app',
            codename='manage_post'
        )

# Path: protector/models.py
# class GenericGlobalPerm(models.Model):
#     """
#         This model is for defining template-like permissions
#         e.g. Every blog moderator could edit his blog
#     """
#     content_type = models.ForeignKey(
#         ContentType, related_name='global_perms', verbose_name=_('content type'),
#         on_delete=models.CASCADE, null=True
#     )
#     roles = models.IntegerField(verbose_name=_('roles'), default=DEFAULT_ROLE)
#     permission = models.ForeignKey(
#         to=Permission, verbose_name=_('permission'), on_delete=models.CASCADE
#     )
# 
#     class Meta:
#         verbose_name = _('global group permission')
#         verbose_name_plural = _('global group permissions')
#         unique_together = ('content_type', 'permission')


# Path: test_project/test_app/tests.py
from django.test import TestCase
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.test.utils import override_settings
from test_app.models import TestPost
from protector.models import GenericGlobalPerm


TestUser = get_user_model()


@override_settings(
    DISABLE_GENERIC_PERMISSION_CACHE=True
)
class AutoMemberTest(TestCase):

    def setUp(self):
        self.test_user = TestUser.objects.create(
            username='test1', email='test@test.com'
        )
        self.test_user2 = TestUser.objects.create(
            username='test2', email='test2@test.com'
        )
        self.test_user3 = TestUser.objects.create(
            username='test3', email='test3@test.com'
        )
        self.post = TestPost.objects.create(
            author=self.test_user
        )
        self.manage_post_perm = Permission.objects.get(
            content_type__app_label='test_app',
            codename='manage_post'
        )

        GenericGlobalPerm.objects.create(