|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pyiceberg.catalog.rest import RestCatalog |
| 4 | + |
| 5 | +TEST_NAMESPACE_IDENTIFIER = "TEST NS" |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.integration |
| 9 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 10 | +def test_namespace_exists(catalog: RestCatalog) -> None: |
| 11 | + if not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 12 | + catalog.create_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 13 | + |
| 14 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.integration |
| 18 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 19 | +def test_namespace_not_exists(catalog: RestCatalog) -> None: |
| 20 | + if catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 21 | + catalog.drop_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 22 | + |
| 23 | + assert not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.integration |
| 27 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 28 | +def test_create_namespace_if_not_exists(catalog: RestCatalog) -> None: |
| 29 | + if catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 30 | + catalog.drop_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 31 | + |
| 32 | + catalog.create_namespace_if_not_exists(TEST_NAMESPACE_IDENTIFIER) |
| 33 | + |
| 34 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.integration |
| 38 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 39 | +def test_create_namespace_if_already_existing(catalog: RestCatalog) -> None: |
| 40 | + if not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 41 | + catalog.create_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 42 | + |
| 43 | + catalog.create_namespace_if_not_exists(TEST_NAMESPACE_IDENTIFIER) |
| 44 | + |
| 45 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
0 commit comments