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
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"
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
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
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
def test_getImg(in_dict): db.addImg(in_dict) ans = db.getImg(in_dict["name"]) db.delImg(in_dict["name"]) assert ans == in_dict
def test_delImg(in_dict): db.addImg(in_dict) db.delImg(in_dict["name"]) assert not db.hasImg(in_dict["name"])
def test_addImg(in_dict): name = db.addImg(in_dict) db.delImg(name) assert name == in_dict["name"]