2017-02-01 23:11:39 +00:00
|
|
|
from django import db
|
2016-11-01 19:11:36 +00:00
|
|
|
from django.contrib.auth.models import User
|
2016-10-12 14:44:14 +00:00
|
|
|
from django.test import TestCase
|
2017-02-01 23:11:39 +00:00
|
|
|
from django.test import TransactionTestCase
|
2016-11-01 19:11:36 +00:00
|
|
|
|
2016-10-12 14:44:14 +00:00
|
|
|
from app.boot import boot
|
2016-11-01 19:11:36 +00:00
|
|
|
from app.models import Project
|
|
|
|
|
2016-10-12 14:44:14 +00:00
|
|
|
|
2017-02-01 23:11:39 +00:00
|
|
|
def setupUsers():
|
|
|
|
User.objects.create_superuser(username='testsuperuser',
|
|
|
|
email='superuser@test.com',
|
|
|
|
password='test1234')
|
|
|
|
User.objects.create_user(username='testuser',
|
|
|
|
email='user@test.com',
|
|
|
|
password='test1234')
|
|
|
|
User.objects.create_user(username='testuser2',
|
|
|
|
email='user2@test.com',
|
|
|
|
password='test1234')
|
|
|
|
|
|
|
|
|
|
|
|
def setupProjects():
|
|
|
|
Project.objects.create(
|
|
|
|
owner=User.objects.get(username="testsuperuser"),
|
|
|
|
name="Super User Test Project",
|
|
|
|
description="This is a test project"
|
|
|
|
)
|
|
|
|
Project.objects.create(
|
|
|
|
owner=User.objects.get(username="testuser"),
|
|
|
|
name="User Test Project",
|
|
|
|
description="This is a test project"
|
|
|
|
)
|
|
|
|
Project.objects.create(
|
|
|
|
owner=User.objects.get(username="testuser2"),
|
|
|
|
name="User 2 Test Project",
|
|
|
|
description="This is a test project"
|
|
|
|
)
|
|
|
|
|
2016-10-12 14:44:14 +00:00
|
|
|
class BootTestCase(TestCase):
|
|
|
|
'''
|
|
|
|
This class provides optional default mock data as well as
|
|
|
|
proper boot initialization code. All tests for the app
|
|
|
|
module should derive from this class instead of TestCase.
|
|
|
|
|
|
|
|
We don't use fixtures because we have signal initialization login
|
2016-10-24 18:14:35 +00:00
|
|
|
for some models, which doesn't play well with them.
|
2016-10-12 14:44:14 +00:00
|
|
|
'''
|
|
|
|
@classmethod
|
2017-02-01 23:11:39 +00:00
|
|
|
def setUpTestData(cls):
|
|
|
|
super(BootTestCase, cls).setUpTestData()
|
2016-10-12 14:44:14 +00:00
|
|
|
boot()
|
|
|
|
setupUsers()
|
|
|
|
setupProjects()
|
2016-10-24 18:14:35 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(BootTestCase, cls).tearDownClass()
|
2017-02-01 23:11:39 +00:00
|
|
|
|
2017-02-06 03:23:02 +00:00
|
|
|
|
2017-02-01 23:11:39 +00:00
|
|
|
class BootTransactionTestCase(TransactionTestCase):
|
|
|
|
'''
|
|
|
|
Same as above, but inherits from TransactionTestCase
|
|
|
|
'''
|
2017-02-15 19:20:41 +00:00
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
2017-02-01 23:11:39 +00:00
|
|
|
boot()
|
|
|
|
setupUsers()
|
|
|
|
setupProjects()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(BootTransactionTestCase, cls).tearDownClass()
|