예제 #1
0
    def on_put(self, req, resp, productId):
        try:
            productId = int(productId)
            product = bl.getProduct(productId)

            if product is None:
                return falcon.HTTP_404

            doc = req.context['doc']
            newProduct  = Product.from_json(doc)

            if newProduct.productId is None:
                newProduct.productId = product.productId

            #If updated object has id which doesn't match old one, return http forbidden-status
            elif newProduct.productId != productId:
                return falcon.HTTP_403

            #update product
            bl.setProduct(newProduct)

            resp.status = falcon.HTTP_200 #Status Ok
        except:
            #Return 500 - internal error
            resp.status = falcon.HTTP_500
예제 #2
0
    def on_get(self, req, resp, productId):
        try:
            productId = int(productId)
            product = bl.getProduct(productId)

            if product is None:
                return falcon.HTTP_404

            result = {'product':product}

            resp.body = json.dumps(result, sort_keys=True, default=Product.serialize)
            resp.status = falcon.HTTP_200 #Status Ok

        except:
            #Return 500 - internal error
            resp.status = falcon.HTTP_500
예제 #3
0
def test_product_serialize():
    p = bl.getProduct(1)

    print(json.dumps(Product.serialize(p), sort_keys = True))
예제 #4
0
def test_product_remove():
     
    p = bl.getProduct(code="POOLBL")
    db.removeProduct(p.productId)
예제 #5
0
def test_product_add():
    print("Testing product insert..")

    db.updateProduct(Product(code="POOLBL",name="PoolBall",price=Decimal(9.80),in_stock=999))
    t = bl.getProduct(code="POOLBL")
    assert(t is not None)