コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
def test_create_twice(json_client, data, db_cur, redis_connection):
    data["events"].append(data["events"][0])
    response = json_client.post(WRITE_URL, data)
    assert_error_response(response, ERROR_CODES.MODEL_EXISTS)
    assert_no_db_entry(db_cur)
    assert_no_modified_fields(redis_connection)