Skip to content

Commit 08576c7

Browse files
grieve54706goldmedal
authored andcommitted
test: close test client after testing and make manifest_str be pytest.fixture (#830)
1 parent 0c1c3c2 commit 08576c7

File tree

10 files changed

+189
-189
lines changed

10 files changed

+189
-189
lines changed

ibis-server/tests/routers/test_ibis.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
"columns": [
1414
{"name": "orderkey", "expression": "o_orderkey", "type": "integer"}
1515
],
16-
"primaryKey": "orderkey",
1716
},
1817
],
1918
}
2019

2120

2221
@pytest.fixture
23-
def manifest_hash(web_server):
22+
def manifest_str(web_server):
2423
return web_server.register_mdl(manifest)
2524

2625

2726
with TestClient(app) as client:
2827

29-
def test_dry_plan(manifest_hash):
28+
def test_dry_plan(manifest_str):
3029
response = client.post(
3130
url="/v2/connector/dry-plan",
3231
json={
33-
"manifestStr": manifest_hash,
32+
"manifestStr": manifest_str,
3433
"sql": 'SELECT orderkey FROM "Orders" LIMIT 1',
3534
},
3635
)

ibis-server/tests/routers/v2/connector/test_bigquery.py

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ def test_validate_with_unknown_rule(manifest_str):
270270
"parameters": {"modelName": "Orders", "columnName": "orderkey"},
271271
},
272272
)
273+
273274
assert response.status_code == 422
274275
assert (
275276
response.text

ibis-server/tests/routers/v2/connector/test_mssql.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
],
7070
}
7171

72+
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
73+
74+
75+
@pytest.fixture
76+
def manifest_str(web_server):
77+
return web_server.register_mdl(manifest)
78+
7279

7380
@pytest.fixture(scope="module")
7481
def mssql(request) -> SqlServerContainer:
@@ -103,13 +110,6 @@ def mssql(request) -> SqlServerContainer:
103110
return mssql
104111

105112

106-
@pytest.fixture
107-
def manifest_str(web_server):
108-
return web_server.register_mdl(manifest)
109-
110-
111-
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
112-
113113
with TestClient(app) as client:
114114

115115
def test_query(manifest_str, mssql: SqlServerContainer):

ibis-server/tests/routers/v2/connector/test_mysql.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@
7878
],
7979
}
8080

81+
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
82+
83+
84+
@pytest.fixture
85+
def manifest_str(web_server):
86+
return web_server.register_mdl(manifest)
87+
8188

8289
@pytest.fixture(scope="module")
8390
def mysql(request) -> MySqlContainer:
@@ -109,13 +116,6 @@ def mysql(request) -> MySqlContainer:
109116
return mysql
110117

111118

112-
@pytest.fixture
113-
def manifest_str(web_server):
114-
return web_server.register_mdl(manifest)
115-
116-
117-
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
118-
119119
with TestClient(app) as client:
120120

121121
def test_query(manifest_str, mysql: MySqlContainer):

ibis-server/tests/routers/v2/connector/test_postgres.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
],
8383
}
8484

85+
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
86+
87+
88+
@pytest.fixture
89+
def manifest_str(web_server):
90+
return web_server.register_mdl(manifest)
91+
8592

8693
@pytest.fixture(scope="module")
8794
def postgres(request) -> PostgresContainer:
@@ -97,14 +104,6 @@ def postgres(request) -> PostgresContainer:
97104
return pg
98105

99106

100-
@pytest.fixture
101-
def manifest_str(web_server):
102-
return web_server.register_mdl(manifest)
103-
104-
105-
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
106-
107-
108107
with TestClient(app) as client:
109108

110109
def test_query(manifest_str, postgres: PostgresContainer):
@@ -164,8 +163,7 @@ def test_query_with_connection_url(manifest_str, postgres: PostgresContainer):
164163
assert result["dtypes"] is not None
165164

166165
def test_dry_run_with_connection_url_and_password_with_bracket_should_not_raise_value_error(
167-
manifest_str,
168-
postgres: PostgresContainer,
166+
manifest_str, postgres: PostgresContainer
169167
):
170168
connection_url = _to_connection_url(postgres)
171169
part = urlparse(connection_url)

ibis-server/tests/routers/v2/connector/test_snowflake.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@
6969
],
7070
}
7171

72+
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
73+
7274

7375
@pytest.fixture
7476
def manifest_str(web_server):
7577
return web_server.register_mdl(manifest)
7678

7779

78-
orig_manifest_str = base64.b64encode(orjson.dumps(manifest)).decode("utf-8")
79-
8080
with TestClient(app) as client:
8181

8282
def test_query(manifest_str):
@@ -326,12 +326,10 @@ def test_validate_rule_column_is_valid_without_one_parameter():
326326
assert response.status_code == 422
327327
assert response.text == "Missing required parameter: `modelName`"
328328

329+
@pytest.mark.skip(reason="Not implemented")
330+
def test_metadata_list_tables():
331+
pass
329332

330-
@pytest.mark.skip(reason="Not implemented")
331-
def test_metadata_list_tables():
332-
pass
333-
334-
335-
@pytest.mark.skip(reason="Not implemented")
336-
def test_metadata_list_constraints():
337-
pass
333+
@pytest.mark.skip(reason="Not implemented")
334+
def test_metadata_list_constraints():
335+
pass

