def test_error_for_invalid_sku():
    item = model.CartItem("i1", "NONEXISTENTSKU", 10)
    product = model.Product("p1", "AREALSKU", 100,  100, 'A REAL SKU' , 100)
    repo = FakeRepository([product])

    with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"):
        services.add(item, repo, FakeSession())
def test_commits():
    item = model.CartItem("i1", "CHAKRI ATTA", 10)
    product = model.Product("p1", "CHAKRI ATTA", 100,  100, 'CHAKRI ATTA' , 16)
    repo = FakeRepository([product])
    session = FakeSession()

    services.add(item, repo, session)
    assert session.committed is True
Esempio n. 3
0
def new_message():
    data = request.get_json()

    # check for errors in payload
    errors = check_payload(data, ["sender", "msg", "timestamp"])
    if len(errors) > 0:
        return {"errors": errors}, 400

    # parse message, format args, and check for errors in service and arguments
    msg = data["msg"]
    service, arguments, errors = parse_service_and_args_from(
        msg, services_dict)
    if len(errors) > 0:
        return {"errors": errors}, 400

    # perform service
    if service == "help":
        return {"msg": help()}
    elif service == "add":
        return {"msg": add(arguments[0], arguments[1])}
    elif service == "subtract":
        return {"msg": subtract(arguments[0], arguments[1])}
    elif service == "multiply":
        return {"msg": multiply(arguments[0], arguments[1])}
    elif service == "divide":
        return {"msg": divide(arguments[0], arguments[1])}
    elif service == "search":
        return {"msg": search(arguments[0])}
    else:
        return {"msg": "Sorry, I don't know how to do that."}
def test_returns_item():
    item = model.CartItem("i1", "CHAKRI ATTA", 10)
    product = model.Product("p1", "CHAKRI ATTA", 100,  100, 'CHAKRI ATTA' , 16)
    repo = FakeRepository([product])

    result = services.add(item, repo, FakeSession())
    assert result == "p1"
Esempio n. 5
0
def add_wrapper():
    data = request.get_json()
    errors = check_payload(data, ["num0", "num1"])
    if len(errors) > 0:
        return {"errors": errors}, 400
    a = float(data['num0'])
    b = float(data['num1'])
    numsum = add(a, b)
    return {"value": numsum}
Esempio n. 6
0
def add_bookmark():
    session = get_session()
    repo = repository.SqlAlchemyRepository(session)
    content = request.get_json()
    date_added = datetime.now(timezone.utc)
    id = str(uuid.uuid4())

    bookmark = model.Bookmark(id, request.json["title"], request.json["url"],
                              request.json["notes"], date_added)

    bookmarkref = services.add(bookmark, repo, session)
    return jsonify({'message': 'Barky App'})
Esempio n. 7
0
def add_endpoint():
    session = get_session()
    repo = repository.SqlAlchemyRepository(session)
    item = model.CartItem(
        request.json["itemid"],
        request.json["sku"],
        request.json["qty"],
    )

    try:
        productref = services.add(item, repo, session)
    except (model.OutOfStock, services.InvalidSku) as e:
        return {"message": str(e)}, 400

    return {"productref": productref}, 201
Esempio n. 8
0
def add_services():
    print 'inside function add_services'
    services.add()