Example #1
0
    def testAddItemsAndGetItems(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=(), quantity=2)
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        i1, i2 = im.getItems()        

        i1.getId() == "0"
        i1.getProduct() == self.product_1
        i1.getAmount() == 4
        
        i1.getId() == "1"
        i1.getProduct() == self.product_2
        i1.getAmount() == 2
Example #2
0
    def testDeleteItemByOrd(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        # Try to delete non existing ord
        result = im.deleteItemByOrd(3)
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)

        # delete first item
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)
        self.assertEqual(len(im.getItems()), 1)

        # Once again, but now it should be another
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)
        self.assertEqual(len(im.getItems()), 0)
Example #3
0
    def testDeleteItemByOrd(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        # Try to delete non existing ord
        result = im.deleteItemByOrd(3)
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)
        
        # delete first item
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 1)

        # Once again, but now it should be another
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 0)
Example #4
0
    def testAddItemsAndGetItems(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=(), quantity=2)
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        i1, i2 = im.getItems()

        i1.getId() == "0"
        i1.getProduct() == self.product_1
        i1.getAmount() == 4

        i1.getId() == "1"
        i1.getProduct() == self.product_2
        i1.getAmount() == 2
Example #5
0
    def testDeleteItem(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)
        
        # Try to delete non existing id
        result = im.deleteItem("3")
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)

        # delete first item
        result = im.deleteItem("0")
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 1)

        # delete second item
        result = im.deleteItem("1")
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 0)
Example #6
0
    def testDeleteItem(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        # Try to delete non existing id
        result = im.deleteItem("3")
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)

        # delete first item
        result = im.deleteItem("0")
        self.assertEqual(result, True)
        self.assertEqual(len(im.getItems()), 1)

        # delete second item
        result = im.deleteItem("1")
        self.assertEqual(result, True)
        self.assertEqual(len(im.getItems()), 0)
Example #7
0
    def afterSetUp(self):
        """
        """
        super(TestCartItemProperties, self).afterSetUp()
        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)

        properties = (
            {
                "id": "color",
                "selected_option": "Red"
            },  # -10.0
            {
                "id": "material",
                "selected_option": "Wood"
            },  # 0.0
            {
                "id": "quality",
                "selected_option": "High"
            },  # 1500.0
        )

        im.addItem(self.product_1, properties=properties, quantity=3)
        self.item1 = im.getItems()[0]
    def testGetItems(self):
        """
        """
        self.order.invokeFactory("OrderItem", "item_1")
        self.order.invokeFactory("OrderItem", "item_2")        
                        
        im = IItemManagement(self.order)
        item_ids = [item.getId() for item in im.getItems()]

        self.assertEqual(item_ids, ["item_1", "item_2"])
    def testGetItems(self):
        """
        """
        self.order.invokeFactory("OrderItem", "item_1")
        self.order.invokeFactory("OrderItem", "item_2")

        im = IItemManagement(self.order)
        item_ids = [item.getId() for item in im.getItems()]

        self.assertEqual(item_ids, ["item_1", "item_2"])
Example #10
0
    def testAddItemFromCartItem(self):
        """
        """
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        properties = (
            {
                "id": "color",
                "selected_option": "Red"
            },  # -10.0
            {
                "id": "material",
                "selected_option": "Wood"
            },  # 0.0
            {
                "id": "quality",
                "selected_option": "High"
            },  # 1500.0
        )

        cim = IItemManagement(cart)
        cim.addItem(self.product_1, properties=properties, quantity=3)

        cart_item = IItemManagement(cart).getItems()[0]

        oim = IItemManagement(self.order)
        oim._addItemFromCartItem("0", cart_item)

        order_item = oim.getItems()[0]

        self.assertEqual(order_item.getProductQuantity(), 3)
        self.assertEqual("%.2f" % order_item.getProductPriceGross(), "22.00")
        self.assertEqual("%.2f" % order_item.getProductPriceNet(), "18.49")
        self.assertEqual("%.2f" % order_item.getProductTax(), "3.51")
        self.assertEqual("%.2f" % order_item.getPriceGross(), "4536.00")
        self.assertEqual("%.2f" % order_item.getPriceNet(), "3811.76")
        self.assertEqual(order_item.getTaxRate(), 19.0)
        self.assertEqual("%.2f" % order_item.getTax(), "724.24")
        self.assertEqual(order_item.getProduct(), self.product_1)

        properties = order_item.getProperties()

        self.assertEqual(properties[0]["title"], "Color")
        self.assertEqual(properties[0]["selected_option"], "Red")
        self.assertEqual(properties[0]["price"], "-10.0")

        self.assertEqual(properties[1]["title"], "Material")
        self.assertEqual(properties[1]["selected_option"], "Wood")
        self.assertEqual(properties[1]["price"], "0.0")

        self.assertEqual(properties[2]["title"], "Quality")
        self.assertEqual(properties[2]["selected_option"], "High")
        self.assertEqual(properties[2]["price"], "1500.0")
