<commit_before>from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from djangotoolbox.contrib.auth.models import Group, User, GroupList, Permission, PermissionList


class GroupPermissionTest(TestCase):

    backend = 'djangotoolbox.contrib.auth.backends.ModelBackend'

    def setUp(self):
        self.curr_auth = settings.AUTHENTICATION_BACKENDS
        settings.AUTHENTICATION_BACKENDS = (self.backend,)
        User.objects.create_user('test', '<EMAIL>', 'test')

    def tearDown(self):
        settings.AUTHENTICATION_BACKENDS = self.curr_auth

    def test_group_perms(self):
        user = User.objects.get(username='test')
        group = Group.objects.create(name='test_group')
        user.group_list.groups.append(group.id)
        user.save()
        content_type=ContentType.objects.get_for_model(Group)
        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
        perm_list = PermissionList.objects.create()
        perm_list.permissions.append(perm.id)
        content_type=ContentType.objects.get_for_model(ContentType)
        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
        perm_list.permissions.append(perm.id)
        perm_list.save()
        group.permissions = perm_list
        group.save()
        self.assertEqual(user.get_group_permissions(), set([u'contenttypes.test_group', u'auth.test_group']))

        pl = PermissionList.objects.create()
        user.user_permissions = pl
        user.save()
        perm = Permission.objects.create(name='perm1', content_type=content_type, codename='perm1')
        pl.permissions.append(perm.id)
        pl.save()

        self.assertEqual(user.has_perm('contenttypes.perm1'),True)
        self.assertEqual(user.get_all_permissions(), set([u'contenttypes.perm1', u'contenttypes.test_group', u'auth.test_group']))<commit_msg>use the new Group|User.objects.create() method<commit_after>from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from djangotoolbox.contrib.auth.models import Group, User, GroupList, Permission, PermissionList


class GroupPermissionTest(TestCase):

    backend = 'djangotoolbox.contrib.auth.backends.ModelBackend'

    def setUp(self):
        self.curr_auth = settings.AUTHENTICATION_BACKENDS
        settings.AUTHENTICATION_BACKENDS = (self.backend,)
        User.objects.create_user('test', '<EMAIL>', 'test')

    def tearDown(self):
        settings.AUTHENTICATION_BACKENDS = self.curr_auth

    def test_group_perms(self):
        user = User.objects.get(username='test')
        group = Group.objects.create(name='test_group')
        
        user.group_list.groups.append(group.id)
        user.save()
        
        content_type=ContentType.objects.get_for_model(Group)
        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')

        group.permissions.permissions.append(perm.id)
        
        content_type=ContentType.objects.get_for_model(ContentType)
        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
        group.permissions.permissions.append(perm.id)
        group.save()
        self.assertEqual(user.get_group_permissions(), set([u'contenttypes.test_group', u'auth.test_group']))

        
        perm = Permission.objects.create(name='perm1', content_type=content_type, codename='perm1')
        user.user_permissions.permissions.append(perm.id)
        user.save()

        self.assertEqual(user.has_perm('contenttypes.perm1'),True)
        self.assertEqual(user.get_all_permissions(), set([u'contenttypes.perm1', u'contenttypes.test_group', u'auth.test_group']))
{'fraction_non_alphanumeric': 0.11490683229813664, 'fraction_numerical': 0.002070393374741201, 'mean_word_length': 3.9235668789808917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5617393', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1132, 'n_words': 157}