|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +# pylint:disable=redefined-outer-name |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | +from pyiceberg.catalog.rest import RestCatalog |
| 22 | + |
| 23 | +TEST_NAMESPACE_IDENTIFIER = "TEST NS" |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.integration |
| 27 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 28 | +def test_namespace_exists(catalog: RestCatalog) -> None: |
| 29 | + if not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 30 | + catalog.create_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 31 | + |
| 32 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.integration |
| 36 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 37 | +def test_namespace_not_exists(catalog: RestCatalog) -> None: |
| 38 | + if catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 39 | + catalog.drop_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 40 | + |
| 41 | + assert not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.integration |
| 45 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 46 | +def test_create_namespace_if_not_exists(catalog: RestCatalog) -> None: |
| 47 | + if catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 48 | + catalog.drop_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 49 | + |
| 50 | + catalog.create_namespace_if_not_exists(TEST_NAMESPACE_IDENTIFIER) |
| 51 | + |
| 52 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.integration |
| 56 | +@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")]) |
| 57 | +def test_create_namespace_if_already_existing(catalog: RestCatalog) -> None: |
| 58 | + if not catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER): |
| 59 | + catalog.create_namespace(TEST_NAMESPACE_IDENTIFIER) |
| 60 | + |
| 61 | + catalog.create_namespace_if_not_exists(TEST_NAMESPACE_IDENTIFIER) |
| 62 | + |
| 63 | + assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER) |
0 commit comments