Exemplo n.º 1
0
 def test_user_catch_order_change_state(self):
     from src.auth.models.order_table import OrderModel
     from src.auth.services.user_service import UserService
     from src.auth.services.delivery_service import DeliveryService
     from src.auth.services.order_service import OrderService
     order_service = OrderService()
     user_service = UserService()
     delivery_service = DeliveryService()
     #Creo usuario normal
     content_user = {"name":"Rodrigo","email":"*****@*****.**","phone_number":42223333,"role":"usuario","password": "******","firebase_uid": "ajsjfkasf","suscripcion":"flat"}
     user = user_service.create_normal_user(content_user)
     assert user.state == 'free'
     #Creo usuario delivery
     content_user =  {"name": "JUan","email": "*****@*****.**","phone_number": 42223333,"role": "usuario","password": "******", "firebase_uid": "ajsjadasfkasf","picture": "www.photo.com","balance": 100}
     user_delivery = delivery_service.create_delivery_user(content_user)
     assert user_delivery.state == 'free'
     #Creo orden
     order_info = {"shop_id": 8572833,"products": [{"product_id": 248524,"units": 2},{"product_id": 1414488,"units": 1}], "latitude": -33.58672,"longitude": -52.52345,
     "payWithPoints": False,"state": 'created', 'user_id':1, "price":200}
     order = OrderModel(order_info)
     order.save()
     #Agarro la orden
     offer_info={}
     offer_info["delivery_price"] = 200
     offer_info["delivery_pay"] = 100
     order_service.catch_order(order.order_id, user_delivery.user_id,offer_info)
     assert user.state == 'waiting'
     assert user_delivery.state == 'working'
     #Entro la orden
     order_service.order_delivered(order.order_id)
     assert user.state == 'free'
     assert user_delivery.state == 'free'
Exemplo n.º 2
0
def get_delivery_price(_id):
    user_id = request.args.get('user_id')
    delivery_id = request.args.get('delivery_id')
    client_lat = request.args.get('latitude')
    client_long = request.args.get('longitude')
    if (user_id is None) | (delivery_id is None) | (client_lat is None) | (
            client_long is None):
        raise InvalidQueryParameters("Invalid query values")
    service = ShopService()
    shop = service.get_shop(_id)
    delivery_service = DeliveryService()
    price, pay = delivery_service.get_delivery_price_and_pay(
        user_id, delivery_id, shop, client_lat, client_long)
    return jsonify({'price': price, 'pay': pay})
Exemplo n.º 3
0
def add_user():
    content = request.get_json()
    service = UserService()
    try:
        service = UserService()
        user_data = normal_user_schema.load(content)
        service.create_normal_user(user_data=user_data)
    except IntegrityError as e:
        return jsonify({'msg': 'user with this email already exists.'}), 409
    except:
        pass
    else:
        return jsonify({'msg': 'a new user was created.'}), 200

    try:
        service = DeliveryService()
        user_data = delivery_user_schema.load(content)
        service.create_delivery_user(user_data=user_data)
    except ValidationError:
        raise InvalidUserInformation("Falta informacion del usuario")
    except IntegrityError as e:
        return jsonify({'msg':
                        'delivery with this email already exists.'}), 409
    except:
        raise
    else:
        return jsonify({'msg': 'a new delivery was created.'}), 200
Exemplo n.º 4
0
def get_deliveries():
    longitude = request.args.get('longitude')
    latitude = request.args.get('latitude')
    cantidad = int(request.args.get('cantidad'))
    if (longitude is None) | (latitude is None) | (cantidad is None):
        raise InvalidQueryParameters("Invalid query values")
    delivery_service = DeliveryService()
    direc_service = DirecService()
    try:
        shop = {"latitude": latitude, "longitude": longitude}
        deliverys = delivery_service.get_available_deliverys()
        deliverys = direc_service.get_nearly_deliverys(shop,deliverys)
    except:
        raise
    else:
        if not deliverys:
            return jsonify({'msg': 'No hay deliveries cerca'}), 431
        return jsonify(deliverys[:cantidad]), 200
