Skip to content

Commit e7a8c15

Browse files
authored
Fix tests (#4)
1 parent d78883d commit e7a8c15

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

crates/control_plane/src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl Warehouse {
185185
let location = format!("{prefix}/{id}");
186186
let now = Utc::now().naive_utc();
187187
Ok(Self {
188-
id: Uuid::new_v4(),
188+
id,
189189
prefix,
190190
name,
191191
location,

crates/nexus/src/http/catalog/router.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use axum::Router;
44

55
use crate::http::catalog::handlers::{
66
commit_table, create_namespace, create_table, delete_namespace, delete_table, get_config,
7-
get_namespace, get_table, list_namespaces,
7+
get_namespace, get_table, list_namespaces, list_tables,
88
};
99

1010
pub fn create_router() -> Router<AppState> {
1111
let table_router: Router<AppState> = Router::new()
1212
.route("/", post(create_table))
13+
.route("/", get(list_tables))
1314
.route("/:table", get(get_table))
1415
.route("/:table", delete(delete_table))
1516
.route("/:table", post(commit_table));

tests/conftest.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
S3_PATH_STYLE_ACCESS = os.environ.get("S3_PATH_STYLE_ACCESS")
2323

2424

25+
@dataclasses.dataclass
26+
class Namespace:
27+
name: [str]
28+
properties: dict
29+
warehouse_id: str
30+
31+
2532
@dataclasses.dataclass
2633
class Server:
2734
catalog_url: str
@@ -39,12 +46,24 @@ def create_storage_profile(self, **payload) -> dict:
3946
assert response.ok, response.text
4047
return response.json()
4148

49+
def delete_storage_profile(self, storage_profile: dict) -> None:
50+
sid = storage_profile.get("id", None)
51+
assert sid
52+
storage_profile_url = urllib.parse.urljoin(
53+
self.management_url, f"v1/storage-profile/{sid}"
54+
)
55+
response = requests.delete(
56+
storage_profile_url,
57+
json=storage_profile,
58+
)
59+
assert response.ok, response.text
60+
4261
def create_warehouse(
4362
self,
4463
**payload,
4564
) -> uuid.UUID:
4665
"""Create a warehouse in this server"""
47-
warehouse_url = self.warehouse_url
66+
warehouse_url = urllib.parse.urljoin(self.management_url, "v1/warehouse")
4867
payload = {k.replace("_", "-"): v for k, v in payload.items()}
4968
response = requests.post(
5069
warehouse_url,
@@ -53,9 +72,15 @@ def create_warehouse(
5372
assert response.ok, response.text
5473
return response.json()
5574

56-
@property
57-
def warehouse_url(self) -> str:
58-
return urllib.parse.urljoin(self.management_url, "v1/warehouse")
75+
def delete_warehouse(self, warehouse: dict) -> None:
76+
wid = warehouse.get("id", None)
77+
assert wid
78+
warehouse_url = urllib.parse.urljoin(self.management_url, f"v1/warehouse/{wid}")
79+
response = requests.delete(
80+
warehouse_url,
81+
json=warehouse,
82+
)
83+
assert response.ok, response.text
5984

6085

6186
@pytest.fixture(scope="session")
@@ -73,7 +98,7 @@ def server() -> Server:
7398

7499
@pytest.fixture(scope="session")
75100
def storage_profile(server: Server) -> dict:
76-
return server.create_storage_profile(
101+
data = server.create_storage_profile(
77102
type="aws",
78103
region=S3_REGION,
79104
bucket=S3_BUCKET,
@@ -86,6 +111,9 @@ def storage_profile(server: Server) -> dict:
86111
endpoint=S3_ENDPOINT,
87112
)
88113

114+
yield data
115+
server.delete_storage_profile(data)
116+
89117

90118
@pytest.fixture(scope="session")
91119
def warehouse(server: Server, storage_profile) -> dict:
@@ -96,14 +124,19 @@ def warehouse(server: Server, storage_profile) -> dict:
96124
prefix=preix,
97125
storage_profile_id=storage_profile.get("id", None),
98126
)
99-
return wh
127+
yield wh
128+
server.delete_warehouse(wh)
100129

101130

102131
@pytest.fixture(scope="session")
103132
def namespace(catalog) -> dict:
104-
namespace = "test-namespace"
133+
namespace = ("test-namespace",)
105134
catalog.create_namespace(namespace)
106-
return catalog.get_namespace(namespace)
135+
return Namespace(
136+
name=namespace,
137+
properties={},
138+
warehouse_id=catalog.properties.get("warehouse", None),
139+
)
107140

108141

109142
@pytest.fixture(scope="session")

tests/test_catalog.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,28 @@
66
import pyiceberg.io as io
77

88

9-
def test_create_namespace(warehouse):
10-
catalog = conftest.catalog(warehouse)
9+
def test_create_namespace(catalog):
1110
namespace = ("test_create_namespace",)
1211
catalog.create_namespace(namespace)
1312
assert namespace in catalog.list_namespaces()
1413

1514

16-
def test_list_namespaces(warehouse):
17-
catalog = conftest.catalog(warehouse)
15+
def test_list_namespaces(catalog):
1816
catalog.create_namespace(("test_list_namespaces_1",))
1917
catalog.create_namespace(("test_list_namespaces_2"))
2018
namespaces = catalog.list_namespaces()
2119
assert ("test_list_namespaces_1",) in namespaces
2220
assert ("test_list_namespaces_2",) in namespaces
2321

2422

25-
def test_default_location_for_namespace_is_set(warehouse):
26-
catalog = conftest.catalog(warehouse)
23+
def test_default_location_for_namespace_is_set(catalog):
2724
namespace = ("test_default_location_for_namespace",)
2825
catalog.create_namespace(namespace)
2926
loaded_properties = catalog.load_namespace_properties(namespace)
3027
assert "location" in loaded_properties
3128

3229

33-
def test_namespace_properties(warehouse):
34-
catalog = conftest.catalog(warehouse)
30+
def test_namespace_properties(catalog):
3531
namespace = ("test_namespace_properties",)
3632
properties = {"key-1": "value-1", "key2": "value2"}
3733
catalog.create_namespace(namespace, properties=properties)
@@ -40,17 +36,15 @@ def test_namespace_properties(warehouse):
4036
assert loaded_properties[key] == value
4137

4238

43-
def test_drop_namespace(warehouse):
44-
catalog = conftest.catalog(warehouse)
39+
def test_drop_namespace(catalog):
4540
namespace = ("test_drop_namespace",)
4641
catalog.create_namespace(namespace)
4742
assert namespace in catalog.list_namespaces()
4843
catalog.drop_namespace(namespace)
4944
assert namespace not in catalog.list_namespaces()
5045

5146

52-
def test_create_table(warehouse):
53-
catalog = conftest.catalog(warehouse)
47+
def test_create_table(catalog):
5448
namespace = ("test_create_table",)
5549
table_name = "my_table"
5650
schema = pa.schema(
@@ -71,8 +65,7 @@ def test_create_table(warehouse):
7165
assert len(loaded_table.schema().fields) == 3
7266

7367

74-
def test_drop_table(namespace):
75-
catalog = conftest.catalog(namespace.warehouse)
68+
def test_drop_table(catalog, namespace):
7669
table_name = "my_table"
7770
schema = pa.schema(
7871
[
@@ -89,8 +82,7 @@ def test_drop_table(namespace):
8982
assert "NoSuchTableError" in str(e)
9083

9184

92-
def test_drop_purge_table(namespace, storage_config):
93-
catalog = conftest.catalog(namespace.warehouse)
85+
def test_drop_purge_table(catalog, namespace, storage_config):
9486
table_name = "my_table"
9587
schema = pa.schema(
9688
[
@@ -133,8 +125,7 @@ def test_drop_purge_table(namespace, storage_config):
133125
assert "NoSuchTableError" in str(e)
134126

135127

136-
def test_table_properties(namespace):
137-
catalog = conftest.catalog(namespace.warehouse)
128+
def test_table_properties(catalog, namespace):
138129
table_name = "my_table"
139130
schema = pa.schema(
140131
[
@@ -151,8 +142,7 @@ def test_table_properties(namespace):
151142
assert table.properties == properties
152143

153144

154-
def test_list_tables(namespace):
155-
catalog = conftest.catalog(namespace.warehouse)
145+
def test_list_tables(catalog, namespace):
156146
assert len(catalog.list_tables(namespace.name)) == 0
157147
table_name_1 = "my_table_1"
158148
table_name_2 = "my_table_2"
@@ -171,8 +161,7 @@ def test_list_tables(namespace):
171161
assert (*namespace.name, table_name_2) in tables
172162

173163

174-
def test_write_read(namespace):
175-
catalog = conftest.catalog(namespace.warehouse)
164+
def test_write_read(catalog, namespace):
176165
table_name = "my_table"
177166
schema = pa.schema(
178167
[

0 commit comments

Comments
 (0)