Ejemplo n.º 1
0
    def test_product_current_price_with_history(self):
        now = datetime.datetime.now()
        p = ProductFactory.build(
            price=PriceValueFactory.build(price=100.00, date=now))

        yesterday = now - datetime.timedelta(days=1)
        p.set_price(PriceValueFactory.build(price=150.00, date=yesterday))

        last_week = now - datetime.timedelta(weeks=1)
        p.set_price(PriceValueFactory.build(price=130.00, date=last_week))

        self.assertEquals(100.00, p.get_price(), "Current price incorrect")
        self.assertEquals(150.00, p.get_price(date=yesterday),
                          "Yesterday price incorrect")
        self.assertEquals(150.00,
                          p.get_price(date=now - datetime.timedelta(hours=1)),
                          "Price an hour ago incorrect")
        self.assertEquals(130.00,
                          p.get_price(date=now - datetime.timedelta(days=3)),
                          "Price 3 days ago incorrect")

        # Update price again, delta should be small
        p.set_price(
            PriceValueFactory.build(price=90.00, date=datetime.datetime.now()))
        self.assertEquals(90.00, p.get_price(),
                          "Updated current price incorrect")

        self.assertIsNone(p.get_price(date=now - datetime.timedelta(weeks=2)),
                          "Price 2 weeks ago no undefined")
Ejemplo n.º 2
0
    def setUp(self):
        self.discount_repository = Mock()
        self.discount_repository.find = Mock()
        discounts = {
            ("MANF-A", "GRADE-A"): Discount(0.3, "MANF-A", "GRADE-A"),
            ("MANF-B", "GRADE-A"): Discount(0.1, "MANF-B", "GRADE-A")
        }
        self.discount_repository.find = Mock(side_effect=lambda category, tier: discounts.get((category, tier)))
        self.pricing_service = PricingService(self.discount_repository)

        customers = {
            "Customer": CustomerFactory.build(name="Customer"),
        }
        self.customer_repository = Mock()
        self.customer_repository.find = Mock(side_effect=lambda sku: customers.get(sku))

        tax_rate = Mock()
        tax_rate.rate = 0.1
        self.tax_repository = Mock()
        self.tax_repository.find = Mock(return_value=tax_rate)

        prod1 = ProductFactory.build(sku="PROD001", price_category="MANF-A")
        prod1.set_price(PriceValueFactory.build(price=100.00))
        prod2 = ProductFactory.build(sku="PROD002", price_category="MANF-B")
        prod2.set_price(PriceValueFactory.build(price=20.00))
        self.products = {
            "PROD001": prod1,
            "PROD002": prod2,
        }
        self.product_repository = Mock()
        self.product_repository.find = Mock(side_effect=lambda sku: self.products.get(sku))

        inv_prod1 = InventoryItemFactory.build(sku="PROD001")
        inv_prod1.enter_stock_on_hand(10)

        inv_prod2 = InventoryItemFactory.build(sku="PROD002", on_hand_buffer=7)
        inv_prod2.enter_stock_on_hand(10)

        self.inventory = {
            "PROD001": inv_prod1,
            "PROD002": inv_prod2,
        }
        self.inventory_repository = Mock()
        self.inventory_repository.find = Mock(side_effect=lambda sku: self.inventory.get(sku))

        self.order_descriptors = {
            "ORD001": [
                ("PROD001", 1),
                ("PROD002", 3),
            ],
            "ORD002": [
                ("PROD001", 2),
                ("PROD002", 4),
            ]

        }

        self.order_repository = Mock()
        order_ids = ["ORD002", "ORD001"]
        self.order_repository.next_id = Mock(side_effect=lambda: order_ids.pop())
