예제 #1
0
 def check_validation(self):
     prod = Product()
     prod.code = "some01"
     try:
         prod.save()
     except ValueError, e:
         pass
예제 #2
0
 def check_validation(self):
     prod = Product()
     prod.code = "some01"
     try:
         prod.save()
     except ValueError, e:
         pass
예제 #3
0
 def check_single_nodeID(self):
     prod = Product()
     prod.categories = 1
     prod.code = ""
     try:
         prod.save()
     finally:
         assert prod.categories.IDs() == (1,), "product doesn't cope with single nodeID"
예제 #4
0
    def check_categories_some_more(self):
        prod = Product()
        prod.code = "some02"
        prod.name = "something else"
        prod.categories = (1, 2, 3, 4)
        prod.save()

        self.cur.execute("SELECT nodeID FROM shop_product_node " "WHERE productID=2 " "ORDER by nodeID ")

        actual = [int(row[0]) for row in self.cur.fetchall()]
        assert actual == [1, 2, 3, 4], "Product doesn't save nodeIDs properly: %s" % str(actual)

        # @TODO: do I really need this?
        actual = prod.categories.IDs()
        assert actual == (1, 2, 3, 4), "Product.categories.IDs() screws up: %s " % str(actual)

        ## make sure it still works after an update:
        assert prod == prod.categories.owner, "what the?"
        assert prod.ID == 2, "???"
        prod.categories = (1, 2)
        assert prod.categories.IDs() == (1, 2)
        assert prod.ID == 2, "???"
        prod.save()

        self.cur.execute("SELECT nodeID FROM shop_product_node " "WHERE productID=2 " "ORDER BY nodeID")

        actual = self.cur.fetchall()
        assert actual == ((1,), (2,)), "Product doesn't update nodeIDs properly: %s" % str(actual)

        assert prod.categories.IDs() == (1, 2), "Product doesn't return nodeIDs properly after an update"
예제 #5
0
    def check_styles(self):

        prod = Product()
        assert len(prod.styles) == 0, "shouldn't be any styles by default."
        style = prod.styles.new()
        style.code = "ABC"
        prod.styles << style
        assert len(prod.styles) == 1, "didn't add style in memory.."

        prod = Product()
        prod.name = prod.code = "abc"
        prod.save()
        style = prod.styles.new()
        style.code = "xyz"
        prod.styles << style
        assert len(prod.styles) == 1, "didn't save style to db.."
예제 #6
0
    def check_available(self):
        prod = Product()
        assert prod.available == 0, "products shouldn't be available by default."

        prod.stock = 10
        assert prod.available == 10, "available should be stock when nothing on hold"

        prod.hold = 5
        assert prod.available == 5, "available should be stock - hold"

        style = prod.styles.new()
        style.stock = 10
        style.hold = 5
        prod.styles << style
        actual = prod.available
        assert actual == 10, "available should take styles into account.. (got %s)" % actual
예제 #7
0
    def check_delete(self):
        cat = Category()
        cat.name = "stuff"

        prod = Product()
        prod.name = "ASDF"
        prod.code = "ASFD"
        cat.products << prod

        cat.save()

        assert len(cat.products) == 1, "got wrong lengths for products"
        try:
            gotError = 0
            cat.delete()
        except AssertionError:
            gotError = 1

        assert gotError, "didn't get error deleting category with products"
예제 #8
0
    def check_available(self):
        prod = Product()
        assert prod.available == 0, \
               "products shouldn't be available by default."

        prod.stock = 10
        assert prod.available == 10, \
               "available should be stock when nothing on hold"

        prod.hold = 5
        assert prod.available == 5, \
               "available should be stock - hold"

        style = prod.styles.new()
        style.stock = 10
        style.hold = 5
        prod.styles << style
        actual = prod.available
        assert actual == 10, \
               "available should take styles into account.. (got %s)" % actual
예제 #9
0
    def check_delete(self):
        cat = Category()
        cat.name = "stuff"

        prod = Product()
        prod.name = "ASDF"
        prod.code = "ASFD"
        cat.products << prod

        cat.save()
        
        assert len(cat.products)==1, \
               "got wrong lengths for products"
        try:
            gotError=0
            cat.delete()
        except AssertionError:
            gotError=1
            
        assert gotError, \
               "didn't get error deleting category with products"
