Exemple #1
0
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")
Exemple #2
0
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_too_long_collection(json_client, db_cur):
    response = json_client.post(RESERVE_IDS_URL, {
        "amount": 1,
        "collection": "x" * (COLLECTION_MAX_LEN + 1)
    })
    assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
    assert_no_db_entry(db_cur)
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_negative_amount(json_client, db_cur):
    response = json_client.post(RESERVE_IDS_URL, {
        "amount": -1,
        "collection": "test_collection"
    })
    assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
    assert_no_db_entry(db_cur)
Exemple #6
0
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_no_json(client):
    response = client.post(RESERVE_IDS_URL,
                           data={
                               "amount": 1,
                               "collection": "test_collection"
                           })
    assert response.is_json
    assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
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_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_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_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)
Exemple #12
0
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)
Exemple #13
0
def test_list_update_invalid_key(json_client, data, redis_connection, reset_redis_data):
    data["events"].append(
        {
            "type": "update",
            "fqid": "a/1",
            "fields": {"g": 1},
            "list_fields": {"invalid": {"field": [1]}},
        }
    )
    response = json_client.post(WRITE_URL, data)
    assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
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_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)
Exemple #17
0
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_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_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_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)
Exemple #21
0
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)
Exemple #22
0
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)
Exemple #23
0
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)
Exemple #24
0
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)
Exemple #25
0
def test_empty_events(json_client, data):
    data["events"] = []
    response = json_client.post(WRITE_URL, data)
    assert_error_response(response, ERROR_CODES.INVALID_FORMAT)
Exemple #26
0
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)
Exemple #27
0
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)
Exemple #28
0
def test_missing_user_id(json_client, data):
    del data["user_id"]
    response = json_client.post(WRITE_URL, data)
    assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
Exemple #29
0
def test_no_json(client):
    response = client.post(WRITE_URL, data={"some": "data"})
    assert response.is_json
    assert_error_response(response, ERROR_CODES.INVALID_REQUEST)
Exemple #30
0
def test_wrong_format(json_client):
    response = json_client.post(WRITE_URL, ["not_valid", None])
    assert_error_response(response, ERROR_CODES.INVALID_REQUEST)