def test_complex_order_tax(include_taxes): tax = get_default_tax() quantities = [44, 23, 65] product = get_default_product() supplier = get_default_supplier() shop = get_default_shop() shop.prices_include_tax = include_taxes shop.save() order = create_empty_order(shop=shop) order.full_clean() order.save() pricing_context = get_pricing_module().get_context_from_data( shop=shop, customer=order.customer or AnonymousContact(), ) total_price = Decimal("0") price = Decimal("50") for quantity in quantities: total_price += quantity * price add_product_to_order(order, supplier, product, quantity, price, tax.rate, pricing_context) order.cache_prices() order.save() currency = "EUR" summary = order.get_tax_summary()[0] assert summary.tax_rate == tax.rate assert summary.based_on == Money(total_price, currency) assert summary.tax_amount == Money(total_price * tax.rate, currency) assert summary.taxful == summary.based_on + summary.tax_amount assert order.get_total_tax_amount() == Money(total_price * tax.rate, currency)
def test_as_rounded_values(currency, digits): set_precision_provider(babel_precision_provider.get_precision) amounts = [ '1', '2', '3', '4', '1.23223', '12.24442', '42.26233', '1223.46636', '13.24655', '411.234554', '101.74363', '12.99346', '4222.57422', '112.93549', '199.2446', '422.29234', '1994.49654', '940.23452', '425.24566', '1994.496541234566', '940.2345298765', '425.2456612334', ] for amount in amounts: precision = Decimal('0.1') ** digits rounded = Decimal(amount).quantize(precision) rounded2 = Decimal(amount).quantize(Decimal('0.01')) rounded3 = Decimal(amount).quantize(Decimal('0.001')) # test using the currency assert Money(amount, currency).as_rounded().value == rounded # test using digits assert Money(amount, currency).as_rounded(3).value == rounded3 # test using not existent currency code assert Money(amount, "XTS").as_rounded().value == rounded2
def test_money_property_set(): w = get_wallet() w.amount = Money(3, 'EUR') assert w.amount == Money(3, 'EUR') assert w.value == 3 assert type(w.value) == Decimal assert w.currency == 'EUR'
def test_refund_without_shipment(restock): shop = get_default_shop() supplier = get_simple_supplier() product = create_product( "test-sku", shop=get_default_shop(), default_price=10, ) # Start out with a supplier with quantity of 10 of a product supplier.adjust_stock(product.id, 10) check_stock_counts(supplier, product, physical=10, logical=10) order = create_order_with_product(product, supplier, 2, 200, shop=shop) order.cache_prices() check_stock_counts(supplier, product, physical=10, logical=8) # Restock value shouldn't matter if we don't have any shipments product_line = order.lines.first() order.create_refund([ {"line": product_line, "quantity": 2, "amount": Money(400, order.currency), "restock_products": restock}]) if restock: check_stock_counts(supplier, product, physical=10, logical=10) else: check_stock_counts(supplier, product, physical=10, logical=8) assert product_line.refunded_quantity == 2 assert order.get_total_tax_amount() == Money( order.taxful_total_price_value - order.taxless_total_price_value, order.currency)
def test_money_basics(): m1 = Money(1, 'EUR') m2 = Money(2, 'EUR') m3 = Money(3, 'EUR') assert m1 + m2 == m3 assert m3 - m1 == m2 assert m3.value == 3 assert m3 / m2 == m3.value / m2.value
def test_multiplication(self): d = Money.dollar(5) f = Money.franc(5) # test dollar multiplication self.assertEqual(Money(10, "USD"), d.times(2)) self.assertEqual(Money(15, "USD"), d.times(3)) # test franc multiplication self.assertEqual(Money(15, "CHF"), f.times(3)) self.assertEqual(Money(10, "CHF"), f.times(2))
def __init__(self): self._stan = m.Money() #self._stan.dodaj(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) # sytuacja gdzie automat ma tylko jeden grosz self._stan.dodaj(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10) self._wplacone = m.Money() self._wplacone.dodaj(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) self._suma = m.Money() #stan automatu + wplaconych pieniędzy self._suma = m.Money.suma(self._stan, self._wplacone)
def test_refund_with_shipment(restock): shop = get_default_shop() supplier = get_simple_supplier() product = create_product( "test-sku", shop=get_default_shop(), default_price=10, ) # Start out with a supplier with quantity of 10 of a product supplier.adjust_stock(product.id, 10) check_stock_counts(supplier, product, physical=10, logical=10) # Order 4 products, make sure product counts are accurate order = create_order_with_product(product, supplier, 4, 200, shop=shop) order.cache_prices() check_stock_counts(supplier, product, physical=10, logical=6) product_line = order.lines.first() # Shipment should decrease physical count by 2, logical by none order.create_shipment({product_line.product: 2}, supplier=supplier) check_stock_counts(supplier, product, physical=8, logical=6) assert order.shipping_status == ShippingStatus.PARTIALLY_SHIPPED # Check correct refunded quantities assert not product_line.refunded_quantity # Create a refund that refunds from unshipped quantity first, then shipped quantity, check stocks check_stock_counts(supplier, product, physical=8, logical=6) order.create_refund([ {"line": product_line, "quantity": 3, "amount": Money(600, order.currency), "restock_products": restock}]) assert product_line.refunded_quantity == 3 assert order.shipping_status == ShippingStatus.FULLY_SHIPPED if restock: check_stock_counts(supplier, product, physical=9, logical=9) else: check_stock_counts(supplier, product, physical=8, logical=6) # Create a second refund that refunds the last shipped quantity, check stocks order.create_refund([ {"line": product_line, "quantity": 1, "amount": Money(200, order.currency), "restock_products": restock}]) assert product_line.refunded_quantity == 4 if restock: # Make sure we're not restocking more than maximum restockable quantity check_stock_counts(supplier, product, physical=10, logical=10) else: # Make sure maximum restockable quantity is not 0 check_stock_counts(supplier, product, physical=8, logical=6) assert order.get_total_tax_amount() == Money( order.taxful_total_price_value - order.taxless_total_price_value, order.currency)
def test_basic_order(): PRODUCTS_TO_SEND = 10 product = get_default_product() supplier = get_default_supplier() order = create_order_with_product( product, supplier=supplier, quantity=PRODUCTS_TO_SEND, taxless_base_unit_price=10, tax_rate=Decimal("0.5") ) assert order.shop.prices_include_tax is False price = order.shop.create_price currency = order.currency discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER) discount_order_line.discount_amount = price(30) assert discount_order_line.price == price(-30) discount_order_line.save() order.cache_prices() order.check_all_verified() order.save() assert order.taxful_total_price == TaxfulPrice(PRODUCTS_TO_SEND * (10 + 5) - 30, currency) shipment = order.create_shipment_of_all_products(supplier=supplier) assert shipment.total_products == PRODUCTS_TO_SEND, "All products were shipped" assert shipment.weight == product.gross_weight * PRODUCTS_TO_SEND / 1000, "Gravity works" assert not order.get_unshipped_products(), "Nothing was left in the warehouse" order.shipping_status = ShippingStatus.FULLY_SHIPPED order.create_payment(order.taxful_total_price) assert order.payments.exists(), "A payment was created" with pytest.raises(NoPaymentToCreateException): order.create_payment(Money(6, currency)) assert order.is_paid(), "Order got paid" assert order.can_set_complete(), "Finalization is possible" order.status = OrderStatus.objects.get_default_complete() assert order.is_complete(), "Finalization done" summary = order.get_tax_summary() assert len(summary) == 2 assert summary[0].tax_rate * 100 == 50 assert summary[0].based_on == Money(100, currency) assert summary[0].tax_amount == Money(50, currency) assert summary[0].taxful == summary[0].based_on + summary[0].tax_amount assert summary[1].tax_id is None assert summary[1].tax_code == '' assert summary[1].tax_amount == Money(0, currency) assert summary[1].tax_rate == 0 assert order.get_total_tax_amount() == Money(50, currency)
def test_mixed_chart(): labels = ["One", "Two", "Three"] locale = "pt_br" currency = "BRL" chart = MixedChart("ma biultiful xart", labels, data_type=ChartDataType.CURRENCY, locale=locale, currency=currency) dataset1 = OrderedDict({"type": ChartType.BAR, "label": "some bars #1", "data": [1, 2, 3]}) dataset2 = OrderedDict({"type": ChartType.BAR, "label": "some bars #2", "data": [2, 3, 4]}) dataset3 = OrderedDict({"type": ChartType.LINE, "label": "some lines #1", "data": [5, 6, 7]}) dataset4 = OrderedDict({"type": ChartType.LINE, "label": "some lines #2", "data": [8, 9, 10]}) datasets = [dataset1, dataset2, dataset3, dataset4] for dataset in datasets: chart.add_data(dataset["label"], dataset["data"], dataset["type"]) chart_config = chart.get_config() assert chart_config["type"] == "mixed" assert chart_config["labels"] == labels for i in range(len(chart_config["data"])): for j in range(len(chart_config["data"][i]["data"])): assert chart_config["data"][i]["data"][j] == datasets[i]["data"][j] formatted_data = chart_config["data"][i]["formatted_data"][j] assert formatted_data == format_money(Money(datasets[i]["data"][j], currency=currency).as_rounded())
def test_product_purchasable_media(): shop = get_default_shop() supplier = get_simple_supplier() product = create_product( "test-sku", shop=get_default_shop(), default_price=10, ) medias = add_product_image(product, True) supplier.adjust_stock(product.id, 5) # Order with 2 unshipped, non-refunded items and a shipping cost order = create_order_with_product(product, supplier, 2, 200, shop=shop) order.create_shipment_of_all_products(supplier=supplier) order.shipping_status = ShippingStatus.FULLY_SHIPPED order.create_payment(order.taxful_total_price) currency = order.currency assert order.payments.exists(), "A payment was created" with pytest.raises(NoPaymentToCreateException): order.create_payment(Money(6, currency)) order.save() assert order.is_paid() assert order.get_purchased_attachments().count() == len(medias)
def test_create_refund_amount(prices_include_tax): supplier = get_simple_supplier() order = _get_order(prices_include_tax, True, True) original_order_total = order.taxful_total_price num_order_lines = order.lines.count() # refund the discount lines first for line in order.lines.discounts(): order.create_refund([ {"line": "amount", "quantity": line.quantity, "amount": line.taxful_price.amount}]) # refund each line 1 by 1 for line in order.lines.products(): order.create_refund([ {"line": "amount", "quantity": 1, "amount": line.taxful_price.amount, "restock_products": True}]) assert order.has_refunds() #assert not order.can_create_refund() assert not order.taxful_total_price_value assert not order.taxless_total_price_value assert order.lines.refunds().count() == num_order_lines # we haven't refunded any quantity so the shipping status remains as-is assert order.shipping_status == ShippingStatus.NOT_SHIPPED assert order.payment_status == PaymentStatus.FULLY_PAID assert order.get_total_refunded_amount() == original_order_total.amount assert not order.get_total_unrefunded_amount().value for line in order.lines.products(): order.create_refund([ {"line": line, "quantity": line.quantity, "amount": Money(0, "EUR"), "restock_products": True}]) assert order.shipping_status == ShippingStatus.FULLY_SHIPPED
def amount(self): """ Money amount of this price. :rtype: Money """ return Money(self.value, self.currency)
def test_module(address, expected_taxes): """ Test the DefaultTaxModule. """ # Create a product shop = get_shop(prices_include_tax=False, currency='USD') product = create_product('PROD', shop=shop, default_price=1000) price = product.get_shop_instance(shop).default_price # Put the tax rules into database for ruledef in shuffled(TAX_RULE_DEFS): rule = ruledef.get_tax_rule() rule.tax.save() rule.tax = rule.tax # refresh the id rule.save() rule.tax_classes.add(product.tax_class) assert TaxRule.objects.count() == len(TAX_RULE_DEFS) with override_settings(E-Commerce_TAX_MODULE='default_tax'): module = get_tax_module() assert isinstance(module, DefaultTaxModule) context = TaxingContext(location=address) taxed_price = module.get_taxed_price_for(context, product, price) expected_codes = set(sum([x.split() for x in expected_taxes], [])) assert set(x.tax.code for x in taxed_price.taxes) == expected_codes expected_tax = Money(TAX_AMOUNTS[expected_taxes], 'USD') assert taxed_price.taxful.amount == price.amount + expected_tax # Clean-up the rules TaxRule.objects.all().delete()
def test_init_with_currency(): m42eur = TaxlessPrice(42, 'EUR') assert m42eur.amount == Money(42, 'EUR') assert m42eur.value == 42 assert m42eur.currency == 'EUR' assert TaxlessPrice(1, 'USD').currency == 'USD'
def test_set_course(self): money = Money.Money(10, 10) self.assertEqual(money.course, 1) money.set_course(80) self.assertEqual(money.course, 80) money.set_course(0) self.assertEqual(money.course, 80)
def _get_refund_line_info(self, order, data, supplier): refund_line_info = {} amount_value = data.get("amount", 0) or 0 line_number = data.get("line_number") quantity = data.get("quantity", 0) or 1 restock_products = data.get("restock_products") if line_number != "amount": lines = order.lines.filter(ordering=line_number) if supplier: lines = lines.filter(supplier=supplier) line = lines.first() if not line: return None refund_line_info["line"] = line refund_line_info["quantity"] = quantity refund_line_info["restock_products"] = bool(restock_products) else: refund_line_info["line"] = "amount" refund_line_info["text"] = data.get("text") refund_line_info["quantity"] = 1 refund_line_info["amount"] = Money(amount_value, order.currency) return refund_line_info
def test_tax_special_cases3(): taxless_line = Line( base_unit_price=TaxfulPrice(0, 'EUR'), quantity=0, discount_amount=TaxfulPrice(0, 'EUR'), tax_amount=Money(0, 'EUR') ) assert taxless_line.taxful_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_price == TaxlessPrice(0, 'EUR') assert taxless_line.base_unit_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxful_base_unit_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_base_unit_price == TaxlessPrice(0, 'EUR') assert taxless_line.discount_amount == TaxfulPrice(0, 'EUR') assert taxless_line.taxful_discount_amount == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_discount_amount == TaxlessPrice(0, 'EUR') assert taxless_line.price == TaxfulPrice(0, 'EUR') assert taxless_line.taxful_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_price == TaxlessPrice(0, 'EUR') assert taxless_line.base_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxful_base_price == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_base_price == TaxlessPrice(0, 'EUR') assert taxless_line.unit_discount_amount == TaxfulPrice(0, 'EUR') assert taxless_line.taxful_unit_discount_amount == TaxfulPrice(0, 'EUR') assert taxless_line.taxless_unit_discount_amount == TaxlessPrice(0, 'EUR') assert taxless_line.discount_rate == 0 assert taxless_line.tax_rate == 0
def from_line_taxes(cls, line_taxes, untaxed): """ Create TaxSummary from LineTaxes. :param line_taxes: List of line taxes to summarize :type line_taxes: list[LineTax] :param untaxed: Sum of taxless prices that have no taxes added :type untaxed: E-Commerce.core.pricing.TaxlessPrice """ zero_amount = Money(0, untaxed.currency) tax_amount_by_tax = defaultdict(lambda: zero_amount) raw_base_amount_by_tax = defaultdict(lambda: zero_amount) base_amount_by_tax = defaultdict(lambda: zero_amount) for line_tax in line_taxes: assert isinstance(line_tax, LineTax) tax_amount_by_tax[line_tax.tax] += line_tax.amount raw_base_amount_by_tax[line_tax.tax] += line_tax.base_amount base_amount_by_tax[line_tax.tax] += line_tax.base_amount.as_rounded() lines = [ TaxSummaryLine.from_tax(tax, base_amount_by_tax[tax], raw_base_amount_by_tax[tax], tax_amount) for (tax, tax_amount) in tax_amount_by_tax.items() ] if untaxed: lines.append( TaxSummaryLine( tax_id=None, tax_code='', tax_name=_("Untaxed"), tax_rate=Decimal(0), based_on=untaxed.amount.as_rounded(), raw_based_on=untaxed.amount, tax_amount=zero_amount)) return cls(sorted(lines, key=TaxSummaryLine.get_sort_key))
def max_refundable_amount(self): """ :rtype: E-Commerce.utils.money.Money """ refunds = self.child_lines.refunds().filter(parent_line=self) refund_total_value = sum(refund.taxful_price.amount.value for refund in refunds) return (self.taxful_price.amount + Money(refund_total_value, self.order.currency))
def add_data(self, name, data, chart_type): """ Add data to this chart :param name: the name of the dataset :type name: str :param data: the list of data :type data: list[int|float|Decimal] :param chart_type: the chart type - tells how data should be rendered. This data type must be available in the `supported_chart_type` attribute of this instance :type chart_type: ChartType """ assert chart_type in self.supported_chart_types formatted_data = [] # format value for each data point if self.data_type == ChartDataType.CURRENCY: for value in data: formatted_data.append(format_money(Money(value, currency=self.currency).as_rounded())) elif self.data_type == ChartDataType.PERCENT: for value in data: formatted_data.append(format_percent(value, locale=self.locale)) # self.data_type == ChartDataType.NUMBER else: for value in data: formatted_data.append(format_decimal(value, locale=self.locale)) self.datasets.append({"type": chart_type, "label": name, "data": data, "formatted_data": formatted_data})
def test_get_currency(self): money = Money.Money(10, 10) money.set_course(2) self.assertEqual("5.05", money.get_currency()) money.set_course(10) self.assertEqual("1.01", money.get_currency()) money.set_course(8) self.assertEqual("1.2625", money.get_currency())
def test_money_formatter_fi(): with translation.override("fi-FI"): assert money(Money("29.99", "USD")) == nbsp("29,99 $") assert money(Money("29.99", "EUR")) == nbsp("29,99 €") assert money(Money("29.99", "GBP")) == nbsp("29,99 £") assert money(Money("29.99", "CAD")) == nbsp("29,99 CAD") assert money(Money("29.99", "JPY")) == nbsp("30 ¥") # No such thing as a decimal yen! assert money(Money("29.99", "CNY")) == nbsp("29,99 CNY") assert money(Money("29.99", "KRW")) == nbsp("30 KRW") # the 1/100 subunit "jeon" is theoretical and not in use assert money(Money("29.99", "SEK")) == nbsp("29,99 SEK")
def test_money_formatter_en(): with translation.override("en-US"): assert money(Money("29.99", "USD")) == "$29.99" assert money(Money("29.99", "EUR")) == "€29.99" assert money(Money("29.99", "GBP")) == "£29.99" assert money(Money("29.99", "CAD")) == "CA$29.99" assert money(Money("29.99", "JPY")) == "¥30" # No such thing as a decimal yen! assert money(Money("29.99", "CNY")) == "CN¥29.99" assert money(Money("29.99", "KRW")) == "₩30" # the 1/100 subunit "jeon" is theoretical and not in use assert money(Money("29.99", "SEK")) == "kr29.99"
def parse_transaction_rc(file_name): print(f'parsing file "{file_name}"') budget = Budget.BudgetCategory() for i, line in enumerate(open(file_name).readlines()): key, value = line.split(':', 1) key = key.strip() if key[0:2] == '>>': # new budget -- handle previous handle_budget(budget) budget = Budget.BudgetCategory(value) else: description = value.strip() money = Money.Money(key) transaction = Money.Transaction(money, description) # TODO: add description & date budget.add_transaction(transaction) # handle last budget handle_budget(budget)
def test_refunds_rounding_multiple_partial_refund(): shop = get_default_shop() supplier = get_default_supplier() product = create_product( "test-sku", shop=get_default_shop(), default_price=29.264, ) order = create_order_with_product(product, supplier, 2, 29.264, shop=shop) order.cache_prices() assert len(order.lines.all()) == 1 line = order.lines.first() order.create_refund([{"line": line, "quantity": 1, "amount": Money("29.26", order.currency)}]) assert order.taxful_total_price == order.shop.create_price("29.27") order.create_refund([{"line": line, "quantity": 1, "amount": Money("29.27", order.currency)}]) assert line.max_refundable_amount == Money("0", order.currency) assert order.taxful_total_price == order.shop.create_price(0)
def test_can_create_payment(): shop = get_default_shop() supplier = get_default_supplier() product = create_product( "test-sku", shop=get_default_shop(), default_price=10, ) order = create_order_with_product(product, supplier, 1, 200, shop=shop) assert order.can_create_payment() order.cache_prices() # Partially paid orders can create payments payment_amount = (order.taxful_total_price.amount / 2) order.create_payment(payment_amount) assert order.can_create_payment() # But fully paid orders can't remaining_amount = order.taxful_total_price.amount - payment_amount order.create_payment(remaining_amount) assert not order.can_create_payment() order = create_order_with_product(product, supplier, 1, 200, shop=shop) order.cache_prices() assert order.can_create_payment() # Canceled orders can't create payments order.set_canceled() assert not order.can_create_payment() order = create_order_with_product(product, supplier, 2, 200, shop=shop) order.cache_prices() assert order.can_create_payment() # Partially refunded orders can create payments order.create_refund([ {"line": order.lines.first(), "quantity": 1, "amount": Money(200, order.currency), "restock": False}]) assert order.can_create_payment() # But fully refunded orders can't order.create_refund([ {"line": order.lines.first(), "quantity": 1, "amount": Money(200, order.currency), "restock": False}]) assert not order.can_create_payment()
def create_tax_from_string(string): if ' ' in string: (spec, name) = string.split(' ', 1) else: name = spec = string if spec.startswith('$'): return create_tax(name, amount=Money(spec[1:], 'USD')) elif spec.endswith('%'): return create_tax(name, rate=(Decimal(spec[:-1]) / 100)) raise ValueError('Unknown tax string: %r' % (string,))
def test_units_match(): class XxxMoney(int): currency = 'XXX' m1 = Money(1, 'EUR') m2 = Money(2, 'EUR') m3 = Money(3, 'XXX') m4 = XxxMoney(4) assert m1.unit_matches_with(m2) assert not m1.unit_matches_with(m3) assert m3.unit_matches_with(m4)
def get_data(self): data = [] tax_map = {} for tax_total in self.get_objects(): # load tax on-demand if not tax_total["tax"] in tax_map: tax_map[tax_total["tax"]] = Tax.objects.get(pk=tax_total["tax"]) data.append({ "tax": tax_map[tax_total["tax"]].name, "tax_rate": tax_total["tax__rate"] * Decimal(100.0), "order_count": tax_total["order_count"], "total_pretax_amount": Money(tax_total["total_pretax_amount"], self.shop.currency).as_rounded().value, "total_tax_amount": Money(tax_total["total_tax_amount"], self.shop.currency).as_rounded().value, "total": Money(tax_total["total"], self.shop.currency).as_rounded().value }) return self.get_return_data(data)
class TestMoney(unittest.TestCase): def setUp(self): self.money = Money() def testEquality(self): self.assertTrue(self.money.dollar(9).__eq__(self.money.dollar(9))) self.assertFalse(self.money.dollar(8).__eq__(self.money.dollar(9))) self.assertFalse(self.money.dollar(5).__eq__(self.money.franc(5))) self.assertTrue(self.money.franc(9).__eq__(self.money.franc(9))) self.assertFalse(self.money.franc(8).__eq__(self.money.franc(9))) def testGetCurrency(self): self.assertEqual('USD', self.money.dollar(1).getCurrency()) self.assertEqual('CHF', self.money.franc(1).getCurrency()) def testMulplification(self): dollar = self.money.dollar(5) self.assertEqual(self.money.dollar(10), dollar.times(2)) self.assertEqual(self.money.dollar(15), dollar.times(3)) f = self.money.franc(5) self.assertEqual(self.money.franc(10), f.times(2)) self.assertEqual(self.money.franc(15), f.times(3)) def testMoneyAdd(self): bank = Bank() bank.addRate('CHF', 'USD', 2) d5 = self.money.dollar(5) d6 = self.money.dollar(6) f1 = self.money.franc(1) e = d5 + f1 self.assertEqual(e.__class__, Expression([self.money.dollar(1)]).__class__) e = d5 + d6 self.assertEqual(e.__class__, Expression([self.money.dollar(1)]).__class__) d11 = bank.exchange(e, 'USD') self.assertEqual(self.money.dollar(11), d11) f22 = bank.exchange(e, 'CHF') self.assertEqual(self.money.franc(22), f22) def testExpressoinMulplification(self): e = Expression([self.money.dollar(5)]) e.times(2) self.assertEqual(e, Expression([self.money.dollar(10)])) e.times(3) self.assertEqual(e, Expression([self.money.dollar(30)])) d5=self.money.dollar(5) f6 = self.money.franc(6) e2 = d5 + f6 e2.times(2) self.assertEqual(e2, self.money.dollar(10) + self.money.franc(12)) e2 = self.money.dollar(5) + self.money.franc(6) e2.times(3) self.assertEqual(e2, self.money.dollar(15) + self.money.franc(18)) def testFailure(self): self.assertRaises(NeedListError, Expression, self.money.dollar(1))
def setUp(self): self.money = Money()