# Path: tutelary/models.py
# class Policy(models.Model):
#     """An individual policy has a name and a JSON policy body.  Changes to
#     policies are audited.
# 
#     """
# 
#     name = models.CharField(max_length=200)
#     """Policy name field."""
# 
#     body = models.TextField()
#     """Policy JSON body."""
# 
#     audit_log = AuditLog()
# 
#     def __str__(self):
#         return self.name
# 
#     def variable_names(self):
#         pat = re.compile(r'\$(?:([_a-z][_a-z0-9]*)|{([_a-z][_a-z0-9]*)})')
#         return set([m[0] for m in re.findall(pat, self.body)])
# 
#     def save(self, *args, **kwargs):
#         super().save(*args, **kwargs)
#         self.refresh()
# 
#     def refresh(self):
#         for pset in _policy_psets([self]):
#             pset.refresh()
# 
# class Role(models.Model):
#     """A policy role has a name, a sequence of policies and a set of
#     variable assignments.  Changes to roles are audited.
# 
#     """
# 
#     name = models.CharField(max_length=200)
#     """Role name field."""
# 
#     policies = models.ManyToManyField(Policy, through=RolePolicyAssign)
# 
#     variables = models.TextField()
#     """JSON dump of dictionary giving variable assignments for role.
# 
#     """
# 
#     audit_log = AuditLog()
# 
#     objects = RoleManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def variable_names(self):
#         return set().union(*[p.variable_names() for p in self.policies.all()])
# 
#     def delete(self, *args, **kwargs):
#         RolePolicyAssign.objects.filter(role=self).delete()
#         super().delete(*args, **kwargs)


import os.path
import factory
from tutelary.models import Policy, Role
from django.contrib.auth.models import User



class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User


class PolicyFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Policy

    @classmethod

# Path: tutelary/models.py
# class Policy(models.Model):
#     """An individual policy has a name and a JSON policy body.  Changes to
#     policies are audited.
# 
#     """
# 
#     name = models.CharField(max_length=200)
#     """Policy name field."""
# 
#     body = models.TextField()
#     """Policy JSON body."""
# 
#     audit_log = AuditLog()
# 
#     def __str__(self):
#         return self.name
# 
#     def variable_names(self):
#         pat = re.compile(r'\$(?:([_a-z][_a-z0-9]*)|{([_a-z][_a-z0-9]*)})')
#         return set([m[0] for m in re.findall(pat, self.body)])
# 
#     def save(self, *args, **kwargs):
#         super().save(*args, **kwargs)
#         self.refresh()
# 
#     def refresh(self):
#         for pset in _policy_psets([self]):
#             pset.refresh()
# 
# class Role(models.Model):
#     """A policy role has a name, a sequence of policies and a set of
#     variable assignments.  Changes to roles are audited.
# 
#     """
# 
#     name = models.CharField(max_length=200)
#     """Role name field."""
# 
#     policies = models.ManyToManyField(Policy, through=RolePolicyAssign)
# 
#     variables = models.TextField()
#     """JSON dump of dictionary giving variable assignments for role.
# 
#     """
# 
#     audit_log = AuditLog()
# 
#     objects = RoleManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def variable_names(self):
#         return set().union(*[p.variable_names() for p in self.policies.all()])
# 
#     def delete(self, *args, **kwargs):
#         RolePolicyAssign.objects.filter(role=self).delete()
#         super().delete(*args, **kwargs)


# Path: tests/factories.py
import os.path
import factory
from tutelary.models import Policy, Role
from django.contrib.auth.models import User




class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User


class PolicyFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Policy

    @classmethod

    def set_directory(cls, dir):