def test_supplier_total_order_sum_with_one_order(self): round = OrderRoundFactory() supplier1 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=round) supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order) self.assertItemsEqual(round.suppliers(), [supplier1]) self.assertEqual(round.supplier_total_order_sum(supplier1), supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount)
def test_suppliers_with_paid_and_unpaid_orders(self): round = OrderRoundFactory() supplier1 = SupplierFactory() supplier2 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=round) finalized_order = OrderFactory(paid=False, finalized=True, order_round=round) supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order) supplier2_orderproduct = OrderProductFactory(product__supplier=supplier2, order=finalized_order) self.assertItemsEqual(round.suppliers(), [supplier1])
def test_suppliers_with_paid_and_unpaid_orders(self): order_round = OrderRoundFactory() supplier1 = SupplierFactory() supplier2 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=order_round) finalized_order = OrderFactory(paid=False, finalized=True, order_round=order_round) OrderProductFactory(product__supplier=supplier1, order=paid_order) OrderProductFactory(product__supplier=supplier2, order=finalized_order) self.assertCountEqual(order_round.suppliers(), [supplier1])
def test_supplier_total_order_sum_with_one_order(self): order_round = OrderRoundFactory() supplier1 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=order_round) supplier1_orderproduct = OrderProductFactory( product__supplier=supplier1, order=paid_order) self.assertCountEqual(order_round.suppliers(), [supplier1]) self.assertEqual( order_round.supplier_total_order_sum(supplier1), supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount)
class TestOrderRoundModel(VokoTestCase): def setUp(self): now = datetime.now(tz=UTC) self.prev_order_round = OrderRoundFactory( open_for_orders=now - timedelta(days=8), closed_for_orders=now - timedelta(days=4)) self.cur_order_round = OrderRoundFactory( open_for_orders=now - timedelta(days=1), closed_for_orders=now + timedelta(days=3)) self.next_order_round = OrderRoundFactory( open_for_orders=now + timedelta(days=6), closed_for_orders=now + timedelta(days=9)) def test_is_not_open_yet(self): self.assertFalse(self.prev_order_round.is_not_open_yet()) self.assertFalse(self.cur_order_round.is_not_open_yet()) self.assertTrue(self.next_order_round.is_not_open_yet()) def test_is_over(self): self.assertTrue(self.prev_order_round.is_over) self.assertFalse(self.cur_order_round.is_over) self.assertFalse(self.next_order_round.is_over) def test_is_open_property(self): self.assertFalse(self.prev_order_round.is_open) self.assertTrue(self.cur_order_round.is_open) self.assertFalse(self.next_order_round.is_open) @skip("This test also fails because some weird " "stuff with get_current_order_round") def test_is_current(self): self.assertFalse(self.prev_order_round.is_current()) self.assertTrue(self.cur_order_round.is_current()) self.assertFalse(self.next_order_round.is_current()) def test_suppliers_with_no_orders(self): self.assertEqual(self.cur_order_round.suppliers(), []) def test_suppliers_with_paid_and_unpaid_orders(self): order_round = OrderRoundFactory() supplier1 = SupplierFactory() supplier2 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=order_round) finalized_order = OrderFactory(paid=False, finalized=True, order_round=order_round) OrderProductFactory(product__supplier=supplier1, order=paid_order) OrderProductFactory(product__supplier=supplier2, order=finalized_order) self.assertCountEqual(order_round.suppliers(), [supplier1]) def test_supplier_total_order_sum_with_one_order(self): order_round = OrderRoundFactory() supplier1 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=order_round) supplier1_orderproduct = OrderProductFactory( product__supplier=supplier1, order=paid_order) self.assertCountEqual(order_round.suppliers(), [supplier1]) self.assertEqual( order_round.supplier_total_order_sum(supplier1), supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount) def test_supplier_total_order_sum_with_multiple_orders(self): order_round = OrderRoundFactory() supplier1 = SupplierFactory() supplier1_orderproduct1 = OrderProductFactory( product__supplier=supplier1, order__order_round=order_round, order__paid=True, order__finalized=True) supplier1_orderproduct2 = OrderProductFactory( product__supplier=supplier1, order__order_round=order_round, order__paid=True, order__finalized=True) expected_sum = ((supplier1_orderproduct1.product.base_price * supplier1_orderproduct1.amount) + (supplier1_orderproduct2.product.base_price * supplier1_orderproduct2.amount)) self.assertEqual(order_round.supplier_total_order_sum(supplier1), expected_sum) def test_total_order_sum(self): order_round = OrderRoundFactory() orderproduct1 = OrderProductFactory(order__order_round=order_round, order__paid=True, order__finalized=True) orderproduct2 = OrderProductFactory(order__order_round=order_round, order__paid=True, order__finalized=True) # Not paid OrderProductFactory(order__order_round=order_round, order__paid=False, order__finalized=False) expected_sum = ( (orderproduct1.product.base_price * orderproduct1.amount) + (orderproduct2.product.base_price * orderproduct2.amount)) self.assertEqual(order_round.total_order_sum(), expected_sum) def test_total_corrections_with_no_corrections(self): order_round = OrderRoundFactory() self.assertEqual(order_round.total_corrections(), { 'supplier_inc': 0, 'voko_inc': 0, 'supplier_exc': 0 }) def test_total_corrections(self): order_round = OrderRoundFactory() corr1 = OrderProductCorrectionFactory( order_product__order__order_round=order_round, charge_supplier=True) corr2 = OrderProductCorrectionFactory( order_product__order__order_round=order_round, charge_supplier=False) self.assertEqual( order_round.total_corrections(), { 'supplier_inc': corr1.calculate_refund(), 'voko_inc': corr2.calculate_refund(), 'supplier_exc': corr1.calculate_supplier_refund() }) def test_total_profit_without_corrections(self): order_round = OrderRoundFactory() orderprod1 = OrderProductFactory(order__order_round=order_round, order__paid=True) self.assertEqual(order_round.total_profit(), orderprod1.product.profit * orderprod1.amount) @skip("TODO: Think out logic") def test_total_profit_with_corrections(self): order_round = OrderRoundFactory() OrderProductFactory(order__order_round=order_round, order__paid=True) OrderProductCorrectionFactory( order_product__order__order_round=order_round, order_product__order__paid=True) # TODO: How do we handle (partly) lost profit of corrections? def test_number_of_orders_with_no_orders(self): order_round = OrderRoundFactory() self.assertEqual(order_round.number_of_orders(), 0) def test_number_of_orders_with_paid_and_unpaid_orders(self): order_round = OrderRoundFactory() # 3 paid OrderFactory(order_round=order_round, paid=True) OrderFactory(order_round=order_round, paid=True) OrderFactory(order_round=order_round, paid=True) # 2 unpaid OrderFactory(order_round=order_round, paid=False) OrderFactory(order_round=order_round, paid=False, finalized=True) self.assertEqual(order_round.number_of_orders(), 3)
class TestOrderRoundModel(VokoTestCase): def setUp(self): now = datetime.now(tz=UTC) self.prev_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=8), closed_for_orders=now - timedelta(days=4)) self.cur_order_round = OrderRoundFactory(open_for_orders=now - timedelta(days=1), closed_for_orders=now + timedelta(days=3)) self.next_order_round = OrderRoundFactory(open_for_orders=now + timedelta(days=6), closed_for_orders=now + timedelta(days=9)) def test_is_not_open_yet(self): self.assertFalse(self.prev_order_round.is_not_open_yet()) self.assertFalse(self.cur_order_round.is_not_open_yet()) self.assertTrue(self.next_order_round.is_not_open_yet()) def test_is_over(self): self.assertTrue(self.prev_order_round.is_over()) self.assertFalse(self.cur_order_round.is_over()) self.assertFalse(self.next_order_round.is_over()) def test_is_open_property(self): self.assertFalse(self.prev_order_round.is_open) self.assertTrue(self.cur_order_round.is_open) self.assertFalse(self.next_order_round.is_open) @skip("This test also fails because some weird stuff with get_current_order_round") def test_is_current(self): self.assertFalse(self.prev_order_round.is_current()) self.assertTrue(self.cur_order_round.is_current()) self.assertFalse(self.next_order_round.is_current()) def test_suppliers_with_no_orders(self): self.assertEqual(self.cur_order_round.suppliers(), []) def test_suppliers_with_paid_and_unpaid_orders(self): round = OrderRoundFactory() supplier1 = SupplierFactory() supplier2 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=round) finalized_order = OrderFactory(paid=False, finalized=True, order_round=round) supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order) supplier2_orderproduct = OrderProductFactory(product__supplier=supplier2, order=finalized_order) self.assertItemsEqual(round.suppliers(), [supplier1]) def test_supplier_total_order_sum_with_one_order(self): round = OrderRoundFactory() supplier1 = SupplierFactory() paid_order = OrderFactory(paid=True, finalized=True, order_round=round) supplier1_orderproduct = OrderProductFactory(product__supplier=supplier1, order=paid_order) self.assertItemsEqual(round.suppliers(), [supplier1]) self.assertEqual(round.supplier_total_order_sum(supplier1), supplier1_orderproduct.product.base_price * supplier1_orderproduct.amount) def test_supplier_total_order_sum_with_multiple_orders(self): round = OrderRoundFactory() supplier1 = SupplierFactory() supplier1_orderproduct1 = OrderProductFactory(product__supplier=supplier1, order__order_round=round, order__paid=True, order__finalized=True) supplier1_orderproduct2 = OrderProductFactory(product__supplier=supplier1, order__order_round=round, order__paid=True, order__finalized=True) self.assertEqual(round.supplier_total_order_sum(supplier1), (supplier1_orderproduct1.product.base_price * supplier1_orderproduct1.amount) + (supplier1_orderproduct2.product.base_price * supplier1_orderproduct2.amount)) def test_total_order_sum(self): round = OrderRoundFactory() orderproduct1 = OrderProductFactory(order__order_round=round, order__paid=True, order__finalized=True) orderproduct2 = OrderProductFactory(order__order_round=round, order__paid=True, order__finalized=True) orderproduct3 = OrderProductFactory(order__order_round=round, order__paid=False, order__finalized=False) self.assertEqual(round.total_order_sum(), (orderproduct1.product.base_price * orderproduct1.amount) + (orderproduct2.product.base_price * orderproduct2.amount)) def test_total_corrections_with_no_corrections(self): round = OrderRoundFactory() self.assertEqual(round.total_corrections(), {'supplier_inc': 0, 'voko_inc': 0, 'supplier_exc': 0}) def test_total_corrections(self): round = OrderRoundFactory() corr1 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=True) corr2 = OrderProductCorrectionFactory(order_product__order__order_round=round, charge_supplier=False) self.assertEqual(round.total_corrections(), {'supplier_inc': corr1.calculate_refund(), 'voko_inc': corr2.calculate_refund(), 'supplier_exc': corr1.calculate_supplier_refund()}) def test_total_profit_without_corrections(self): round = OrderRoundFactory() orderprod1 = OrderProductFactory(order__order_round=round, order__paid=True) self.assertEqual(round.total_profit(), orderprod1.product.profit * orderprod1.amount) @skip("TODO: Think out logic") def test_total_profit_with_corrections(self): round = OrderRoundFactory() orderprod1 = OrderProductFactory(order__order_round=round, order__paid=True) ordercorr1 = OrderProductCorrectionFactory(order_product__order__order_round=round, order_product__order__paid=True) # TODO: How do we handle (partly) lost profit of corrections? def test_number_of_orders_with_no_orders(self): round = OrderRoundFactory() self.assertEqual(round.number_of_orders(), 0) def test_number_of_orders_with_paid_and_unpaid_orders(self): round = OrderRoundFactory() paid1 = OrderFactory(order_round=round, paid=True) paid2 = OrderFactory(order_round=round, paid=True) paid3 = OrderFactory(order_round=round, paid=True) unpaid1 = OrderFactory(order_round=round, paid=False) unpaid2 = OrderFactory(order_round=round, paid=False, finalized=True) self.assertEqual(round.number_of_orders(), 3)