def test_in_alternative_currency(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() order = TestOrderFactory(currency=alternative_currency) refund = OrderRefundFactory(order=order, exchange_rate=Decimal("1.5555")) self.assertEqual(refund.amount_in_primary_currency(), Decimal("11.25"))
def test_set_exchange_rate__alternative_currency(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() ExchangeRate.objects.create(currency=alternative_currency, rate="0.1234") order = TestOrderFactory(currency=alternative_currency) refund = OrderRefundFactory(order=order) self.assertEqual(refund.exchange_rate, Decimal("0.1234"))
def test_in_alternative_currency__less(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() order = TestOrderFactory(currency=alternative_currency, exchange_rate=Decimal("0.937658")) self.assertEqual( order.total_in_primary_currency().quantize(Decimal(".01")), Decimal("37.33"))
def test_in_alternative_currency__less(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() order = TestOrderFactory( currency=alternative_currency, exchange_rate=Decimal("0.937658") ) self.assertEqual( order.total_in_primary_currency().quantize(Decimal(".01")), Decimal("37.33") )
def test_multiple_refunds_different_exhange_rates(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() order = TestOrderFactory(currency=alternative_currency) OrderRefund.objects.create(order=order, amount=Decimal("1.00"), exchange_rate=Decimal("1.5555")) OrderRefund.objects.create(order=order, amount=Decimal("1.00"), exchange_rate=Decimal("0.95")) self.assertEqual(order.refund_in_primary_currency(), Decimal("1.69"))
def test_multiple_refunds_different_exhange_rates(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory() order = TestOrderFactory(currency=alternative_currency) OrderRefund.objects.create( order=order, amount=Decimal("1.00"), exchange_rate=Decimal("1.5555") ) OrderRefund.objects.create( order=order, amount=Decimal("1.00"), exchange_rate=Decimal("0.95") ) self.assertEqual(order.refund_in_primary_currency(), Decimal("1.69"))
class DisplayMethodsTest(TestCase): def setUp(self): self.currency = USDCurrencyFactory() self.currency.primary = True self.currency.accepted = True self.currency.save() self.order = TestOrderFactory(currency=self.currency) def test_total(self): self.assertEqual(self.order.display_total, "$35.00 (USD)") def test_tax(self): self.assertEqual(self.order.display_tax, "$0.00 (USD)") def test_refund(self): self.order.refund = Decimal("5.00") self.assertEqual(self.order.display_refund, "$5.00 (USD)") def test_sub_total(self): self.assertEqual(self.order.display_sub_total, "$25.00 (USD)") def test_sub_total_with_tax(self): self.assertEqual(self.order.display_sub_total_with_tax, "$25.00 (USD)") def test_balance(self): self.assertEqual(self.order.display_balance, "$35.00 (USD)") def test_balance_paid(self): self.assertEqual(self.order.display_balance_paid, "$0.00 (USD)") def test_shipping_sub_total(self): self.assertEqual(self.order.display_shipping_sub_total, "$10.00 (USD)") def test_shipping_with_tax(self): self.assertEqual(self.order.display_shipping_with_tax, "$10.00 (USD)") def test_shipping_cost(self): self.assertEqual(self.order.display_shipping_cost, "$10.00 (USD)") def test_discount(self): self.order.discount = Decimal("5.00") self.assertEqual(self.order.display_discount, "$5.00 (USD)") def test_shipping_discount(self): self.order.shipping_discount = Decimal("5.00") self.assertEqual(self.order.display_shipping_discount, "$5.00 (USD)") def test_item_discount(self): self.order.discount = Decimal("5.00") self.assertEqual(self.order.display_item_discount, "$5.00 (USD)")
def test_in_alternative_currency__less(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory(primary=False) alternative_currency.accepted = True alternative_currency.save() order = TestOrderFactory(currency=alternative_currency) OrderRefund.objects.create(order=order, amount=Decimal("5.00"), exchange_rate=Decimal("0.937658")) self.assertEqual( order.refund_in_primary_currency().quantize(Decimal(".01")), Decimal("5.33"))
def test_in_alternative_currency__less(self): primary_currency = USDCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = EURCurrencyFactory(primary=False) alternative_currency.accepted = True alternative_currency.save() order = TestOrderFactory(currency=alternative_currency) OrderRefund.objects.create( order=order, amount=Decimal("5.00"), exchange_rate=Decimal("0.937658") ) self.assertEqual( order.refund_in_primary_currency().quantize(Decimal(".01")), Decimal("5.33") )
def setUp(self): # Set primary currency + accepted currencies EURCurrencyFactory() USDCurrencyFactory() currency = GBPCurrencyFactory() currency.primary = True currency.save() Currency.objects.update(accepted=True)
def test_creates_order(self): usd = USDCurrencyFactory() usd.accepted = True usd.save() cart = CartFactory() contact = ContactFactory() data = {"shipping": None, "discount": None} request = self.request_factory.get("/") request.session = {"currency_code": "USD"} order = get_or_create_order(request, cart, contact, data) self.assertEqual(Order.objects.all().count(), 1) self.assertEqual(order.contact, contact) self.assertEqual(order.currency.iso_4217_code, "USD") for item in cart.cartitem_set.all(): self.assertIn(item.product, (oi.product for oi in order.orderitem_set.all()))
def setUp(self): self.client = FixerExchangeRateClient() # Set primary currency + accepted currencies EURCurrencyFactory() USDCurrencyFactory() currency = GBPCurrencyFactory() currency.primary = True currency.save() Currency.objects.update(accepted=True)
def test_in_alternative_currency__more(self): primary_currency = EURCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = USDCurrencyFactory() order = TestOrderFactory(currency=alternative_currency, exchange_rate=Decimal("1.06649")) self.assertEqual( order.shipping_cost_in_primary_currency().quantize(Decimal(".01")), Decimal("9.38"), )
def test_in_alternative_currency__more(self): primary_currency = EURCurrencyFactory() primary_currency.primary = True primary_currency.save() alternative_currency = USDCurrencyFactory() order = TestOrderFactory(currency=alternative_currency) OrderRefund.objects.create(order=order, amount=Decimal("5.00"), exchange_rate=Decimal("1.06649")) self.assertEqual( order.refund_in_primary_currency().quantize(Decimal(".01")), Decimal("4.69"))
def setUp(self): self.currency = USDCurrencyFactory() self.currency.primary = True self.currency.accepted = True self.currency.save() self.order = TestOrderFactory(currency=self.currency)
def setUp(self): self.currency = USDCurrencyFactory() self.order = TestOrderFactory(currency=self.currency) self.order_item = OrderItemFactory(order=self.order)
def test_currency_code(self): currency = USDCurrencyFactory() order = TestOrderFactory(currency=currency) order_item = OrderItemFactory(order=order) self.assertEqual(order_item.currency_code, currency.iso_4217_code)
def test_USD(self): currency = USDCurrencyFactory() order = TestOrderFactory(currency=currency) self.assertEqual(order.display_total, "$35.00 (USD)")