diff --git a/smash/web/tests/__init__.py b/smash/web/tests/__init__.py index 915d82c0bd85fec22b86d0d5f64c16e9f10fd818..bf24a02c5d39827dcfe705b1ce4f57980458e89b 100644 --- a/smash/web/tests/__init__.py +++ b/smash/web/tests/__init__.py @@ -1,15 +1,22 @@ import logging import os +import sys + from django.conf import settings from django.contrib.auth.models import User from django.test import Client from django.test import TestCase -from web.models import Worker -from web.decorators import PermissionDecorator +from web.decorators import PermissionDecorator +from web.models import Worker from .functions import create_worker, create_user, add_permissions_to_worker -settings.MEDIA_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') +# if manage.py test was called, use test settings +if 'test' in sys.argv: + try: + settings.MEDIA_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') + except ImportError: + pass logger = logging.getLogger(__name__) @@ -19,7 +26,7 @@ class LoggedInTestCase(TestCase): self.password = 'abcd1234' #superuser self.super_worker = create_worker(user=User.objects.create_superuser(username='super', password=self.password, email='a@mail.com')) - #admin + #admin self.admin_worker = Worker.get_by_user(create_user(username='admin', password=self.password)) add_permissions_to_worker(self.admin_worker, PermissionDecorator.codenames) #staff @@ -34,15 +41,15 @@ class LoggedInTestCase(TestCase): def login_as_staff(self): self.client.logout() - self.client.login(username='staff', password=self.password) + self.client.login(username='staff', password=self.password) def login_as_admin(self): self.client.logout() - self.client.login(username='admin', password=self.password) + self.client.login(username='admin', password=self.password) def login_as_super(self): self.client.logout() - self.client.login(username='super', password=self.password) + self.client.login(username='super', password=self.password) class LoggedInWithWorkerTestCase(LoggedInTestCase):