def initOrder(cls, data): response = {'orderInitialized': False, 'object': None} """If all the condition are respected, object will contain the order model object and if at least one condition is not respected, object will contain a dict with the first error.""" if ValidateProductOrderSchema(pOrderDict=data) is True: pList = data['product'] validation = ValidateOrder(pList=pList) if validation is not True: return validation order = Order.create() instanciatedProductList = [] for p in pList: prod = ProductOrdered.create(order=order, product=p["id"], product_quantity=p["quantity"]) instanciatedProductList.append(prod) order.setTotalPrice(products=instanciatedProductList) order.setShippingPrice(products=instanciatedProductList) order.save() response['status_code'] = 200 response['object'] = order.id else: response = getMissingProductFieldErrorDict() return response
def test_credit_card_missing_client_information(self, app, client): with app.app_context(): product = Product(name="Brown eggs", type="dairy", description="Raw organic brown eggs in a basket", image="0.jpg", height=600, weight=400, price=28.1, rating=5, in_stock=True) product.save() order = Order(product=product, product_quantity=1) order.save() response = client.put("/order/1", json={ "credit_card": {"name": "John Doe", "number": "4242 4242 4242 4242", "expiration_year": 2024, "cvv": "123", "expiration_month": 9}}) assert response.status_code == 422 assert b'missing-fields' in response.data
def test_set_order_total_price(): product_price = 200 product_quantity = 2 total_price = product_price * product_quantity product = Product(id="1", name="product 1", type="type 1", description="description 1", image="image 1", price=product_price) order = Order(product=product, product_quantity=product_quantity) order.setTotalPrice() assert order.total_price == total_price
def test_set_order_shipping_price_with_2001g_weight(): product_price = 200 product_quantity = 1 product_weight = 2001 product = Product(id="1", name="product 1", type="type 1", description="description 1", image="image 1", price=product_price, weight=product_weight) order = Order(product=product, product_quantity=product_quantity) order.setShippingPrice() assert order.shipping_price == 25.00
def getNextOrderID(): id = Order.select(fn.Max(Order.id)).scalar() if id is None: id = 1 else: id += 1 return id
def test_setCreditCard_order_already_paid(self, app): product = Product(name="Brown eggs", type="dairy", description="Raw organic brown eggs in a basket", image="0.jpg", height=600, weight=400, price=28.1, rating=5, in_stock=True) product.save() shipping_information = ShippingInformation( country="Canada", address="201, rue des rosiers", postal_code="G7X 3Y9", city="Chicoutimi", province="QC") shipping_information.save() order = Order(product=product, product_quantity=1, email="*****@*****.**", shipping_information=shipping_information, paid=True) order.setShippingPrice() order.setTotalPrice() order.save() response = OrderServices.setCreditCard(cCardDict={ "credit_card": { "name": "John Doe", "number": "4242 4242 4242 4242", "expiration_year": 2024, "cvv": "123", "expiration_month": 9 } }, orderId=1) assert response == { 'set': False, "object": { "errors": { "order": { "code": "already-paid", "name": "The order has already been paid." } } }, "status_code": 422 }
def getOrder(cls, id): redis = getRedis() order = redis.get(str(id)) if order is not None: order = pickle.loads(order) else: order = Order.get_or_none(Order.id == id) return order
def test_setCreditCard_missing_client_informations(self, app): product = Product(name="Brown eggs", type="dairy", description="Raw organic brown eggs in a basket", image="0.jpg", height=600, weight=400, price=28.1, rating=5, in_stock=True) product.save() order = Order(product=product, product_quantity=1) order.save() response = OrderServices.setCreditCard(cCardDict={ "credit_card": { "name": "John Doe", "number": "4242 4242 4242 4242", "expiration_year": 2024, "cvv": "123", "expiration_month": 9 } }, orderId=1) assert response == { 'set': False, "object": { "errors": { "order": { "code": "missing-fields", "name": "Client informations are required before applying a credit card to the order." } } }, "status_code": 422 }
def test_credit_card_missing_fields(self, app, client): with app.app_context(): product = Product(name="Brown eggs", type="dairy", description="Raw organic brown eggs in a basket", image="0.jpg", height=600, weight=400, price=28.1, rating=5, in_stock=True) product.save() shipping_information = ShippingInformation(country="Canada", address="201, rue des rosiers", postal_code="G7X 3Y9", city="Chicoutimi", province="QC") shipping_information.save() order = Order(product=product, product_quantity=1, email="*****@*****.**", shipping_information=shipping_information) order.setShippingPrice() order.setTotalPrice() order.save() response = client.put("/order/1", json={ "credit_card": {"name": "John Doe", "number": "4242 4242 4242 4242", "expiration_year": 2024, "expiration_month": 9}}) assert response.status_code == 422 assert b'missing-fields' in response.data