def requestOrder(postBody): response = {} try: order = Order(postBody["serviceType"], postBody["pickupAddress"], postBody["dropoffAddress"], postBody["customerId"]) orderObj = order.__dict__ client = mongoConnect() db = client.team12_demand orders = db.orders publicId = orders.count_documents({}) + 1000 orderObj["publicId"] = publicId orderId = orders.insert_one(orderObj).inserted_id address1 = (orderObj["pickupAddress"]).replace(" ", "+") address2 = (orderObj["dropoffAddress"]).replace(" ", "+") #### Uncomment this block when supply is up on server #### routeResponse = requests.get( f"http://localhost:8081/vehicles/req?service_type={orderObj['serviceType']}&order_id={orderId}&customer_id={orderObj['customerId']}&destination={address1}" ) # routeResponse = requests.get(f"https://supply.team12.sweispring21.tk/api/vehicles/req?service_type={orderObj['serviceType']}&order_id={orderId}&customer_id={orderObj['customerId']}&destination={address1}") responseObj = routeResponse.json() routeObj = responseObj["data"] if responseObj['status'] == "OK": order.setStatus("vehicle on route") response = { 'status': responseObj['status'], 'data': { "_id": orderId, "publicId": publicId, "status": order.getStatus(), "routeObj": routeObj } } dbRouteObj = routeObj else: response = { 'status': responseObj['status'], 'data': responseObj['data'] } order.setStatus("unfulfilled") dbRouteObj = routeObj orders.update_one( {"_id": orderId}, {"$set": { "status": order.getStatus(), "routeObj": dbRouteObj }}) except ValueError as err: response = {'status': 'CONFLICT', 'data': {'msg': err}} except Exception as err: logging.error(err) response = { 'status': 'INTERNAL_SERVER_ERROR', 'data': { 'msg': 'Server stopped working, please try again later' } } return response
def test_valid_status_setter(self): order = Order() order.setStatus(validStatus1) correctValue = validStatus1 self.assertEqual( order.getStatus(), correctValue, msg= f"Error in the email setter and getter values:\n\n{order.getStatus()}\n\n{correctValue}" )