def test_lock_fqfield_template_same_field_locked(json_client, data): create_and_update_model(json_client, "a/1", {"f_$1": 1}, {"f_$1": 2}) data["locked_fields"]["a/1/f_$1"] = 1 response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) 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_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_lock_fqid_not_ok(json_client, data): create_and_update_model(json_client, "a/1", {"f1": 1}, {"f2": 2}) data["locked_fields"]["a/1"] = 1 response = json_client.post(WRITE_URL, data) assert_error_response(response, ERROR_CODES.MODEL_LOCKED) assert response.json["error"]["keys"] == ["a/1"] assert_no_model("a/2")
def test_single_restore(json_client, data, redis_connection, reset_redis_data): data["events"].append({"type": "delete", "fqid": "a/1"}) response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_no_model("a/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_response_code(response, 201) assert_model("a/1", {"f": 1}, 2) assert_modified_fields(redis_connection, {"a/1": ["f"]})
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_create_delete_restore_different_positions(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"} response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_no_model("a/1") assert_modified_fields(redis_connection, {"a/1": ["f"]}) reset_redis_data() data["events"][0] = {"type": "restore", "fqid": "a/1"} response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_model("a/1", {"f": 1}, 3) assert_modified_fields(redis_connection, {"a/1": ["f"]})
def test_single_delete(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"} response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_no_model("a/1") # assert the model is still in the lookup table, but marked as deleted connection_handler = injector.get(ConnectionHandler) with connection_handler.get_connection_context(): # read from read db read_db: ReadDatabase = injector.get(ReadDatabase) model = read_db.get("a/1", [], DeletedModelsBehaviour.ONLY_DELETED) assert model == {"f": 1, "meta_deleted": True, "meta_position": 2} assert read_db.is_deleted("a/1") assert_modified_fields(redis_connection, {"a/1": ["f"]})
def test_create_delete(json_client, data, redis_connection, reset_redis_data): data["events"].append({"type": "delete", "fqid": "a/1"}) response = json_client.post(WRITE_URL, data) assert_response_code(response, 201) assert_no_model("a/1") assert_modified_fields(redis_connection, {"a/1": ["f"]})