<commit_before># -*- coding: utf-8 -*-

"""Main test script."""

from django.contrib.auth.models import User
from django.db import models

from django.test import TestCase

from django_fake_model import models as f

from accesscontrol import Control, Permission
from accesscontrol.dsm import DSM
from accesscontrol.models import Access, AccessAttempt


class FakeUser(f.FakeModel, User):
    """Fake user model."""


class FakeResource(f.FakeModel, models.Model):
    """Fake resource model."""

    name = models.CharField(max_length=100)


class FakeResourceAccess(f.FakeModel, Access):
    """Fake resource access model with implicit_perms method."""

    @classmethod
    def implicit_perms(cls, user, resource=None):
        """
        Implicit permissions based on IDs.

        If the user has the same id than the resource, then we assume he has
        all permissions on the resource.

        If resource is None, then the user has permission to create this
        type of resource.

        Else, he has no permissions at all.
        """
        user_id, resource_id = Access._user_resource_id(user, resource)
        if user_id == resource_id:
            return Permission.ALL
        elif resource is None:
            return Permission.CREATE,
        return ()


class FakeResourceAccessAttempt(f.FakeModel, AccessAttempt):
    """Fake resource access attempt model."""


authorize, allow, deny, forget = Control({
    FakeResource: (FakeResourceAccess, FakeResourceAccessAttempt)
}).get_controls()


@FakeUser.fake_me
@FakeResource.fake_me
@FakeResourceAccess.fake_me
@FakeResourceAccessAttempt.fake_me
class MainTestCase(TestCase):
    """Main Django test case."""

    def setUp(self):<commit_msg>Fix tests<commit_after># -*- coding: utf-8 -*-

"""Main test script."""

from django.contrib.auth.models import User
from django.db import models

from django.test import TestCase

from django_fake_model import models as f

from accesscontrol import Control, Permission
from accesscontrol.dsm import DSM
from accesscontrol.models import Access, AccessAttempt


class FakeUser(f.FakeModel, User):
    """Fake user model."""


class FakeResource(f.FakeModel, models.Model):
    """Fake resource model."""

    name = models.CharField(max_length=100)


class FakeResourceAccess(f.FakeModel, Access):
    """Fake resource access model with implicit_perms method."""

    @classmethod
    def implicit_perms(cls, user, resource=None):
        """
        Implicit permissions based on IDs.

        If the user has the same id than the resource, then we assume he has
        all permissions on the resource.

        If resource is None, then the user has permission to create this
        type of resource.

        Else, he has no permissions at all.
        """
        user_id, resource_id = cls.user_resource_id(user, resource)
        if user_id == resource_id:
            return Permission.ALL
        elif resource is None:
            return Permission.CREATE,
        return ()


class FakeResourceAccessAttempt(f.FakeModel, AccessAttempt):
    """Fake resource access attempt model."""


authorize, allow, deny, forget = Control({
    FakeResource: (FakeResourceAccess, FakeResourceAccessAttempt)
}).get_controls()


@FakeUser.fake_me
@FakeResource.fake_me
@FakeResourceAccess.fake_me
@FakeResourceAccessAttempt.fake_me
class MainTestCase(TestCase):
    """Main Django test case."""

    def setUp(self):
{'fraction_non_alphanumeric': 0.08916083916083917, 'fraction_numerical': 0.002331002331002331, 'mean_word_length': 3.4354005167958657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1333453', 'n_tokens_mistral': 958, 'n_tokens_neox': 904, 'n_words': 318}