Example #1
0
    def test_order_bad_customer(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        with self.assertRaises(OrderingError):
            service.create_order("Fake Customer", None)

        self.assertTrue(call("Fake Customer") in self.customer_repository.find.call_args_list,
                        "Fake Customer was not queried for")
Example #2
0
    def test_order_bad_customer(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        with self.assertRaises(OrderingError):
            service.create_order("Fake Customer", None)

        self.assertTrue(
            call("Fake Customer")
            in self.customer_repository.find.call_args_list,
            "Fake Customer was not queried for")
Example #3
0
    def test_order_cannot_auto_acknowledge(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        # PROD002 has a high on hand buffer, ORD002 should trigger a verification requirement and thus
        # not auto-acknowledge
        order = service.create_order("Customer",
                                     self.order_descriptors["ORD002"])

        self.assertFalse(order.is_acknowledged(),
                         "Order should not have been acknowledged")

        # Rest of the order should be fine however
        for line_item in order.line_items:
            if line_item.sku == "PROD001":
                self.assertEquals(2, line_item.quantity,
                                  "Incorrect Quantity for PROD001")
                self.assertEquals(100.00, line_item.price,
                                  "Incorrect price for PROD001")
                self.assertEquals(0.3, line_item.discount,
                                  "Incorrect discount for PROD001")
            if line_item.sku == "PROD002":
                self.assertEquals(4, line_item.quantity,
                                  "Incorrect Quantity for PROD002")
                self.assertEquals(20.00, line_item.price,
                                  "Incorrect price for PROD002")
                self.assertEquals(0.1, line_item.discount,
                                  "Incorrect discount for PROD002")
            else:
                self.assert_("Unknown item found in order")
Example #4
0
    def test_order_cannot_auto_acknowledge(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        # PROD002 has a high on hand buffer, ORD002 should trigger a verification requirement and thus
        # not auto-acknowledge
        order = service.create_order("Customer", self.order_descriptors["ORD002"])

        self.assertFalse(order.is_acknowledged(), "Order should not have been acknowledged")

        # Rest of the order should be fine however
        for line_item in order.line_items:
            if line_item.sku == "PROD001":
                self.assertEquals(2, line_item.quantity, "Incorrect Quantity for PROD001")
                self.assertEquals(100.00, line_item.price, "Incorrect price for PROD001")
                self.assertEquals(0.3, line_item.discount, "Incorrect discount for PROD001")
            if line_item.sku == "PROD002":
                self.assertEquals(4, line_item.quantity, "Incorrect Quantity for PROD002")
                self.assertEquals(20.00, line_item.price, "Incorrect price for PROD002")
                self.assertEquals(0.1, line_item.discount, "Incorrect discount for PROD002")
            else:
                self.assert_("Unknown item found in order")
Example #5
0
    def test_order_creation(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        order = service.create_order("Customer", self.order_descriptors["ORD001"], customer_reference="Customer-PO-Ref")

        self.assertEquals("Customer-PO-Ref", order.customer_reference, "Customer reference not set correctly")
        self.assertTrue(order.is_acknowledged(), "Order should not have been acknowledged")
        self.assertEquals("ORD001", order.order_id, "Order ID was not set correctly")

        for line_item in order.line_items:
            if line_item.sku == "PROD001":
                self.assertTrue(call("PROD001") in self.product_repository.find.call_args_list,
                                "Product PROD001 was not queried for")
                self.assertEquals(1, line_item.quantity, "Incorrect Quantity for PROD001")
                self.assertEquals(100.00, line_item.price, "Incorrect price for PROD001")
                self.assertEquals(0.3, line_item.discount, "Incorrect discount for PROD001")
            if line_item.sku == "PROD002":
                self.assertTrue(call("PROD002") in self.product_repository.find.call_args_list,
                                "Product PROD002 was not queried for")
                self.assertEquals(3, line_item.quantity, "Incorrect Quantity for PROD002")
                self.assertEquals(20.00, line_item.price, "Incorrect price for PROD002")
                self.assertEquals(0.1, line_item.discount, "Incorrect discount for PROD002")
            else:
                self.assert_("Unknown item found in order")
Example #6
0
    def test_order_bad_product(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        order_descriptors = [
            ("PROD001", 1),
            ("PROD-FAKE", 1),
        ]

        with self.assertRaises(OrderingError):
            service.create_order("Customer", order_descriptors)

        self.assertTrue(call("PROD-FAKE") in self.product_repository.find.call_args_list,
                        "Fake product was not queried for")
Example #7
0
    def test_order_bad_product(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        order_descriptors = [
            ("PROD001", 1),
            ("PROD-FAKE", 1),
        ]

        with self.assertRaises(OrderingError):
            service.create_order("Customer", order_descriptors)

        self.assertTrue(
            call("PROD-FAKE") in self.product_repository.find.call_args_list,
            "Fake product was not queried for")
Example #8
0
    def test_order_fails_no_inventory_item(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        # Remove PROD002 from inventory
        self.inventory.pop("PROD002")

        with self.assertRaises(OrderingError):
            order = service.create_order("Customer", self.order_descriptors["ORD001"])

        self.assertTrue(call("PROD002") in self.product_repository.find.call_args_list,
                        "Product PROD002 was not queried for")
        self.assertTrue(call("PROD002") in self.inventory_repository.find.call_args_list,
                        "Product PROD002 was not queried for")
Example #9
0
    def test_order_creation(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        order = service.create_order("Customer",
                                     self.order_descriptors["ORD001"],
                                     customer_reference="Customer-PO-Ref")

        self.assertEquals("Customer-PO-Ref", order.customer_reference,
                          "Customer reference not set correctly")
        self.assertTrue(order.is_acknowledged(),
                        "Order should not have been acknowledged")
        self.assertEquals("ORD001", order.order_id,
                          "Order ID was not set correctly")

        for line_item in order.line_items:
            if line_item.sku == "PROD001":
                self.assertTrue(
                    call("PROD001")
                    in self.product_repository.find.call_args_list,
                    "Product PROD001 was not queried for")
                self.assertEquals(1, line_item.quantity,
                                  "Incorrect Quantity for PROD001")
                self.assertEquals(100.00, line_item.price,
                                  "Incorrect price for PROD001")
                self.assertEquals(0.3, line_item.discount,
                                  "Incorrect discount for PROD001")
            if line_item.sku == "PROD002":
                self.assertTrue(
                    call("PROD002")
                    in self.product_repository.find.call_args_list,
                    "Product PROD002 was not queried for")
                self.assertEquals(3, line_item.quantity,
                                  "Incorrect Quantity for PROD002")
                self.assertEquals(20.00, line_item.price,
                                  "Incorrect price for PROD002")
                self.assertEquals(0.1, line_item.discount,
                                  "Incorrect discount for PROD002")
            else:
                self.assert_("Unknown item found in order")
Example #10
0
    def test_order_fails_no_inventory_item(self):
        service = OrderingService(self.customer_repository,
                                  self.product_repository,
                                  self.order_repository,
                                  self.inventory_repository,
                                  self.pricing_service)

        # Remove PROD002 from inventory
        self.inventory.pop("PROD002")

        with self.assertRaises(OrderingError):
            order = service.create_order("Customer",
                                         self.order_descriptors["ORD001"])

        self.assertTrue(
            call("PROD002") in self.product_repository.find.call_args_list,
            "Product PROD002 was not queried for")
        self.assertTrue(
            call("PROD002") in self.inventory_repository.find.call_args_list,
            "Product PROD002 was not queried for")