Make TestCase create and drop its database
and use with_transaction decorator. issue5263 review20711002
This commit is contained in:
@@ -4,80 +4,69 @@ import unittest
|
||||
import doctest
|
||||
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.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from trytond.modules.currency.tests import create_currency
|
||||
|
||||
|
||||
class CarrierWeightTestCase(ModuleTestCase):
|
||||
'Test CarrierWeight module'
|
||||
class CarrierPercentageTestCase(ModuleTestCase):
|
||||
'Test CarrierPercentage module'
|
||||
module = 'carrier_percentage'
|
||||
|
||||
def setUp(self):
|
||||
super(CarrierWeightTestCase, self).setUp()
|
||||
self.party = POOL.get('party.party')
|
||||
self.uom = POOL.get('product.uom')
|
||||
self.template = POOL.get('product.template')
|
||||
self.product = POOL.get('product.product')
|
||||
self.category = POOL.get('product.category')
|
||||
self.currency = POOL.get('currency.currency')
|
||||
self.carrier = POOL.get('carrier')
|
||||
|
||||
def test0010compute_percentage(self):
|
||||
@with_transaction()
|
||||
def test_compute_percentage(self):
|
||||
'Test compute_percentage'
|
||||
with Transaction().start(DB_NAME, USER, context=CONTEXT):
|
||||
party, = self.party.create([{
|
||||
'name': 'Carrier',
|
||||
}])
|
||||
uom, = self.uom.search([
|
||||
('name', '=', 'Unit'),
|
||||
])
|
||||
category, = self.category.create([{
|
||||
'name': 'Category',
|
||||
}])
|
||||
template, = self.template.create([{
|
||||
'name': 'Carrier',
|
||||
'default_uom': uom.id,
|
||||
'category': category.id,
|
||||
'type': 'service',
|
||||
'list_price': Decimal(0),
|
||||
'cost_price': Decimal(0),
|
||||
}])
|
||||
product, = self.product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
currency, = self.currency.search([
|
||||
('code', '=', 'cu1'),
|
||||
])
|
||||
carrier, = self.carrier.create([{
|
||||
'party': party.id,
|
||||
'carrier_product': product.id,
|
||||
'carrier_cost_method': 'percentage',
|
||||
'percentage': Decimal(15),
|
||||
}])
|
||||
for amount, price in [
|
||||
(Decimal(0), Decimal(0)),
|
||||
(Decimal(100), Decimal('15.00')),
|
||||
(Decimal(150), Decimal('22.50')),
|
||||
]:
|
||||
self.assertEqual(
|
||||
carrier.compute_percentage(amount, currency.id),
|
||||
(price, currency.id))
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Uom = pool.get('product.uom')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Category = pool.get('product.category')
|
||||
Carrier = pool.get('carrier')
|
||||
|
||||
party, = Party.create([{
|
||||
'name': 'Carrier',
|
||||
}])
|
||||
uom, = Uom.search([
|
||||
('name', '=', 'Unit'),
|
||||
])
|
||||
category, = Category.create([{
|
||||
'name': 'Category',
|
||||
}])
|
||||
template, = Template.create([{
|
||||
'name': 'Carrier',
|
||||
'default_uom': uom.id,
|
||||
'category': category.id,
|
||||
'type': 'service',
|
||||
'list_price': Decimal(0),
|
||||
'cost_price': Decimal(0),
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
currency = create_currency('cu1')
|
||||
carrier, = Carrier.create([{
|
||||
'party': party.id,
|
||||
'carrier_product': product.id,
|
||||
'carrier_cost_method': 'percentage',
|
||||
'percentage': Decimal(15),
|
||||
}])
|
||||
for amount, price in [
|
||||
(Decimal(0), Decimal(0)),
|
||||
(Decimal(100), Decimal('15.00')),
|
||||
(Decimal(150), Decimal('22.50')),
|
||||
]:
|
||||
self.assertEqual(
|
||||
carrier.compute_percentage(amount, currency.id),
|
||||
(price, currency.id))
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
from trytond.modules.product.tests import test_product
|
||||
for test in test_product.suite():
|
||||
if test not in suite and not isinstance(test, doctest.DocTestCase):
|
||||
suite.addTest(test)
|
||||
from trytond.modules.currency.tests import test_currency
|
||||
for test in test_currency.suite():
|
||||
if test not in suite and not isinstance(test, doctest.DocTestCase):
|
||||
suite.addTest(test)
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
CarrierWeightTestCase))
|
||||
CarrierPercentageTestCase))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_carrier_percentage_with_purchase_shipment_cost.rst',
|
||||
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
|
||||
|
||||
Reference in New Issue
Block a user