Skip to content

Commit f8fd7b9

Browse files
committed
Remove store dependency in client
1 parent a469b13 commit f8fd7b9

1 file changed

Lines changed: 70 additions & 53 deletions

File tree

meorg_client/tests/test_client.py

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import pytest
55
from meorg_client.client import Client
66
import meorg_client.utilities as mu
7-
from conftest import store
8-
9-
# from requests import RequestException
107
import tempfile as tf
11-
import time
128

139

1410
def _get_authenticated_client() -> Client:
@@ -39,7 +35,7 @@ def _get_authenticated_client() -> Client:
3935
return client
4036

4137

42-
@pytest.fixture
38+
@pytest.fixture(scope="module")
4339
def client() -> Client:
4440
"""Get an authenticated client.
4541
@@ -84,7 +80,7 @@ def test_list_endpoints(client: Client):
8480

8581

8682
@pytest.fixture
87-
def model_output_generator(client: Client, model_profile_id):
83+
def model_output_generator(request, client: Client, model_profile_id: str):
8884
model_output_ids = []
8985

9086
def _make_model_output(model_output_name):
@@ -95,20 +91,27 @@ def _make_model_output(model_output_name):
9591

9692
yield _make_model_output
9793

98-
# TODO: Make tests more tight
99-
# try:
100-
# for model_output_id in model_output_ids:
101-
# client.model_output_delete(model_output_id)
102-
# except RequestException:
103-
# pass
94+
# Used if already deleted
95+
if hasattr(request.node, "skip_teardown"):
96+
return
97+
98+
for model_output_id in model_output_ids:
99+
client.model_output_delete(model_output_id)
104100

105101

106102
@pytest.fixture
107-
def model_output_id(client: Client, model_output_generator: str):
108-
return model_output_generator("model_output_test")
103+
def model_output_id(model_output_generator: str):
104+
"""Generate fresh model output ID.
105+
106+
Parameters
107+
----------
108+
model_output_generator: str
109+
Model output generator function
110+
"""
111+
return model_output_generator("base_model_output")
109112

110113

111-
class ModelOutput:
114+
class TestModelOutput:
112115

113116
def test_create_model_output(
114117
self, client: Client, model_profile_id: str, model_output_name: str
@@ -120,13 +123,10 @@ def test_create_model_output(
120123
model_output_id = response.get("data").get("modeloutput")
121124
assert model_output_id is not None
122125

123-
store.set("model_output_id", model_output_id)
124-
125126
self.test_model_output_query(client, model_output_id)
126127

127128
def test_model_output_query(self, client: Client, model_output_id: str):
128129
"""Test Existing Model output."""
129-
# response = client.model_output_query(store.get("model_output_id"))
130130
response = client.model_output_query(model_output_id)
131131
assert client.success()
132132

@@ -136,6 +136,7 @@ def test_model_output_query(self, client: Client, model_output_id: str):
136136
def test_model_output_update(
137137
self,
138138
client: Client,
139+
model_output_id: str,
139140
model_profile_id: str,
140141
):
141142
"""Test updation of model output."""
@@ -148,10 +149,11 @@ def test_model_output_update(
148149
"comments": "updated model output pytest",
149150
"is_bundle": False,
150151
}
151-
_ = client.model_output_update(store.get("model_output_id"), update_data)
152+
_ = client.model_output_update(model_output_id, update_data)
152153
assert client.success()
153154

154-
def test_model_output_delete(client: Client, model_output_id: str):
155+
def test_model_output_delete(self, request, client: Client, model_output_id: str):
156+
request.node.skip_teardown = True
155157
_ = client.model_output_delete(model_output_id)
156158
assert client.success()
157159

@@ -163,37 +165,51 @@ class TestBenchmark:
163165
def model_output_id(
164166
self, client: Client, model_output_generator, experiment_id: str
165167
):
166-
id1 = model_output_generator("model_output_benchmark1")
167-
id2 = model_output_generator("model_output_benchmark2")
168+
id1 = model_output_generator("meorg_test_benchmark1")
169+
id2 = model_output_generator("meorg_test_benchmark2")
168170
client.model_output_experiments_extend(id1, [experiment_id])
169171
client.model_output_experiments_extend(id2, [experiment_id])
170172
return id1
171173

174+
def _check_available_benchmarks(self, response, expected):
175+
available_benchmarks = response.get("data").get("benchmarks")
176+
assert type(available_benchmarks) is list
177+
assert len(available_benchmarks) == 1
178+
return available_benchmarks
179+
180+
def _check_current_benchmarks(self, response, expected):
181+
current_benchmarks = response.get("data").get("current")
182+
assert type(current_benchmarks) is list
183+
assert len(current_benchmarks) == 0
184+
return current_benchmarks
185+
172186
def test_model_output_benchmarks_list(
173187
self, client: Client, model_output_id: str, experiment_id: str
174188
):
175189

176190
response = client.model_output_benchmarks_list(model_output_id, experiment_id)
177-
178-
benchmarks_list = response.get("data").get("benchmarks")
179-
180-
assert type(benchmarks_list) is list
181-
assert len(benchmarks_list) > 0
182-
183-
store.set("sample_benchmark_id", benchmarks_list[0]["id"])
184-
191+
self._check_available_benchmarks(response, 1)
192+
self._check_current_benchmarks(response, 0)
185193
assert client.success()
186194

187195
def test_model_output_benchmarks_replace(
188196
self, client: Client, model_output_id: str, experiment_id: str
189197
):
198+
response = client.model_output_benchmarks_list(model_output_id, experiment_id)
199+
200+
available_benchmarks = self._check_available_benchmarks(response, 1)
201+
self._check_current_benchmarks(response, 0)
202+
190203
client.model_output_benchmarks_replace(
191204
model_output_id,
192205
experiment_id,
193-
[store.get("sample_benchmark_id")],
206+
[available_benchmarks[0]["id"]],
194207
)
195208
assert client.success()
196209

210+
self._check_available_benchmarks(response, 0)
211+
self._check_current_benchmarks(response, 1)
212+
197213

198214
def test_model_output_experiments_extend(
199215
client: Client, model_output_id: str, experiment_id: str
@@ -229,9 +245,6 @@ def test_upload_file(client: Client, test_filepath: str, model_output_id: str):
229245
# Make sure it worked
230246
assert client.success()
231247

232-
# Store the response.
233-
store.set("file_upload", response)
234-
235248

236249
def test_upload_file_multiple(client: Client, test_filepath: str, model_output_id: str):
237250
"""Test the uploading of multiple files in sequence.
@@ -253,9 +266,6 @@ def test_upload_file_multiple(client: Client, test_filepath: str, model_output_i
253266
[response.get("data").get("files")[0].get("id") for response in responses]
254267
)
255268

