|
18 | 18 | from unittest.mock import MagicMock |
19 | 19 |
|
20 | 20 | import pytest |
21 | | -from google.api_core.exceptions import NotFound |
| 21 | +from google.api_core.exceptions import Conflict, NotFound |
22 | 22 | from google.cloud.bigquery import Dataset, DatasetReference, Table, TableReference |
23 | 23 | from google.cloud.bigquery.external_config import ExternalCatalogDatasetOptions, ExternalCatalogTableOptions |
24 | 24 | from pytest_mock import MockFixture |
25 | 25 |
|
26 | 26 | from pyiceberg.catalog.bigquery_metastore import ICEBERG_TABLE_TYPE_VALUE, TABLE_TYPE_PROP, BigQueryMetastoreCatalog |
27 | | -from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchTableError |
| 27 | +from pyiceberg.exceptions import NamespaceAlreadyExistsError, NoSuchNamespaceError, NoSuchTableError |
28 | 28 | from pyiceberg.schema import Schema |
29 | 29 |
|
30 | 30 |
|
@@ -124,6 +124,19 @@ def test_drop_namespace(mocker: MockFixture, gcp_dataset_name: str) -> None: |
124 | 124 | assert args[0].dataset_id == gcp_dataset_name |
125 | 125 |
|
126 | 126 |
|
| 127 | +def test_create_namespace_already_exists(mocker: MockFixture, gcp_dataset_name: str) -> None: |
| 128 | + client_mock = MagicMock() |
| 129 | + client_mock.create_dataset.side_effect = Conflict("Already Exists") |
| 130 | + mocker.patch("pyiceberg.catalog.bigquery_metastore.Client", return_value=client_mock) |
| 131 | + mocker.patch.dict(os.environ, values={"PYICEBERG_LEGACY_CURRENT_SNAPSHOT_ID": "True"}) |
| 132 | + catalog = BigQueryMetastoreCatalog( |
| 133 | + "test_catalog", **{"gcp.bigquery.project-id": "my-project", "warehouse": "gs://test-bucket/warehouse"} |
| 134 | + ) |
| 135 | + |
| 136 | + with pytest.raises(NamespaceAlreadyExistsError, match=f"^Namespace {gcp_dataset_name} already exists$"): |
| 137 | + catalog.create_namespace(gcp_dataset_name) |
| 138 | + |
| 139 | + |
127 | 140 | def test_list_tables(mocker: MockFixture, gcp_dataset_name: str) -> None: |
128 | 141 | client_mock = MagicMock() |
129 | 142 |
|
|
0 commit comments