def test_get_many_with_position_deleted_no_deleted(
        reader: ReaderService, read_db: SqlReadDatabaseBackendService):
    deleted_map = {"a/1": True, "b/1": False}
    read_db.get_deleted_status = gds = MagicMock(return_value=deleted_map)
    read_db.build_models_ignore_deleted = bmid = MagicMock()
    reader.apply_mapped_fields_multi = MagicMock()

    parts = [
        GetManyRequestPart("a", "1", ["field1"]),
        GetManyRequestPart("b", "1", ["field2"]),
    ]
    request = GetManyRequest(parts, ["field"], 42)

    reader.get_many(request)

    gds.assert_called_with(["a/1", "b/1"], 42)
    bmid.assert_called_with(["b/1"], 42)
def test_get_many(reader: ReaderService,
                  read_db: SqlReadDatabaseBackendService):
    model = MagicMock()
    result = {"c/1": model}
    read_db.get_many = get_many = MagicMock(return_value=result)

    parts = [
        GetManyRequestPart("a", "1", ["field1"]),
        GetManyRequestPart("b", "1", ["field2"]),
    ]
    request = GetManyRequest(parts, ["field"])

    assert reader.get_many(request) == {"a": {}, "b": {}, "c": {1: model}}

    get_many.assert_called_with(
        ["a/1", "b/1"],
        {
            "a/1": ["field1", "field"],
            "b/1": ["field2", "field"]
        },
        DeletedModelsBehaviour.NO_DELETED,
    )
def test_get_many_with_position(reader: ReaderService,
                                read_db: SqlReadDatabaseBackendService):
    model = MagicMock()
    result = {"c/1": model}
    deleted_map = {"a/1": False, "b/1": False}
    read_db.get_deleted_status = gds = MagicMock(return_value=deleted_map)
    read_db.build_models_ignore_deleted = bmid = MagicMock(return_value=result)
    reader.apply_mapped_fields_multi = amfm = MagicMock(return_value=result)

    parts = [
        GetManyRequestPart("a", "1", ["field1"]),
        GetManyRequestPart("b", "1", ["field2"]),
    ]
    request = GetManyRequest(parts, ["field"], 42)

    assert reader.get_many(request) == {"a": {}, "b": {}, "c": {1: model}}

    gds.assert_called_with(["a/1", "b/1"], 42)
    bmid.assert_called_with(["a/1", "b/1"], 42)
    amfm.assert_called_with(result, {
        "a/1": ["field1", "field"],
        "b/1": ["field2", "field"]
    })