Exemplo n.º 1
0
def test_hasImg(img_name, expt):
    db.addImg(in_dict1)
    db.addImg(in_dict2)
    ans = db.hasImg(img_name)
    db.delImg(img_name1)
    db.delImg(img_name2)
    assert ans == expt
Exemplo n.º 2
0
def processImg(img_name):
    """Invert the image and add the image to database.

    Args:
        img_name (str): Name of the image.
    """
    in_dict = db.getImg(img_name)
    inv_b64_str = transimg.invertImg(in_dict["b64str"])
    fname = img_name.split(".")[0] + "_proecessed" + ".jpg"
    inv_in_dict = transimg.makeDict(fname, inv_b64_str, in_dict["imgsize"],
                                    True)
    db.addImg(inv_in_dict)
    return "Success: process the image"
Exemplo n.º 3
0
def postImg():
    """Post request from server to add image to database.

    returns:
        (tuple): tuple containing:
        str: Status message.
        str: Status code.
    """
    sample_dict = {
        "name": str,
        "b64str": str,
        "imgsize": str,
        "processed": bool,
        "timestamp": str
    }
    in_dict = request.get_json()
    isValid, msg = verifyInfo(in_dict, sample_dict)
    if not isValid:
        return msg, 400
    logging.info("post a new image: {}".format(in_dict["name"]))
    db.addImg(in_dict)
    return "image added", 200
Exemplo n.º 4
0
def test_getSelectedNames(processed, expt):
    db.addImg(in_dict1)
    db.addImg(in_dict2)
    db.addImg(in_dict3)
    ans = db.getSelectedNames(processed)
    db.delImg(img_name1)
    db.delImg(img_name2)
    db.delImg(img_name3)
    assert ans == expt
Exemplo n.º 5
0
def test_getNames():
    db.addImg(in_dict1)
    db.addImg(in_dict2)
    db.addImg(in_dict3)
    ans = db.getNames()
    expt = [img_name1, img_name2, img_name3]
    db.delImg(img_name1)
    db.delImg(img_name2)
    db.delImg(img_name3)
    assert ans == expt
Exemplo n.º 6
0
def test_getImg(in_dict):
    db.addImg(in_dict)
    ans = db.getImg(in_dict["name"])
    db.delImg(in_dict["name"])
    assert ans == in_dict
Exemplo n.º 7
0
def test_delImg(in_dict):
    db.addImg(in_dict)
    db.delImg(in_dict["name"])
    assert not db.hasImg(in_dict["name"])
Exemplo n.º 8
0
def test_addImg(in_dict):
    name = db.addImg(in_dict)
    db.delImg(name)
    assert name == in_dict["name"]