From f9e496b3199b6fbd8a8bc8282ce91b00b649b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 6 Feb 2016 19:13:32 +0100 Subject: [PATCH] Make TestCase create and drop its database and use with_transaction decorator. issue5263 review20711002 --- tests/test_timesheet_cost.py | 44 ++++++++++++++---------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/tests/test_timesheet_cost.py b/tests/test_timesheet_cost.py index 3f97e5f8b4..2912a0e77c 100644 --- a/tests/test_timesheet_cost.py +++ b/tests/test_timesheet_cost.py @@ -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