Example #11
0
    def afterSetUp(self):
        """
        """
        super(TestCartItems, self).afterSetUp()

        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)
        im.addItem(self.product_1, properties=(), quantity=2)
        im.addItem(self.product_2, properties=(), quantity=3)

        self.item1, self.item2 = im.getItems()
 def afterSetUp(self):
     """
     """
     super(TestCartItems, self).afterSetUp()
     
     self.login("newmember")
     cm = ICartManagement(self.shop)
     cart = cm.createCart()
     
     im = IItemManagement(cart)
     im.addItem(self.product_1, properties=(), quantity=2)
     im.addItem(self.product_2, properties=(), quantity=3)
     
     self.item1, self.item2 = im.getItems()
    def testAddItemFromCartItem(self):
        """
        """
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        properties = (
            {"id" : "color"   , "selected_option" : "Red" },    # -10.0
            {"id" : "material", "selected_option" : "Wood"},    # 0.0
            {"id" : "quality" , "selected_option" : "High"},    # 1500.0
        )

        cim = IItemManagement(cart)
        cim.addItem(self.product_1, properties=properties, quantity=3)
                
        cart_item = IItemManagement(cart).getItems()[0]
        
        oim = IItemManagement(self.order)        
        oim._addItemFromCartItem("0", cart_item)
        
        order_item = oim.getItems()[0]
        
        self.assertEqual(order_item.getProductQuantity(), 3)
        self.assertEqual("%.2f" % order_item.getProductPriceGross(), "22.00")
        self.assertEqual("%.2f" % order_item.getProductPriceNet(), "18.49")
        self.assertEqual("%.2f" % order_item.getProductTax(), "3.51")
        self.assertEqual("%.2f" % order_item.getPriceGross(), "4536.00")
        self.assertEqual("%.2f" % order_item.getPriceNet(), "3811.76")
        self.assertEqual(order_item.getTaxRate(), 19.0)
        self.assertEqual("%.2f" % order_item.getTax(), "724.24")
        self.assertEqual(order_item.getProduct(), self.product_1)
        
        properties = order_item.getProperties()
            
        self.assertEqual(properties[0]["title"], "Color")
        self.assertEqual(properties[0]["selected_option"], "Red")
        self.assertEqual(properties[0]["price"], "-10.0")

        self.assertEqual(properties[1]["title"], "Material")
        self.assertEqual(properties[1]["selected_option"], "Wood")
        self.assertEqual(properties[1]["price"], "0.0")

        self.assertEqual(properties[2]["title"], "Quality")
        self.assertEqual(properties[2]["selected_option"], "High")
        self.assertEqual(properties[2]["price"], "1500.0")
    def testAddItemsFromCart(self):
        """
        """
        view = getMultiAdapter((self.shop.products.product_1, self.shop.products.product_1.REQUEST), name="addToCart")
        view.addToCart()

        view = getMultiAdapter((self.shop.products.product_2, self.shop.products.product_2.REQUEST), name="addToCart")
        view.addToCart()

        cm = ICartManagement(self.shop)
        cart = cm.getCart()
        
        im = IItemManagement(self.order)
        im.addItemsFromCart(cart)

        product_ids = [item.getProduct().getId() for item in im.getItems()]

        self.assertEqual(product_ids, ["product_1", "product_2"])
    def afterSetUp(self):
        """
        """
        super(TestCartItemProperties, self).afterSetUp()
        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)

        properties = (
            {"id" : "color"   , "selected_option" : "Red" },    # -10.0
            {"id" : "material", "selected_option" : "Wood"},    # 0.0
            {"id" : "quality" , "selected_option" : "High"},    # 1500.0
        )

        im.addItem(self.product_1, properties=properties, quantity=3)
        self.item1 = im.getItems()[0]
Example #16
0
    def testAddItemsFromCart(self):        
        """
        """
        cm = ICartManagement(self.shop)
        cart1 = cm.createCart()
        
        im1 = IItemManagement(cart1)
        
        im1.addItem(self.product_1, properties=())
        im1.addItem(self.product_2, properties=(), quantity=3)
        
        self.login("newmember")
        cart2 = cm.createCart()

        im2 = IItemManagement(cart2)
        im2.addItemsFromCart(cart1)
        
        self.assertEqual(len(im2.getItems()), 2)
Example #17
0
    def testAddItemsFromCart(self):
        """
        """
        cm = ICartManagement(self.shop)
        cart1 = cm.createCart()

        im1 = IItemManagement(cart1)

        im1.addItem(self.product_1, properties=())
        im1.addItem(self.product_2, properties=(), quantity=3)

        self.login("newmember")
        cart2 = cm.createCart()

        im2 = IItemManagement(cart2)
        im2.addItemsFromCart(cart1)

        self.assertEqual(len(im2.getItems()), 2)
Example #18
0
    def testAddItemsFromCart(self):
        """
        """
        view = getMultiAdapter((self.shop.products.product_1,
                                self.shop.products.product_1.REQUEST),
                               name="addToCart")
        view.addToCart()

        view = getMultiAdapter((self.shop.products.product_2,
                                self.shop.products.product_2.REQUEST),
                               name="addToCart")
        view.addToCart()

        cm = ICartManagement(self.shop)
        cart = cm.getCart()

        im = IItemManagement(self.order)
        im.addItemsFromCart(cart)

        product_ids = [item.getProduct().getId() for item in im.getItems()]

        self.assertEqual(product_ids, ["product_1", "product_2"])