Skip to content

Commit 870be8f

Browse files
committed
REST: Add integration test for views
1 parent 2be1827 commit 870be8f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,11 @@ def clean_up(test_catalog: Catalog) -> None:
25102510
if "my_iceberg_database-" in database_name:
25112511
for identifier in test_catalog.list_tables(database_name):
25122512
test_catalog.drop_table(identifier)
2513+
try:
2514+
for identifier in test_catalog.list_views(database_name):
2515+
test_catalog.drop_view(identifier)
2516+
except NotImplementedError:
2517+
pass
25132518
test_catalog.drop_namespace(database_name)
25142519

25152520

tests/integration/test_catalog.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import uuid
2020
from collections.abc import Generator
2121
from pathlib import Path, PosixPath
22+
from typing import Any
2223

2324
import pytest
2425
from pytest_lazy_fixtures import lf
@@ -44,6 +45,8 @@
4445
from pyiceberg.table.sorting import INITIAL_SORT_ORDER_ID, SortField, SortOrder
4546
from pyiceberg.transforms import BucketTransform, DayTransform, IdentityTransform
4647
from pyiceberg.types import IntegerType, LongType, NestedField, TimestampType, UUIDType
48+
from pyiceberg.view import View
49+
from pyiceberg.view.metadata import ViewMetadata
4750
from tests.conftest import (
4851
clean_up,
4952
does_support_atomic_concurrent_updates,
@@ -617,6 +620,55 @@ def test_register_table_existing(test_catalog: Catalog, table_schema_nested: Sch
617620
test_catalog.register_table(identifier, metadata_location=table.metadata_location)
618621

619622

623+
@pytest.mark.integration
624+
def test_rest_list_views(
625+
rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str
626+
) -> None:
627+
identifier = (database_name, view_name)
628+
629+
rest_catalog.create_namespace_if_not_exists(database_name)
630+
view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1))
631+
632+
assert identifier not in rest_catalog.list_views(database_name)
633+
634+
rest_catalog.create_view(identifier, view.schema(), view.current_version())
635+
636+
assert identifier in rest_catalog.list_views(database_name)
637+
638+
639+
@pytest.mark.integration
640+
def test_rest_create_view(
641+
rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str
642+
) -> None:
643+
identifier = (database_name, view_name)
644+
645+
rest_catalog.create_namespace_if_not_exists(database_name)
646+
view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1))
647+
648+
assert not rest_catalog.view_exists(identifier)
649+
650+
rest_catalog.create_view(identifier, view.schema(), view.current_version())
651+
652+
assert rest_catalog.view_exists(identifier)
653+
assert rest_catalog.load_view(identifier).schema() == view.schema()
654+
655+
656+
@pytest.mark.integration
657+
def test_rest_drop_view(
658+
rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str
659+
) -> None:
660+
identifier = (database_name, view_name)
661+
662+
rest_catalog.create_namespace_if_not_exists(database_name)
663+
view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1))
664+
665+
rest_catalog.create_view(identifier, view.schema(), view.current_version())
666+
assert rest_catalog.view_exists(identifier)
667+
668+
rest_catalog.drop_view(identifier)
669+
assert not rest_catalog.view_exists(identifier)
670+
671+
620672
@pytest.mark.integration
621673
@pytest.mark.skip(reason="Requires Iceberg REST Fixtures 1.11.x")
622674
def test_rest_custom_namespace_separator(rest_catalog: RestCatalog, table_schema_simple: Schema) -> None:

0 commit comments

Comments
 (0)