Exemplo n.º 5
0
def delete_delivery():
    delivery_id = request.args.get('id')
    try:
        response = DeliveryService().delete_delivery(delivery_id)
    except NotFoundException as e:
        return jsonify({'404': "delivery {}".format(e.msg)}), 404
    except:
        raise
    else:
        return jsonify({'OK': "delivery deleted"}), 200
Exemplo n.º 6
0
def statics():
    return jsonify({
        "users":
        UserService().get_quantity_users(),
        "deliveries":
        DeliveryService().get_quantity_deliverys(),
        "completedOrders":
        OrderService().get_quantity_complete_orders(),
        "canceledOrders":
        OrderService().get_quantity_cancelled_orders()
    }), 200
Exemplo n.º 7
0
def update_delivery():
    delivery_id = request.args.get('id')
    content = request.get_json()
    try:
        response = DeliveryService().update_delivery(delivery_id, content)
    except NotFoundException as e:
        return jsonify({'404': "delivery {}".format(e.msg)}), 404
    except:
        raise
    else:
        return jsonify({"OK": "Delivery actualizado con exito!"}), 200
Exemplo n.º 8
0
def create_delivery():
    try:
        content = request.get_json()
        content['role'] = 'delivery'
        DeliveryService().create_delivery_user(content)
    except ValidationError:
        return jsonify({"error": "Informacion del delivery Incorrecta"}), 420
    except:
        raise
    else:
        return jsonify({"OK": "Delivery creado con exito!"}), 200
Exemplo n.º 9
0
 def test_get_deliverys_direc_ordered(self):
     from src.auth.models.user_table import DeliveryUserModel
     from src.auth.services.delivery_service import DeliveryService
     from src.auth.services.direc_service import DirecService
     user = DeliveryUserModel(delivery_data)
     user.latitude = -34.849859
     user.longitude = -58.386222
     user.save()
     user_d = DeliveryUserModel(delivery2_data)
     user_d.latitude = -34.859575
     user_d.longitude = -58.380182
     user_d.save()
     delivery_service = DeliveryService()
     users = delivery_service.get_available_deliverys()
     assert users[0]["user_id"] == 1
     assert len(users) == 2
     direc_service = DirecService()
     shop = {"latitude": -34.859138, "longitude": -58.387252}
     users = direc_service.get_nearly_deliverys(shop, users)
     #Al ordenarlos el primer usuario tendria que ser el usuario 2
     assert users[0]["user_id"] == 2
Exemplo n.º 10
0
def statics_deliverys():
    try:
        data = {
            "year_from": request.args.get('year_from'),
            "month_from": request.args.get('month_from'),
            "year_to": request.args.get('year_to'),
            "month_to": request.args.get('month_to')
        }
        data = statics_datetime_schema.load(data)
        result = DeliveryService().get_quantity_deliverys_by_month(
            data['year_from'], data['month_from'], data['year_to'],
            data['month_to'])
    except ValidationError:
        return jsonify({"error": "Informacion Incorrecta"}), 410
    except:
        raise
    else:
        return jsonify(result), 200
Exemplo n.º 11
0
    def order_delivered(self, order_id):
        from src.auth.models.order_table import OrderModel
        from src.auth.services.user_service import UserService
        from src.auth.services.delivery_service import DeliveryService
        order = OrderModel.get_instance(order_id)
        order_info = {}
        user_service = UserService()
        del_service = DeliveryService()
        #Pagar al delivery
        if order.payWithPoints: #chequeo que el que acepto la orden sea un usuario normal, no delivery
            order_info["payWithPoints"] = True
            order_info['favourPoints'] = order.favourPoints
        else:
            order_info["payWithPoints"] = False
            order_info["delivery_price"] = order.delivery_pay

        user_service.pay_order(order.user_id, order.delivery_id, order_info)
        user_service.user_finish_working(order.delivery_id)
        user_service.receive_order(order.user_id)

        self.change_order_state(order_id, "delivered")
