Unit tests fixed.

This commit is contained in:
Antoine Nguyen
2015-02-02 14:21:39 +01:00
parent dde98c235c
commit a8b5c86c8a
34 changed files with 198 additions and 240 deletions
+2
View File
@@ -22,6 +22,8 @@ BASE_EVENTS = [
"PasswordChange",
"UserCanSetRole",
"InitialDataLoaded",
"UserMenuDisplay",
"AdminMenuDisplay",
"GetStaticContent",
+15 -5
View File
@@ -1,27 +1,37 @@
"""Factories for core application."""
import factory
from django.contrib.auth.models import Group
from . import models
class PermissionFactory(factory.DjangoModelFactory):
ABSTRACT_FACTORY = True
class Meta:
abstract = True
@factory.post_generation
def set_permission(self, create, extracted, **kwargs):
if not create:
return
self.post_create(models.User.objects.get(pk=1))
self.post_create(models.User.objects.filter(is_superuser=True).first())
class GroupFactory(factory.DjangoModelFactory):
FACTORY_FOR = Group
class Meta:
model = Group
name = 'DefaultGroup'
class UserFactory(PermissionFactory):
FACTORY_FOR = models.User
FACTORY_DJANGO_GET_OR_CREATE = ("username", )
class Meta:
model = models.User
django_get_or_create = ("username", )
email = factory.LazyAttribute(lambda a: a.username)
password = '{PLAIN}toto'
@@ -25,15 +25,17 @@ class Command(BaseCommand, CloseConnectionMixin):
def handle(self, *args, **options):
"""Command entry point."""
if not User.objects.filter(pk=1, username="admin").exists():
if not User.objects.filter(is_superuser=True).count():
admin = User(username="admin", is_superuser=True)
admin.set_password("password")
admin.save()
ObjectAccess.objects.create(
user=admin, content_object=admin, is_owner=True)
superadmin = User.objects.filter(is_superuser=True).first()
groups = PERMISSIONS.keys() + [
role[0] for role in events.raiseQueryEvent("GetExtraRoles")
role[0] for role
in events.raiseQueryEvent("GetExtraRoles", superadmin)
]
for groupname in groups:
group, created = Group.objects.get_or_create(name=groupname)
@@ -49,3 +51,4 @@ class Command(BaseCommand, CloseConnectionMixin):
for extname in exts_pool.extensions.keys():
extension = exts_pool.get_extension(extname)
extension.load_initial_data()
events.raiseEvent("InitialDataLoaded", extname)