Ejemplo n.º 3
0
    def test_product_current_price_with_history(self):
        now = datetime.datetime.now()
        p = ProductFactory.build(price=PriceValueFactory.build(price=100.00, date=now))

        yesterday = now - datetime.timedelta(days=1)
        p.set_price(PriceValueFactory.build(price=150.00, date=yesterday))

        last_week = now - datetime.timedelta(weeks=1)
        p.set_price(PriceValueFactory.build(price=130.00, date=last_week))

        self.assertEquals(100.00, p.get_price(), "Current price incorrect")
        self.assertEquals(150.00, p.get_price(date=yesterday), "Yesterday price incorrect")
        self.assertEquals(150.00, p.get_price(date=now - datetime.timedelta(hours=1)), "Price an hour ago incorrect")
        self.assertEquals(130.00, p.get_price(date=now - datetime.timedelta(days=3)), "Price 3 days ago incorrect")

        # Update price again, delta should be small
        p.set_price(PriceValueFactory.build(price=90.00, date=datetime.datetime.now()))
        self.assertEquals(90.00, p.get_price(), "Updated current price incorrect")

        self.assertIsNone(p.get_price(date=now - datetime.timedelta(weeks=2)), "Price 2 weeks ago no undefined")
Ejemplo n.º 4
0
    def test_product_current_price(self):
        p = ProductFactory.build(price=PriceValueFactory.build(price=100.00))

        self.assertEquals(100.00, p.get_price(), "Current price incorrect")
Ejemplo n.º 5
0
    def setUp(self):
        self.discount_repository = Mock()
        self.discount_repository.find = Mock()
        discounts = {
            ("MANF-A", "GRADE-A"): Discount(0.3, "MANF-A", "GRADE-A"),
            ("MANF-B", "GRADE-A"): Discount(0.1, "MANF-B", "GRADE-A")
        }
        self.discount_repository.find = Mock(
            side_effect=lambda category, tier: discounts.get((category, tier)))
        self.pricing_service = PricingService(self.discount_repository)

        customers = {
            "Customer": CustomerFactory.build(name="Customer"),
        }
        self.customer_repository = Mock()
        self.customer_repository.find = Mock(
            side_effect=lambda sku: customers.get(sku))

        tax_rate = Mock()
        tax_rate.rate = 0.1
        self.tax_repository = Mock()
        self.tax_repository.find = Mock(return_value=tax_rate)

        prod1 = ProductFactory.build(sku="PROD001", price_category="MANF-A")
        prod1.set_price(PriceValueFactory.build(price=100.00))
        prod2 = ProductFactory.build(sku="PROD002", price_category="MANF-B")
        prod2.set_price(PriceValueFactory.build(price=20.00))
        self.products = {
            "PROD001": prod1,
            "PROD002": prod2,
        }
        self.product_repository = Mock()
        self.product_repository.find = Mock(
            side_effect=lambda sku: self.products.get(sku))

        inv_prod1 = InventoryItemFactory.build(sku="PROD001")
        inv_prod1.enter_stock_on_hand(10)

        inv_prod2 = InventoryItemFactory.build(sku="PROD002", on_hand_buffer=7)
        inv_prod2.enter_stock_on_hand(10)

        self.inventory = {
            "PROD001": inv_prod1,
            "PROD002": inv_prod2,
        }
        self.inventory_repository = Mock()
        self.inventory_repository.find = Mock(
            side_effect=lambda sku: self.inventory.get(sku))

        self.order_descriptors = {
            "ORD001": [
                ("PROD001", 1),
                ("PROD002", 3),
            ],
            "ORD002": [
                ("PROD001", 2),
                ("PROD002", 4),
            ]
        }

        self.order_repository = Mock()
        order_ids = ["ORD002", "ORD001"]
        self.order_repository.next_id = Mock(
            side_effect=lambda: order_ids.pop())
Ejemplo n.º 6
0
    def test_product_current_price(self):
        p = ProductFactory.build(price=PriceValueFactory.build(price=100.00))

        self.assertEquals(100.00, p.get_price(), "Current price incorrect")