예제 #10
0
    def check_categories_some_more(self):
        prod = Product()
        prod.code = 'some02'
        prod.name = 'something else'
        prod.categories = (1, 2, 3, 4)
        prod.save()

        self.cur.execute("SELECT nodeID FROM shop_product_node "
                         "WHERE productID=2 "
                         "ORDER by nodeID ")

        actual = [int(row[0]) for row in self.cur.fetchall()]
        assert actual == [1,2,3,4], \
               "Product doesn't save nodeIDs properly: %s" % str(actual)

        #@TODO: do I really need this?
        actual = prod.categories.IDs()
        assert  actual == (1, 2, 3, 4), \
               "Product.categories.IDs() screws up: %s " % str(actual)

        ## make sure it still works after an update:
        assert prod == prod.categories.owner, "what the?"
        assert prod.ID == 2, "???"
        prod.categories = (1, 2)
        assert prod.categories.IDs() == (1, 2)
        assert prod.ID == 2, "???"
        prod.save()

        self.cur.execute("SELECT nodeID FROM shop_product_node "
                         "WHERE productID=2 "
                         "ORDER BY nodeID")

        actual = self.cur.fetchall()
        assert actual == ((1,),(2,)), \
               "Product doesn't update nodeIDs properly: %s" % str(actual)

        assert prod.categories.IDs() == (1, 2), \
               "Product doesn't return nodeIDs properly after an update"
예제 #11
0
    def test_get_subtotal(self):
        """
        subtotal should always be product price * quantity
        """
        det = Detail()
        assert det.subtotal == 0, \
               "wrong default subtotal: %s" % det.subtotal

        prod = Product()
        prod.price = '12.00'
        det.product = prod
        assert det.subtotal == 0, \
               "wrong subtotal for 0 quantity: %s" % det.subtotal

        det = Detail()
        det.quantity = 10
        det.product = prod
        assert det.subtotal == 120, \
               "didn't get correct subtotal with nonzero quantity"

        det.quantity = 2
        assert det.subtotal == 24, \
               "didn't change subtotal when quantity changed.."
예제 #12
0
    def test_get_subtotal(self):
        """
        subtotal should always be product price * quantity
        """
        det = Detail()
        assert det.subtotal == 0, \
               "wrong default subtotal: %s" % det.subtotal
        
        prod = Product()
        prod.price = '12.00'
        det.product = prod
        assert det.subtotal == 0, \
               "wrong subtotal for 0 quantity: %s" % det.subtotal

        det = Detail()
        det.quantity = 10
        det.product = prod
        assert det.subtotal == 120, \
               "didn't get correct subtotal with nonzero quantity"

        det.quantity = 2
        assert det.subtotal == 24, \
               "didn't change subtotal when quantity changed.."     
예제 #13
0
 def check_single_nodeID(self):
     prod = Product()
     prod.categories = 1
     prod.code = ""
     try:
         prod.save()
     finally:
         assert prod.categories.IDs() == (1,), \
                "product doesn't cope with single nodeID"
예제 #14
0
    def check_categories(self):
        prod = Product()
        assert len(prod.categories)==0, \
               "categories should be empty list by default"

        nodeA = sixthday.Node()
        nodeA.name = "abc"
        nodeA.save()

        nodeB = sixthday.Node()
        nodeB.name = "xyz"
        nodeB.save()

        prod = Product()
        prod.code = 'some03'
        prod.name = 'something else'
        prod.categories = (nodeA.ID, nodeB.ID)
        prod.save()

        cats = prod.categories
        assert cats[0].name == "abc" and cats[1].name == "xyz", \
               ".categories broke."
예제 #15
0
    def check_categories(self):
        prod = Product()
        assert len(prod.categories) == 0, "categories should be empty list by default"

        nodeA = sixthday.Node()
        nodeA.name = "abc"
        nodeA.save()

        nodeB = sixthday.Node()
        nodeB.name = "xyz"
        nodeB.save()

        prod = Product()
        prod.code = "some03"
        prod.name = "something else"
        prod.categories = (nodeA.ID, nodeB.ID)
        prod.save()

        cats = prod.categories
        assert cats[0].name == "abc" and cats[1].name == "xyz", ".categories broke."
예제 #16
0
    def check_styles(self):

        prod = Product()
        assert len(prod.styles) == 0, \
               "shouldn't be any styles by default."
        style = prod.styles.new()
        style.code = "ABC"
        prod.styles << style
        assert len(prod.styles) == 1, \
               "didn't add style in memory.."

        prod = Product()
        prod.name = prod.code = "abc"
        prod.save()
        style = prod.styles.new()
        style.code = "xyz"
        prod.styles << style
        assert len(prod.styles)==1, \
               "didn't save style to db.."
예제 #17
0
 def check_retail(self):
     assert isinstance(Product().retail, FixedPoint), \
            "retail is wrong type!"
예제 #18
0
 def check_cost(self):
     assert isinstance(Product().cost, FixedPoint), \
            "cost is wrong type!"
예제 #19
0
 def check_price(self):
     assert isinstance(Product().price, FixedPoint), \
            "price is wrong type!"