def test_complete_order_gain_favour_points(self, set_order_price): from src.auth.models.user_table import NormalUserModel from src.auth.models.user_table import DeliveryUserModel from src.auth.services.order_service import OrderService from src.auth.services.order_ofert_service import OrderOfferService from src.auth.auth_exception import NotFoundException set_order_price.return_value = True CANTIDAD_FAVOUR_POINTS = 20 user = NormalUserModel(user_data) user.save() user_old_favour_points = user.favourPoints user_d = NormalUserModel(user2_data) user_d.save() user_d_old_favour_points = user.favourPoints order_service = OrderService() order_data["user_id"] = user.user_id order_data["payWithPoints"] = True order_data["favourPoints"] = CANTIDAD_FAVOUR_POINTS order = order_service.create_order(order_data) assert order.state == 'created' order_ofert_service = OrderOfferService() order_ofert_id = order_ofert_service.create_favour_offer( favour_offer_data) order_ofert_service.update_favour_offer_state(user_d.user_id, order_ofert_id, 'accepted') assert order.state == 'onWay' #Orden entregada order_service.order_delivered(order.order_id) assert user.favourPoints == user_old_favour_points - CANTIDAD_FAVOUR_POINTS assert user_d.favourPoints == user_d_old_favour_points + CANTIDAD_FAVOUR_POINTS
def test_delivery_cant_accept_favours(self, set_order_price): from src.auth.models.user_table import NormalUserModel from src.auth.models.user_table import DeliveryUserModel from src.auth.services.order_service import OrderService from src.auth.services.order_ofert_service import OrderOfferService from src.auth.auth_exception import NotFoundException set_order_price.return_value = True CANTIDAD_FAVOUR_POINTS = 20 user = NormalUserModel(user_data) user.save() delivery = DeliveryUserModel(delivery_data) delivery.save() order_service = OrderService() order_data["user_id"] = user.user_id order_data["payWithPoints"] = True order_data["favourPoints"] = CANTIDAD_FAVOUR_POINTS order = order_service.create_order(order_data) assert order.state == 'created' order_ofert_service = OrderOfferService() order_ofert = order_ofert_service.create_order_ofert(order_ofert_data) with self.assertRaisesRegex( NotFoundException, "ID invalido: Solo los usuarios comunes pueden aceptar favores" ): order_ofert_service.update_offer_state(delivery.user_id, order.order_id, 'accepted')
def update_favour_offer_state(_id): service = OrderOfferService() content = request.get_json() state = content['state'] try: service.update_favour_offer_state() except: return jsonify({'msg': 'Error: la oferta fue cancelada o el id de oferta es invalido'}),409 return jsonify({'msg': 'Offer modified'}), 200
def put_delivery_state(_id,_offer_id): service = OrderOfferService() try: content = request.get_json() state = content['state'] service.update_favour_offer_state(_id,_offer_id,state) except: return jsonify({"msg": "Error: oferta inválida o cancelada"}), 409 else: return jsonify({'msg': 'Offer modified'}),200
def put_delivery_state(_id,_offer_id): service = OrderOfferService() try: content = request.get_json() state = content['state'] service.update_offer_state(_id,_offer_id,state) except: return jsonify({'msg': 'Error: la oferta fue cancelada o el id de oferta es invalido'}),409 else: return jsonify({'msg': 'Offer modified'}), 200
def test_order_wit_discount_subtract_user_favour_pounts(self): from src.auth.models.user_table import NormalUserModel, DeliveryUserModel from src.auth.services.order_service import OrderService from src.auth.services.order_ofert_service import OrderOfferService from src.auth.models.product_table import ProductModel #Agrego dos productos p1 = ProductModel({ "shop_id": 1, "name": "Hamburguesa con queso", "description": "Hamburguesa con queso. Lechuga y tomate opcionales", "price": 120 }) p2 = ProductModel({ "shop_id": 2, "name": "Hamburguesa normal", "description": "Hamburguesa con queso. Lechuga y tomate opcionales", "price": 90 }) p1.save() p2.save() #Creo el user y el delivery user = NormalUserModel(user_data) user.save() delivery = DeliveryUserModel(delivery_data) delivery.save() assert user.favourPoints == 30 #Creo orden order_data_test = order_data.copy() order_data_test["products"] = [{ "product_id": p1.id, "units": 2 }, { "product_id": p2.id, "units": 1 }] order_data_test["discount"] = True order_data_test["user_id"] = user.user_id order_data_test["payWithPoints"] = False order_service = OrderService() order = order_service.create_order(order_data_test) #Oferto a delivery order_ofert_service = OrderOfferService() order_ofert_data["order_id"] = order.order_id order_ofert_data["delivery_id"] = delivery.user_id order_ofert_id = order_ofert_service.create_order_ofert( order_ofert_data) order_ofert_service.update_offer_state(delivery.user_id, order_ofert_id, 'accepted') assert order.state == 'onWay' #Completo orden order_service.order_delivered(order.order_id) assert user.favourPoints == 20
def add_delivery_offer(_id): service = OrderOfferService() try: content = request.get_json() offer_id = service.create_order_ofert(content) except marshmallow.exceptions.ValidationError as e: return jsonify({'msg': 'Missing order ofert information: {}'.format(e)}), 400 except sqlalchemy.exc.IntegrityError: return jsonify({'msg': 'order_id or delivery_id invalid'}), 430 except: raise else: return jsonify({'id': offer_id }), 200
def offer_a_favour(_id): service = OrderOfferService() try: content = request.get_json() offer_id = service.create_favour_offer(content) except marshmallow.exceptions.ValidationError as e: return jsonify({'msg': 'Missing order ofert information: {}'.format(e)}), 400 except sqlalchemy.exc.IntegrityError: return jsonify({'msg': 'order_id or delivery_id invalid'}), 430 except NotEnoughFavourPoints: return jsonify({"msg": "No tienes suficientes puntos"}), 408 except: raise else: return jsonify({'id': offer_id }), 200
def get_favour_offer_by_id(_id): service = OrderOfferService() offer = service.get_favour_offer_by_id(_id) return jsonify(offer), 200
def show_oferts(): service = OrderOfferService() oferts = service.get_oferts() return jsonify(oferts)
def getOffers(_id): service = OrderOfferService() response = service.get_delivery_current_offers(_id) return jsonify(response),200