def test_create_delete_restore(json_client, data, redis_connection):
    data["events"].append({"type": "delete", "fqid": "a/1"})
    data["events"].append({"type": "restore", "fqid": "a/1"})
    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"]})
Exemplo n.º 2
0
def test_lock_collectionfield_with_and_filter(json_client, data):
    create_and_update_model(json_client, "a/1", {
        "f1": 1,
        "f3": False
    }, {"f2": 2})
    data["locked_fields"]["a/f1"] = {
        "position": 1,
        "filter": {
            "and_filter": [
                {
                    "field": "f1",
                    "operator": "=",
                    "value": 1,
                },
                {
                    "field": "f3",
                    "operator": "=",
                    "value": False,
                },
            ],
        },
    }
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/2", {}, 3)
Exemplo n.º 3
0
def test_lock_fqfield_ok_2(json_client, data):
    create_and_update_model(json_client, "a/1", {"f1": 1}, {"f2": 2})
    data["locked_fields"]["a/1/f2"] = 2

    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/2", {}, 3)
def test_update_delete_restore_update(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": {
            "another": "value",
            "f": None
        },
    }
    data["events"].append({"type": "delete", "fqid": "a/1"})
    data["events"].append({"type": "restore", "fqid": "a/1"})
    data["events"].append({
        "type": "update",
        "fqid": "a/1",
        "fields": {
            "third_field": ["my", "list"]
        }
    })
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {"another": "value", "third_field": ["my", "list"]}, 2)
    assert_modified_fields(redis_connection,
                           {"a/1": ["f", "another", "third_field"]})
Exemplo n.º 5
0
def test_lock_fqfield_template_other_field_locked_3(json_client, data):
    create_and_update_model(json_client, "a/1", {"f_$11": 1}, {"f_$11": 2})
    data["locked_fields"]["a/1/f_$1"] = 1

    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/2", {}, 3)
def create_model(json_client, data, redis_connection, reset_redis_data):
    fields = copy.deepcopy(data["events"][0]["fields"])
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", fields, 1)
    assert_modified_fields(redis_connection, {"a/1": list(fields.keys())})
    reset_redis_data()
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_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_create_update(json_client, data, redis_connection):
    field_data = [True, None, {"test": "value"}]
    data["events"].append({
        "type": "update",
        "fqid": "a/1",
        "fields": {
            "f": None,
            "another_field": field_data
        },
    })
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {"another_field": field_data}, 1)
    assert_modified_fields(redis_connection, {"a/1": ["f", "another_field"]})
def test_list_update_with_create(json_client, data, redis_connection,
                                 reset_redis_data):
    data["events"].append({
        "type": "update",
        "fqid": "a/1",
        "list_fields": {
            "add": {
                "g": [2]
            }
        },
    })
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {"f": 1, "g": [2]}, 1)
    assert_modified_fields(redis_connection, {"a/1": ["f", "g"]})
def test_write_none(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
        }
    }
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {}, 2)
    assert_modified_fields(redis_connection, {"a/1": ["f"]},
                           meta_deleted=False)
Exemplo n.º 12
0
def test_lock_collectionfield_prefix_not_locked(json_client, data):
    create_and_update_model(json_client, "a_suf/1", {"f1": 1}, {
        "f1": 2,
        "f2": 2
    })
    data["locked_fields"]["a/f1"] = {
        "position": 1,
        "filter": {
            "field": "f1",
            "operator": "=",
            "value": 2,
        },
    }

    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/2", {}, 3)
def test_single_update(json_client, data, redis_connection, reset_redis_data):
    create_model(json_client, data, redis_connection, reset_redis_data)

    field_data = [True, None, {"test": "value"}]
    data["events"][0] = {
        "type": "update",
        "fqid": "a/1",
        "fields": {
            "f": None,
            "another_field": field_data
        },
    }
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {"another_field": field_data}, 2)
    assert_modified_fields(redis_connection, {"a/1": ["f", "another_field"]},
                           meta_deleted=False)
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_two_write_requests(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}}
    response = json_client.post(WRITE_URL, [data, data2])
    assert_response_code(response, 201)
    assert_model("a/1", {"f2": 1}, 3)
    assert_modified_fields(redis_connection, {"a/1": ["f", "f2"]},
                           meta_deleted=False)
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_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_list_update_remove_empty_1(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": {
                "field": [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": ["field"]},
                           meta_deleted=False)
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_add_duplicate(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, 2]
            }
        },
    }
    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/1", {"f": [1, 2]}, 2)
    assert_modified_fields(redis_connection, {"a/1": ["f"]},
                           meta_deleted=False)
def test_create_empty_field(json_client, data, redis_connection):
    data["events"][0]["fields"]["empty"] = None
    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"]})
Exemplo n.º 22
0
def test_lock_not_existing_fqid(json_client, data):
    data["locked_fields"]["b/2"] = 1

    response = json_client.post(WRITE_URL, data)
    assert_response_code(response, 201)
    assert_model("a/2", {}, 1)