From 07fb7e396eb0277902fe72f647346d800e16abac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 24 Oct 2014 10:44:48 +0200 Subject: [PATCH] Add some test tools to ease scenario writing review11331002 --- tests/scenario_product_cost_fifo.rst | 56 ++++++++-------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/tests/scenario_product_cost_fifo.rst b/tests/scenario_product_cost_fifo.rst index 1c53766c77..20960ddd63 100644 --- a/tests/scenario_product_cost_fifo.rst +++ b/tests/scenario_product_cost_fifo.rst @@ -2,16 +2,14 @@ Stock FIFO Cost Price ===================== -============= -General Setup -============= - Imports:: >>> import datetime >>> from dateutil.relativedelta import relativedelta >>> from decimal import Decimal >>> from proteus import config, Model, Wizard + >>> from trytond.modules.company.tests.tools import create_company, \ + ... get_company >>> today = datetime.date.today() Create database:: @@ -22,35 +20,14 @@ Create database:: Install stock Module:: >>> Module = Model.get('ir.module.module') - >>> modules = Module.find([('name', '=', 'product_cost_fifo')]) - >>> Module.install([x.id for x in modules], config.context) + >>> module, = Module.find([('name', '=', 'product_cost_fifo')]) + >>> module.click('install') >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: - >>> Currency = Model.get('currency.currency') - >>> CurrencyRate = Model.get('currency.currency.rate') - >>> Company = Model.get('company.company') - >>> Party = Model.get('party.party') - >>> company_config = Wizard('company.company.config') - >>> company_config.execute('company') - >>> company = company_config.form - >>> party = Party(name='Dunder Mifflin') - >>> party.save() - >>> company.party = party - >>> currencies = Currency.find([('code', '=', 'USD')]) - >>> if not currencies: - ... currency = Currency(name='US Dollar', symbol='$', code='USD', - ... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]', - ... mon_decimal_point='.') - ... currency.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('1.0'), currency=currency).save() - ... else: - ... currency, = currencies - >>> company.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find() + >>> _ = create_company() + >>> company = get_company() Reload the context:: @@ -94,9 +71,8 @@ Make 4 units of the product available @ 10 :: >>> incoming_move.planned_date = today >>> incoming_move.company = company >>> incoming_move.unit_price = Decimal('10') - >>> incoming_move.currency = currency - >>> incoming_move.save() - >>> StockMove.do([incoming_move.id], config.context) + >>> incoming_move.currency = company.currency + >>> incoming_move.click('do') Check Cost Price is 10:: @@ -115,9 +91,8 @@ Add 2 more units @ 25:: >>> incoming_move.planned_date = today >>> incoming_move.company = company >>> incoming_move.unit_price = Decimal('25') - >>> incoming_move.currency = currency - >>> incoming_move.save() - >>> StockMove.do([incoming_move.id], config.context) + >>> incoming_move.currency = company.currency + >>> incoming_move.click('do') Check Cost Price FIFO is 15:: @@ -136,9 +111,8 @@ Sell 3 units @ 50:: >>> outgoing_move.planned_date = today >>> outgoing_move.company = company >>> outgoing_move.unit_price = Decimal('50') - >>> outgoing_move.currency = currency - >>> outgoing_move.save() - >>> StockMove.do([outgoing_move.id], config.context) + >>> outgoing_move.currency = company.currency + >>> outgoing_move.click('do') Check Cost Price FIFO is 20:: @@ -158,7 +132,7 @@ Sell twice 1 more units @ 50:: >>> outgoing_move.planned_date = today >>> outgoing_move.company = company >>> outgoing_move.unit_price = Decimal('50') - >>> outgoing_move.currency = currency + >>> outgoing_move.currency = company.currency >>> outgoing_move.save() >>> outgoing_moves.append(outgoing_move) @@ -171,11 +145,11 @@ Sell twice 1 more units @ 50:: >>> outgoing_move.planned_date = today >>> outgoing_move.company = company >>> outgoing_move.unit_price = Decimal('50') - >>> outgoing_move.currency = currency + >>> outgoing_move.currency = company.currency >>> outgoing_move.save() >>> outgoing_moves.append(outgoing_move) - >>> StockMove.do([m.id for m in outgoing_moves], config.context) + >>> StockMove.click(outgoing_moves, 'do') Check Cost Price FIFO is 25::