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:13:32 +01:00
1 parent 76b722bf68
commit f9e496b319
1 file changed
+17 -27
+17 -27
View File
@@ -1,31 +1,28 @@
# 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
from decimal import Decimal
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 TimesheetCostTestCase(ModuleTestCase):
'Test TimesheetCost module'
module = 'timesheet_cost'
def setUp(self):
super(TimesheetCostTestCase, self).setUp()
self.party = POOL.get('party.party')
self.employee = POOL.get('company.employee')
self.employee_cost_price = POOL.get('company.employee_cost_price')
self.company = POOL.get('company.company')
self.work = POOL.get('timesheet.work')
self.line = POOL.get('timesheet.line')
def test0010compute_cost_price(self):
@with_transaction()
def test_compute_cost_price(self):
'Test compute_cost_price'
pool = Pool()
Party = pool.get('party.party')
Employee = pool.get('company.employee')
EmployeeCostPrice = pool.get('company.employee_cost_price')
cost_prices = [
(datetime.date(2011, 1, 1), Decimal(10)),
(datetime.date(2012, 1, 1), Decimal(15)),
@@ -40,17 +37,14 @@ class TimesheetCostTestCase(ModuleTestCase):
(datetime.date(2013, 1, 1), Decimal(20)),
(datetime.date(2013, 6, 1), Decimal(20)),
]
with Transaction().start(DB_NAME, USER, context=CONTEXT):
company, = self.company.search([
('rec_name', '=', 'Dunder Mifflin'),
])
party = self.party(name='Pam Beesly')
party.save()
employee = self.employee(party=party.id,
company=company)
party = Party(name='Pam Beesly')
party.save()
company = create_company()
with set_company(company):
employee = Employee(party=party.id, company=company)
employee.save()
for date, cost_price in cost_prices:
self.employee_cost_price(
EmployeeCostPrice(
employee=employee,
date=date,
cost_price=cost_price).save()
@@ -60,10 +54,6 @@ class TimesheetCostTestCase(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(
TimesheetCostTestCase))
return suite