def test_lock_fqfield_template_two_placeholders(json_client, data): create_and_update_model(json_client, "a/1", {"f_1_2_s": 1}, {"f_1_2_s": 2}) data["locked_fields"]["a/1/f_$_$_s"] = 1 response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT) assert_no_model("a/2")
def test_delete_model_does_not_exist(json_client, data, redis_connection, reset_redis_data): data["events"][0] = {"type": "delete", "fqid": "a/1"} response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST) assert_no_model("a/1") assert_no_modified_fields(redis_connection)
def test_lock_fqfield_not_ok(json_client, data): create_and_update_model(json_client, "a/1", {"f1": 1}, {"f2": 2}) data["locked_fields"]["a/1/f2"] = 1 response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) assert_no_model("a/2")
def test_lock_fqfield_template_same_field_with_suffix_locked( json_client, data): create_and_update_model(json_client, "a/1", {"f_$1_s": 1}, {"f_$1_s": 2}) data["locked_fields"]["a/1/f_$1_s"] = 1 response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) assert_no_model("a/2")
def test_get_all_models_no_model(json_client, db_connection, db_cur): response = json_client.post( Route.GET.URL, { "fqid": FQID, "get_deleted_models": DeletedModelsBehaviour.ALL_MODELS }, ) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST)
def test_position_deleted(json_client, db_connection, db_cur): setup_events_data(db_connection, db_cur) db_cur.execute( "insert into events (position, fqid, type) values (3, %s, %s)", [FQID, EVENT_TYPES.DELETE], ) db_connection.commit() response = json_client.post(Route.GET.URL, {"fqid": FQID, "position": 3}) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST)
def test_update_no_fields(json_client, data, redis_connection, reset_redis_data): data["events"].append({ "type": "update", "fqid": "a/1", "fields": {}, "list_fields": {}, }) response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_get_only_deleted_fail(json_client, db_connection, db_cur): setup_data(db_connection, db_cur, {FQID: data}) response = json_client.post( Route.GET.URL, { "fqid": FQID, "get_deleted_models": DeletedModelsBehaviour.ONLY_DELETED }, ) assert_error_response(response, ERROR_CODES.MODEL_NOT_DELETED)
def test_get_no_deleted_fail(json_client, db_connection, db_cur): setup_data(db_connection, db_cur, True) response = json_client.post( Route.GET.URL, { "fqid": FQID, "get_deleted_models": DeletedModelsBehaviour.NO_DELETED }, ) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST)
def test_position_not_deleted(json_client, db_connection, db_cur): setup_events_data(db_connection, db_cur) response = json_client.post( Route.GET.URL, { "fqid": FQID, "position": 1, "get_deleted_models": DeletedModelsBehaviour.ONLY_DELETED, }, ) assert_error_response(response, ERROR_CODES.MODEL_NOT_DELETED)
def test_restore_without_delete(json_client, data, redis_connection, reset_redis_data): response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_model("a/1", {"f": 1}, 1) assert_modified_fields(redis_connection, {"a/1": ["f"]}) reset_redis_data() data["events"] = [{"type": "restore", "fqid": "a/1"}] response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_NOT_DELETED) assert_model("a/1", {"f": 1}, 1) assert_no_modified_fields(redis_connection)
def test_update_non_existing_2(json_client, data, db_cur, redis_connection): data["events"][0] = { "type": "update", "fqid": "a/1", "fields": { "f": None } } response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST) assert_no_db_entry(db_cur) assert_no_modified_fields(redis_connection)
def test_delete_update(json_client, data, redis_connection, reset_redis_data): create_model(json_client, data, redis_connection, reset_redis_data) data["events"][0] = {"type": "delete", "fqid": "a/1"} data["events"].append( { "type": "update", "fqid": "a/1", "fields": {"f": 42}, } ) response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST)
def test_two_write_requests_with_locked_fields( json_client, data, redis_connection, reset_redis_data ): create_model(json_client, data, redis_connection, reset_redis_data) data["events"][0] = {"type": "update", "fqid": "a/1", "fields": {"f": None}} data2 = copy.deepcopy(data) data2["events"][0] = {"type": "update", "fqid": "a/1", "fields": {"f2": 1}} data2["locked_fields"] = {"a/1/f": 1} response = json_client.post(WRITE_URL, [data, data2]) assert_model("a/1", {"f": 1}, 1) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) assert_no_modified_fields(redis_connection)
def test_list_update_remove_no_array( json_client, data, redis_connection, reset_redis_data ): create_model(json_client, data, redis_connection, reset_redis_data) data["events"][0] = { "type": "update", "fqid": "a/1", "list_fields": {"remove": {"f": [1]}}, } response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT) assert_model("a/1", {"f": 1}, 1) assert_no_modified_fields(redis_connection)
def test_lock_collectionfield_with_filter_not_ok(json_client, data): create_and_update_model(json_client, "a/1", {"f1": 1}, {"f2": 2}) data["locked_fields"]["a/f2"] = { "position": 1, "filter": { "field": "f1", "operator": "=", "value": 1, }, } response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) assert_no_model("a/2")
def test_list_update_add_invalid_entry( json_client, data, redis_connection, reset_redis_data ): data["events"][0]["fields"]["f"] = [[1]] create_model(json_client, data, redis_connection, reset_redis_data) data["events"][0] = { "type": "update", "fqid": "a/1", "list_fields": {"add": {"f": [1]}}, } response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT) assert_model("a/1", {"f": [[1]]}, 1) assert_no_modified_fields(redis_connection)
def test_update_list_update_duplicate_field(json_client, data): data["events"].append({ "type": "update", "fqid": "a/1", "fields": { "f": [2] }, "list_fields": { "add": { "f": [3] } }, }) response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_no_model(json_client, db_connection, db_cur): response = json_client.post(Route.GET.URL, {"fqid": FQID}) assert_error_response(response, ERROR_CODES.MODEL_DOES_NOT_EXIST)
def test_invalid_mapped_fields(json_client): response = json_client.post(Route.GET.URL, { "fqid": FQID, "mapped_fields": ["not valid"] }) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_create_invalid_fqid(json_client, data): data["events"][0]["fqid"] = "not valid" response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_empty_events(json_client, data): data["events"] = [] response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_missing_locked_fields(json_client, data): del data["locked_fields"] response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_missing_information(json_client, data): del data["information"] response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_invalid_fqid(json_client): response = json_client.post(Route.GET.URL, {"fqid": "not valid"}) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_create_missing_fields(json_client, data): del data["events"][0]["fields"] response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_invalid_position(json_client): response = json_client.post(Route.GET.URL, {"fqid": FQID, "position": 0}) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_create_invalid_field(json_client, data): data["events"][0]["fields"] = {META_FIELD_PREFIX: "value"} response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
def test_unknwon_event(json_client, data): data["events"][0]["type"] = "unknown" response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
def test_update_empty_fields(json_client, data): data["events"][0]["fields"] = {} data["events"][0]["type"] = "update" response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.INVALID_FORMAT)