def test_create(): entry = CustomEntry.CustomEntry() custom_entry_id = entry.create(TEST_ENTRY_DATA["user_id"], TEST_ENTRY_DATA)["custom_entry_id"] TEST_ENTRY_DATA["custom_entry_id"] = custom_entry_id TEST_ENTRY_DATA["custom_entry_id"] = custom_entry_id res = entry.create(TEST_ENTRY_DATA["user_id"], TEST_ENTRY_DATA) TEST_ENTRY_DATA.update({"custom_entry_id": res["custom_entry_id"]}) assert res is not None
def test_update_protected_fields(): entry = CustomEntry.CustomEntry() copy = dict(TEST_ENTRY_DATA) copy.update({ "user_id": "test", "custom_entry_id": "test", "custom_id": "test" }) res = entry.update(copy) assert res is None
def test_update(): entry = CustomEntry.CustomEntry() copy = dict(TEST_ENTRY_DATA) copy.update({ "timestamp": int(time.time()), "day": datetime.datetime.today().day, "month": datetime.datetime.today().month, "year": datetime.datetime.today().year, "notes": "Update" }) res = entry.update(copy) assert res is not None
def test_update_invalid_data_types(): entry = CustomEntry.CustomEntry() copy = dict(TEST_ENTRY_DATA) copy.update({ "timestamp": "test", "day": "test", "month": "test", "year": "test", "notes": 123 }) print(copy) res = entry.update(copy) assert res is None
def call_api(func_name): try: if func_name not in ENDPOINTS: message = "No such endpoint " + "'" + func_name + "'" return make_response({"message": message}, 404) model = CustomEntry.CustomEntry() # GET requests have no request bodies, so we must get data from the header if func_name == "get": user_id = request.headers.get("user_id") token = request.headers.get("token") return CONTROLLER.execute_model_logic(token, user_id, model, "get", dict(user_id=user_id)) request_body = request.get_json() params = CONTROLLER.deconstruct_request_body(request_body, model, func_name) params.update({"model": model, "function_name": func_name}) return CONTROLLER.execute_model_logic(**params) except Exception as e: return make_response({"message": "Internal Error: " + str(e)}, 500)
def test_delete(): entry = CustomEntry.CustomEntry() entry.delete(TEST_ENTRY_DATA["user_id"], TEST_ENTRY_DATA["custom_entry_id"]) assert entry.get_one(TEST_ENTRY_DATA["custom_entry_id"]) is None
def test_get_many(): entry = CustomEntry.CustomEntry() res = entry.get(TEST_ENTRY_DATA["user_id"]) assert res is not None and isinstance(res, list)
def test_get_one(): entry = CustomEntry.CustomEntry() res = entry.get_one(TEST_ENTRY_DATA["custom_entry_id"]) assert res is not None and res == TEST_ENTRY_DATA
def test_instantiation(): entry = CustomEntry.CustomEntry() assert entry is not None