From a8762ea49b1afee6ba8914626740254b9ee35a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 24 Oct 2014 10:44:38 +0200 Subject: [PATCH] Add some test tools to ease scenario writing review11331002 --- tests/tools.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/tools.py diff --git a/tests/tools.py b/tests/tools.py new file mode 100644 index 0000000000..2b56d07626 --- /dev/null +++ b/tests/tools.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +#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 datetime +from decimal import Decimal + +from proteus import Model + +__all__ = ['get_currency'] + +_names = { + 'USD': 'U.S. Dollar', + 'EUR': 'Euro', + } +_symbols = { + 'USD': '$', + 'EUR': u'€', + } +_rates = { + 'USD': Decimal('1.0'), + 'EUR': Decimal('2.0'), + } + + +def get_currency(code='USD', config=None): + "Get currency with code" + Currency = Model.get('currency.currency', config=config) + CurrencyRate = Model.get('currency.currency.rate', config=config) + + currencies = Currency.find([('code', '=', code)]) + if not currencies: + currency = Currency(name=_names.get(code, code), + symbol=_symbols.get(code, code), code=code, + rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]', + mon_decimal_point='.', mon_thousands_sep=',') + currency.save() + rate = _rates.get(code) + if rate is not None: + CurrencyRate(date=datetime.date.min, rate=rate, + currency=currency).save() + else: + currency, = currencies + return currency