def modify_category(category_id):
    """Modifica una categoría de producto"""
    if not request.is_json:
        abort(400)
    category = request.get_json()
    ProductsService.modify_category(category_id, category)
    return jsonify(result='success'), 200
Exemple #2
0
def test_delete_product_if_product_not_found_raises_not_found_error(
        _product_exists_and_belongs_to_user_mock,
        delete_one_by_id_mock, user_data, product_data):
    _product_exists_and_belongs_to_user_mock.side_effect = NotFoundError("not found")
    delete_one_by_id_mock.return_value = False
    with pytest.raises(NotFoundError):
        ProductsService.delete_product(user_data.uid, product_data.product_id)
def add_category():
    """Agrega una categoría de productos"""
    if not request.is_json:
        abort(400)
    category = request.get_json()
    ProductsService.add_category(category)
    return jsonify(result='success'), 200
def add_product():
    """Servicio de publicación de articulo para la venta"""
    uid = get_jwt_identity()
    if not request.is_json:
        abort(400)
    product = request.get_json()
    product_id = ProductsService.add_product(product, uid)
    return jsonify(result='success', _id=product_id), 200
def add_product_answer(product_id, question_id):
    """Servicio de alta de respuesta a pregunta:
    permite responder una pregunta que fue realizada."""
    uid = get_jwt_identity()
    if not request.is_json:
        abort(400)
    answer = request.get_json()
    product = ProductsService.add_answer(answer, product_id, question_id, uid)
    return jsonify(product), 200
def add_product_question(product_id):
    """Servicio de alta de pregunta: permite realizar una pregunta
     acerca de un artículo que se encuentra publicado para la venta"""
    uid = get_jwt_identity()
    if not request.is_json:
        abort(400)
    question = request.get_json()
    product = ProductsService.add_question(question, product_id, uid)
    return jsonify(product), 200
def get_products():
    """Servicio de búsqueda de productos: Devuelve un listado
     de productos utilizando varios de sus atributos como filtros"""

    keys = ['text', 'units', 'min_price', 'max_price', 'longitude', 'latitude',
            'min_distance', 'max_distance', 'categories', 'payment_methods', 'seller']
    single_value_keys = ['units', 'min_price', 'max_price', 'longitude', 'latitude', 'seller',
                         'latitude', 'longitude', 'min_distance', 'max_distance']

    params = request.args.to_dict(flat=False)
    filters = dict()
    for key in keys:
        if key in params:
            if key in single_value_keys:
                filters[key] = params[key][0]
            else:
                filters[key] = params[key]
    products = ProductsService.get_products(filters)
    return jsonify(count=len(products), result=products), 200
Exemple #8
0
def test_add_answer_if_not_valid_answer_raises_validation_error(product_data, user_data):
    with pytest.raises(ValidationError):
        ProductsService.add_answer(product_data.invalid_answer, product_data.product_id,
                                   product_data.question_id, user_data.uid)
def delete_product(product_id):
    """Servicio de eliminación de un artículo"""
    uid = get_jwt_identity()
    ProductsService.delete_product(uid, product_id)
    return jsonify(result='success'), 200
Exemple #10
0
def test_add_product_if_no_product_sent_raises_validation_error(user_data):
    product_json = {}
    with pytest.raises(ValidationError):
        ProductsService.add_product(product_json, user_data.uid)
def get_product(product_id):
    """Devuelve un producto por su id"""
    product = ProductsService.get_product_by_id(product_id)
    return jsonify(product), 200
def delete_category(category_id):
    """Borra la categoría de productos especificada por su id"""
    ProductsService.delete_category(category_id)
    return jsonify(result='success'), 200
Exemple #13
0
def test_get_product_by_id_if_none_found_raises_not_found_error(pm_mock):
    pm_mock.return_value = None
    with pytest.raises(NotFoundError):
        ProductsService.get_product_by_id(15)
Exemple #14
0
def test_modify_category_if_category_name_exists_raises_data_exists_error(exists_mock, product_data):
    exists_mock.return_value = True
    with pytest.raises(DataExistsError):
        ProductsService.modify_category(product_data.category_id, product_data.valid_input_category)
def get_categories():
    """Devuelve las categorías de productos existentes"""
    categories = ProductsService.get_categories()
    return jsonify(categories), 200
Exemple #16
0
def test_delete_category_if_category_not_found_raises_not_found_error(exists_mock, product_data):
    exists_mock.return_value = False
    with pytest.raises(NotFoundError):
        ProductsService.delete_category(product_data.category_id)
Exemple #17
0
def test_add_answer_if_product_not_found_raises_not_found_error(get_by_id_mock, product_data, user_data):
    get_by_id_mock.return_value = None
    with pytest.raises(NotFoundError):
        ProductsService.add_answer(product_data.valid_answer, product_data.product_id,
                                   product_data.question_id, user_data.uid)
Exemple #18
0
def test_add_question_if_product_not_found_raises_not_found_error(find_one_and_update_mock, product_data, user_data):
    find_one_and_update_mock.return_value = None
    with pytest.raises(NotFoundError):
        ProductsService.add_question(product_data.valid_question, product_data.product_id, user_data.uid)
Exemple #19
0
def test_delete_product(_product_exists_and_belongs_to_user_mock,
                        delete_one_by_id_mock, user_data, product_data):
    _product_exists_and_belongs_to_user_mock.return_value = True
    delete_one_by_id_mock.return_value = True
    assert ProductsService.delete_product(user_data.uid, product_data.product_id)
Exemple #20
0
def test_delete_product_if_user_doesnt_own_product_raises_forbidden_error\
                (_product_exists_and_belongs_to_user_mock, user_data, product_data):
    _product_exists_and_belongs_to_user_mock.side_effect = ForbiddenError("forbidden")
    with pytest.raises(ForbiddenError):
        ProductsService.delete_product(user_data.uid, product_data.product_id)
Exemple #21
0
def test_get_products_if_none_found_raises_not_found_error(pm_mock):
    filters = dict()
    pm_mock.return_value = []
    with pytest.raises(NotFoundError):
        ProductsService.get_products(filters)
Exemple #22
0
def test_add_product_if_wrong_schema_raises_validation_error(product_data, user_data):
    with pytest.raises(ValidationError):
        ProductsService.add_product(product_data.invalid_product, user_data.uid)
Exemple #23
0
def test_modify_category_if_category_not_found_raises_not_found_error(modify_mock, exists_mock, product_data):
    exists_mock.return_value = False
    modify_mock.return_value = None
    with pytest.raises(NotFoundError):
        ProductsService.modify_category(product_data.category_id, product_data.valid_input_category)