Exemplo n.º 12
0
def set_users():
    normal_user = {
        "name":
        "Flavio Normal",
        "email":
        "*****@*****.**",
        "password":
        "******",
        "firebase_uid":
        "SJElQiZPrMMHGRzjrBuScvLW8Cc2",
        "role":
        "usuario",
        "phone_number":
        135138,
        "suscripcion":
        "flat",
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg"
    }

    normal_user2 = {
        "name":
        "Flavio Normal",
        "email":
        "*****@*****.**",
        "password":
        "******",
        "firebase_uid":
        "2yxGFRvkA3TLg1GMKjYDNzHfu6k1",
        "role":
        "usuario",
        "phone_number":
        135138,
        "suscripcion":
        "flat",
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg"
    }

    normal_user3 = {
        "name":
        "Flavio Normal",
        "email":
        "*****@*****.**",
        "password":
        "******",
        "firebase_uid":
        "PKCPkcLExuh8ewLbL2dPDuVuKcY2",
        "role":
        "usuario",
        "phone_number":
        135138,
        "suscripcion":
        "flat",
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg"
    }

    normal_user4 = {
        "name":
        "Flavio Perez",
        "email":
        "*****@*****.**",
        "firebase_uid":
        "z5B7CMytC9YJ11LAcvREY4F5Dvg2",
        "role":
        "usuario",
        "phone_number":
        135138,
        "suscripcion":
        "flat",
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg"
    }

    delivery_user = {
        "name": "Flavio Delivery",
        "email": "*****@*****.**",
        "password": "******",
        "firebase_uid": "05FvThkGGaaDu4PW1qFde3obrjQ2",
        "role": "delivery",
        "phone_number": 135138,
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg",
        "balance": 0
    }

    delivery_user2 = {
        "name": "Flavio Delivery",
        "email": "*****@*****.**",
        "password": "******",
        "firebase_uid": "U5OMU4hcyJdejlEmJ1Mv73lnAnv2",
        "role": "delivery",
        "phone_number": 135138,
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg",
        "balance": 0
    }

    delivery_user3 = {
        "name": "Flavio Delivery",
        "email": "*****@*****.**",
        "password": "******",
        "firebase_uid": "9RmRydK0t1QcuYGSaVgcnAl1ewq1",
        "role": "delivery",
        "phone_number": 135138,
        "picture":
        "gs://foodie-taller2.appspot.com/images/61FuIoIFkLa55OvAYWODuU5SuPZ2/JPEG_20191112_200117_1526502813.jpg",
        "balance": 0
    }

    user_service = UserService()
    user_schema = NormalUserSchema().load(normal_user)
    user_service.create_normal_user(user_schema)
    user_schema = NormalUserSchema().load(normal_user2)
    user_service.create_normal_user(user_schema)
    user_schema = NormalUserSchema().load(normal_user3)
    user_service.create_normal_user(user_schema)
    user_schema = NormalUserSchema().load(normal_user4)
    user_service.create_normal_user(user_schema)

    del_service = DeliveryService()
    del_schema = DeliveryUserSchema().load(delivery_user)
    del_service.create_delivery_user(del_schema)
    del_schema = DeliveryUserSchema().load(delivery_user2)
    del_service.create_delivery_user(del_schema)
    del_schema = DeliveryUserSchema().load(delivery_user3)
    del_service.create_delivery_user(del_schema)

    coord1 = {"latitude": -34.601054, "longitude": -58.392317}
    coord2 = {"latitude": -34.611054, "longitude": -58.492317}
    coord3 = {"latitude": -34.616054, "longitude": -58.652317}
    coord4 = {"latitude": -34.606054, "longitude": -58.282317}
    coord5 = {"latitude": -34.654223, "longitude": -58.692317}
    coord6 = {"latitude": -34.651054, "longitude": -58.402317}
    coord7 = {"latitude": -34.611054, "longitude": -58.352317}

    user_service.update_coordinates(1, coord1)
    user_service.update_coordinates(2, coord2)
    user_service.update_coordinates(3, coord3)
    user_service.update_coordinates(4, coord4)
    user_service.update_coordinates(5, coord5)
    user_service.update_coordinates(6, coord6)
    user_service.update_coordinates(7, coord7)
Exemplo n.º 13
0
def deliveries():
    pageNumber = request.args.get('p')
    pageSize = request.args.get('pSize')
    result = DeliveryService().get_N_deliverys(
        int(pageNumber) - 1, int(pageSize))
    return jsonify(result), 200
Exemplo n.º 14
0
def get_delivery(_id):
    service = DeliveryService()
    delivery = service.get_delivery(_id)
    return jsonify(delivery),200