Make TestCase create and drop its database

and use with_transaction decorator.

issue5263
review20711002
This commit is contained in:
Cédric Krier committed 2016-02-06 19:12:57 +01:00
1 parent 930dbf4939
commit c08c0e1cf4
1 file changed
+23 -32
+23 -32
View File
@@ -1,50 +1,45 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import unittest
import doctest
import datetime
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.modules.company.tests import create_company, set_company
class ProjectTestCase(ModuleTestCase):
'Test Project module'
module = 'project'
def setUp(self):
super(ProjectTestCase, self).setUp()
trytond.tests.test_tryton.install_module('project')
self.timesheet_work = POOL.get('timesheet.work')
self.project_work = POOL.get('project.work')
self.company = POOL.get('company.company')
def test0010sum_tree(self):
@with_transaction()
def test_sum_tree(self):
'Test sum_tree'
with Transaction().start(DB_NAME, USER, context=CONTEXT):
company, = self.company.search([
('rec_name', '=', 'Dunder Mifflin'),
])
pool = Pool()
TimesheetWork = pool.get('timesheet.work')
ProjectWork = pool.get('project.work')
t_work_1, = self.timesheet_work.create([{
company = create_company()
with set_company(company):
t_work_1, = TimesheetWork.create([{
'name': 'Work 1',
'company': company.id,
}])
p_work_1, = self.project_work.create([{
p_work_1, = ProjectWork.create([{
'name': 'Work 1',
'company': company.id,
'work': t_work_1.id,
'effort_duration': datetime.timedelta(hours=1),
}])
t_work_1_1, = self.timesheet_work.create([{
t_work_1_1, = TimesheetWork.create([{
'name': 'Work 1 1',
'company': company.id,
'parent': t_work_1.id,
}])
p_work_1_1, = self.project_work.create([{
p_work_1_1, = ProjectWork.create([{
'name': 'Work 1 1',
'company': company.id,
'parent': p_work_1.id,
@@ -52,12 +47,12 @@ class ProjectTestCase(ModuleTestCase):
'effort_duration': datetime.timedelta(hours=1),
}])
t_work_1_2, = self.timesheet_work.create([{
t_work_1_2, = TimesheetWork.create([{
'name': 'Work 1 1',
'company': company.id,
'parent': t_work_1.id,
}])
p_work_1_2, = self.project_work.create([{
p_work_1_2, = ProjectWork.create([{
'name': 'Work 1 2',
'company': company.id,
'parent': p_work_1.id,
@@ -65,12 +60,12 @@ class ProjectTestCase(ModuleTestCase):
'effort_duration': datetime.timedelta(hours=1),
}])
t_work_1_1_1, = self.timesheet_work.create([{
t_work_1_1_1, = TimesheetWork.create([{
'name': 'Work 1 1 1',
'company': company.id,
'parent': t_work_1_1.id,
}])
p_work_1_1_1, = self.project_work.create([{
p_work_1_1_1, = ProjectWork.create([{
'name': 'Work 1 1 1',
'company': company.id,
'parent': p_work_1_1.id,
@@ -78,12 +73,12 @@ class ProjectTestCase(ModuleTestCase):
'effort_duration': datetime.timedelta(hours=1),
}])
t_work_1_1_2, = self.timesheet_work.create([{
t_work_1_1_2, = TimesheetWork.create([{
'name': 'Work 1 1 2',
'company': company.id,
'parent': t_work_1_1.id,
}])
p_work_1_1_2, = self.project_work.create([{
p_work_1_1_2, = ProjectWork.create([{
'name': 'Work 1 1 2',
'company': company.id,
'parent': p_work_1_1.id,
@@ -91,12 +86,12 @@ class ProjectTestCase(ModuleTestCase):
'effort_duration': datetime.timedelta(hours=1),
}])
t_work_1_1_3, = self.timesheet_work.create([{
t_work_1_1_3, = TimesheetWork.create([{
'name': 'Work 1 1 3',
'company': company.id,
'parent': t_work_1_1.id,
}])
p_work_1_1_3, = self.project_work.create([{
p_work_1_1_3, = ProjectWork.create([{
'name': 'Work 1 1 3',
'company': company.id,
'parent': p_work_1_1.id,
@@ -118,10 +113,6 @@ class ProjectTestCase(ModuleTestCase):
def suite():
suite = trytond.tests.test_tryton.suite()
from trytond.modules.company.tests import test_company
for test in test_company.suite():
if test not in suite and not isinstance(test, doctest.DocTestCase):
suite.addTest(test)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
ProjectTestCase))
return suite