ibis-server/tests/routers/v2/connector/test_trino.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_query_with_limit(manifest_str, trino: TrinoContainer):
184184
result = response.json()
185185
assert len(result["data"]) == 1
186186

187-
def test_query_without_manifest(manifest_str, trino: TrinoContainer):
187+
def test_query_without_manifest(trino: TrinoContainer):
188188
connection_info = _to_connection_info(trino)
189189
response = client.post(
190190
url=f"{base_url}/query",

ibis-server/tests/routers/v2/test_analysis.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@
7878
},
7979
],
8080
}
81-
with TestClient(app) as client:
8281

83-
@pytest.fixture
84-
def manifest_hash(web_server):
85-
return web_server.register_mdl(manifest)
8682

87-
def test_analysis_sql_select_all_customer(manifest_hash):
83+
@pytest.fixture
84+
def manifest_str(web_server):
85+
return web_server.register_mdl(manifest)
86+
87+
88+
with TestClient(app) as client:
89+
90+
def test_analysis_sql_select_all_customer(manifest_str):
8891
result = get_sql_analysis(
89-
{"manifestStr": manifest_hash, "sql": "SELECT * FROM customer"}
92+
{"manifestStr": manifest_str, "sql": "SELECT * FROM customer"}
9093
)
9194
assert len(result) == 1
9295
assert result[0]["relation"]["tableName"] == "customer"
@@ -106,10 +109,10 @@ def test_analysis_sql_select_all_customer(manifest_hash):
106109
assert result[0]["relation"]["tableName"] == "customer"
107110
assert result[0]["relation"]["nodeLocation"] == {"line": 1, "column": 15}
108111

109-
def test_analysis_sql_group_by_customer(manifest_hash):
112+
def test_analysis_sql_group_by_customer(manifest_str):
110113
result = get_sql_analysis(
111114
{
112-
"manifestStr": manifest_hash,
115+
"manifestStr": manifest_str,
113116
"sql": "SELECT custkey, count(*) FROM customer GROUP BY 1",
114117
}
115118
)
@@ -135,10 +138,10 @@ def test_analysis_sql_group_by_customer(manifest_hash):
135138
],
136139
}
137140

138-
def test_analysis_sql_join_customer_orders(manifest_hash):
141+
def test_analysis_sql_join_customer_orders(manifest_str):
139142
result = get_sql_analysis(
140143
{
141-
"manifestStr": manifest_hash,
144+
"manifestStr": manifest_str,
142145
"sql": "SELECT * FROM customer c JOIN orders o ON c.custkey = o.custkey",
143146
}
144147
)
@@ -181,10 +184,10 @@ def test_analysis_sql_join_customer_orders(manifest_hash):
181184
},
182185
]
183186

184-
def test_analysis_sql_where_clause(manifest_hash):
187+
def test_analysis_sql_where_clause(manifest_str):
185188
result = get_sql_analysis(
186189
{
187-
"manifestStr": manifest_hash,
190+
"manifestStr": manifest_str,
188191
"sql": "SELECT * FROM customer WHERE custkey = 1 OR (name = 'test' AND address = 'test')",
189192
}
190193
)
@@ -205,10 +208,10 @@ def test_analysis_sql_where_clause(manifest_hash):
205208
]
206209
assert result[0]["filter"]["right"]["type"] == "AND"
207210

208-
def test_analysis_sql_group_by_multiple_columns(manifest_hash):
211+
def test_analysis_sql_group_by_multiple_columns(manifest_str):
209212
result = get_sql_analysis(
210213
{
211-
"manifestStr": manifest_hash,
214+
"manifestStr": manifest_str,
212215
"sql": "SELECT custkey, count(*), name FROM customer GROUP BY 1, 3, nationkey",
213216
}
214217
)
@@ -251,10 +254,10 @@ def test_analysis_sql_group_by_multiple_columns(manifest_hash):
251254
],
252255
}
253256

254-
def test_analysis_sql_order_by(manifest_hash):
257+
def test_analysis_sql_order_by(manifest_str):
255258
result = get_sql_analysis(
256259
{
257-
"manifestStr": manifest_hash,
260+
"manifestStr": manifest_str,
258261
"sql": "SELECT custkey, name FROM customer ORDER BY 1 ASC, 2 DESC",
259262
}
260263
)
@@ -275,10 +278,10 @@ def test_analysis_sql_order_by(manifest_hash):
275278
assert result[0]["sortings"][1]["ordering"] == "DESCENDING"
276279
assert result[0]["sortings"][1]["nodeLocation"] == {"line": 1, "column": 52}
277280

278-
def test_analysis_sqls(manifest_hash):
281+
def test_analysis_sqls(manifest_str):
279282
result = get_sql_analysis_batch(
280283
{
281-
"manifestStr": manifest_hash,
284+
"manifestStr": manifest_str,
282285
"sqls": [
283286
"SELECT * FROM customer",
284287
"SELECT custkey, count(*) FROM customer GROUP BY 1",

0 commit comments

Comments
 (0)