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LZN3R0hY3w88YOI2ljsbT-eN_oegRlZBKDoVQdN76pivHV25gfxVY_cZyt04zxXs4_MZKA4Mq0pCgRaLS-ZCEtWn4Vgu8bpFg80g30aseIEi2OQtBlAymHRC07_YLCQ6iP6IQfDgiK7oxVgk3GEvvDx7l3FrAf0btM5B3kDmuQPdiUL6oLspIsPJOowtuntgS7KXWIKSMOqnFMqOhQncTE4TkAfpl8acmIwQ5rw1zUPbNpbIxHiCA"
    try:
        id = idForToken(MockRequest({"token": TOKEN}, {}))
        assert len(id) > 0
    except HTTPException:
        assert False

    try:
        id = idForToken(MockRequest(None,
                                    {"Authorization": "Bearer " + TOKEN}))
        assert len(id) > 0
    except HTTPException:
        assert False
Пример #2
0
def update_item():
    user = idForToken(request) 
    item = TrackingItem.fromDict(request.json, TrackingItem.isValidUpdate)
    if item is None:
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.updateItem, item, user)
Пример #3
0
def dashboard_similar():
    user = idForToken(request) 
    if "itemId" not in request.args:
        abort(422)

    itemId = request.args["itemId"]
    if not str.isdigit(itemId) or int(itemId) <= 0:
        abort(422) 

    itemId = int(itemId)

    items = runQuery(TrackingItemDAL.similarItems, user, itemId)
    
    respData = {"items": []} 
    for item in items:
        respData["items"].append(item.toDict())

    try:
        itemUrl = runQuery(TrackingItemDAL.urlForItemId, itemId)
        if itemUrl is not None:
            #TODO do you need to add an https prefix or anything? depends on what front end puts in
            scrapedItems = related_item_scraper(itemUrl)
            for item in scrapedItems:
                item.referrerItemId = itemId
                respData["items"].append(item.toDict())

    except Exception as e:
        print(e)

    return jsonify(respData)
Пример #4
0
def register_item():
    user = idForToken(request) 
    item = TrackingItem.fromDict(request.json, TrackingItem.isValidInsert)
    if item is None:
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.createItem, item, user)
Пример #5
0
def register_similar():
    user = idForToken(request) 
    item = SimilarItem.fromDict(request.json)
    if item is None:
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.registerSimilar, item)
Пример #6
0
def user_get_prime():
    user = idForToken(request) 
    isPrime = runQuery(TrackingItemDAL.isUserPrime, user)
    
    if isPrime is None:
        abort(422)

    return jsonify({"isPrime": isPrime})
Пример #7
0
def dashboard_items():
    user = idForToken(request)
    items = runQuery(TrackingItemDAL.userItems, user)

    respData = {"items": []} 
    for item in items:
        respData["items"].append(item.toDict())

    return jsonify(respData)
Пример #8
0
def delete_item():
    user = idForToken(request) 
    if request.json is None or "id" not in request.json:
        abort(422)
    id = request.json["id"]

    if not isinstance(id, int) or id <= 0:
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.deleteItem, id, user)
Пример #9
0
def user_set_prime():
    user = idForToken(request) 
    if request.json is None or "isPrime" not in request.json:
        abort(422)
    isPrime = request.json["isPrime"]

    if not isinstance(isPrime, bool):
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.updateUserPrime, user, isPrime)
Пример #10
0
def hide_similar():
    user = idForToken(request) 
    if request.json is None or "id" not in request.json:
        abort(422)
    id = request.json["id"]

    if not isinstance(id, int) or id <= 0:
        abort(422)
    
    return makeSuccessResponse(TrackingItemDAL.hideSimilar, id, user)
Пример #11
0
def update_sort_order():
    user = idForToken(request) 
    if request.json is None or "itemIds" not in request.json:
        abort(422)
    itemIds = request.json["itemIds"]

    for id in itemIds:
        if not isinstance(id, int) or id <= 0:
            abort(422) 

    return makeSuccessResponse(TrackingItemDAL.updateSortOrder, user, itemIds)
Пример #12
0
def notification_items():
    user = idForToken(request) 
    items = runQuery(TrackingItemDAL.notificationItems, user)
    
    if items is None:
        abort(422)
    
    itemList = []
    for item in items:
        itemDict = {
            "id": item.id,
            "priceThreshold": str(item.priceThreshold),
            "timeThreshold": item.timeThreshold.isoformat(),
            "url": item.url,
            "imgUrl": item.imgUrl,
            "title":item.title
        } 
        itemList.append(itemDict)

    return jsonify({"items": itemList})
Пример #13
0
def test_invalid_token(api):
    try:
        idForToken(MockRequest({"token": "hello"}, {}))
        assert False
    except HTTPException as e:
        assert e.get_response().status_code == 403
Пример #14
0
def test_no_token(api):
    try:
        idForToken(MockRequest({"id": 1}, {}))
    except HTTPException as e:
        assert e.get_response().status_code == 403
Пример #15
0
def test_no_json(api):
    try:
        idForToken(MockRequest(None, {}))
    except HTTPException as e:
        assert e.get_response().status_code == 422