256-
# Store the response.
257-
store.set("file_upload_multiple", responses)
258-
259269

260270
def test_file_list(client: Client, model_output_id: str):
261271
"""Test the listing of files for a model output.
@@ -270,7 +280,6 @@ def test_file_list(client: Client, model_output_id: str):
270280
response = client.list_files(model_output_id)
271281
assert client.success()
272282
assert isinstance(response.get("data").get("files"), list)
273-
store.set("file_list", response)
274283

275284

276285
class TestAnalysis:
@@ -283,11 +292,18 @@ def model_output_id_analysis(
283292
experiment_id: str,
284293
model_output_generator,
285294
):
286-
model_output_id = model_output_generator("model_output_analysis_test")
295+
model_output_id = model_output_generator("meorg_test_analysis")
287296
client.model_output_experiments_extend(model_output_id, [experiment_id])
288297
client.upload_files([test_filepath, test_filepath], model_output_id)
289298
return model_output_id
290299

300+
@pytest.fixture
301+
def analysis_id(
302+
self, client: Client, model_output_id_analysis: str, experiment_id: str
303+
):
304+
response = client.start_analysis(model_output_id_analysis, experiment_id)
305+
return response.get("data").get("analysisId")
306+
291307
def test_start_analysis(
292308
self, client: Client, model_output_id_analysis: str, experiment_id: str
293309
):
@@ -300,24 +316,17 @@ def test_start_analysis(
300316
model_output_id : str
301317
Model output ID.
302318
"""
303-
# Wait 5s for data to move from cache to store (otherwise analysis will fail, still might)
304-
time.sleep(5)
305-
response = client.start_analysis(model_output_id_analysis, experiment_id)
319+
_ = client.start_analysis(model_output_id_analysis, experiment_id)
306320
assert client.success()
307321

308-
# Store result for status check below
309-
store.set("start_analysis", response)
310-
311-
def test_get_analysis_status(self, client: Client):
322+
def test_get_analysis_status(self, client: Client, analysis_id: str):
312323
"""Test getting the analysis status.
313324
314325
Parameters
315326
----------
316327
client : Client
317328
Client.
318329
"""
319-
# Get the analysis id from the store
320-
analysis_id = store.get("start_analysis").get("data").get("analysisId")
321330
_ = client.get_analysis_status(analysis_id)
322331
assert client.success()
323332

@@ -402,7 +411,9 @@ def test_upload_file_parallel_no_progress(
402411
)
403412

404413

405-
def test_delete_file_from_model_output(client: Client, model_output_id: str):
414+
def test_delete_file_from_model_output(
415+
client: Client, test_filepath: str, model_output_id: str
416+
):
406417
"""Test deleting a file from a model output.
407418
408419
Parameters
@@ -412,12 +423,13 @@ def test_delete_file_from_model_output(client: Client, model_output_id: str):
412423
model_output_id : str
413424
Model output ID.
414425
"""
426+
file_upload = client.upload_files(test_filepath, id=model_output_id)[0]
415427

416428
# Retrieve the uploaded file ID from earlier.
417-
file_id = store.get("file_upload").get("data").get("files")[0].get("id")
429+
file_id = file_upload.get("data").get("files")[0].get("id")
418430

419431
# Retieve the file list from earlier.
420-
files = store.get("file_list")
432+
files = client.list_files(model_output_id)
421433

422434
# Convert to a list of JUST the IDs, none of the extra attributes.
423435
file_ids = [f.get("id") for f in files.get("data").get("files")]
@@ -438,7 +450,9 @@ def test_delete_file_from_model_output(client: Client, model_output_id: str):
438450
assert file_id not in file_ids
439451

440452

441-
def test_delete_all_files_from_model_output(client: Client, model_output_id: str):
453+
def test_delete_all_files_from_model_output(
454+
client: Client, test_filepath: str, model_output_id: str
455+
):
442456
"""Test deleting all files from a model output.
443457
444458
Parameters
@@ -449,8 +463,11 @@ def test_delete_all_files_from_model_output(client: Client, model_output_id: str
449463
Model output ID.
450464
"""
451465

466+
# Upload a list of files
467+
client.upload_files([test_filepath, test_filepath], model_output_id)
468+
452469
# Get the list of files and unpack to list
453-
files = store.get("file_list")
470+
files = client.list_files(model_output_id)
454471
file_ids = [f.get("id") for f in files.get("data").get("files")]
455472

456473
# Make sure the list is more than 2 items long.

0 commit comments

Comments
 (0)