Skip to content

Commit fdf4602

Browse files
committed
write tests for all endpoints
1 parent 15be7e3 commit fdf4602

4 files changed

Lines changed: 129 additions & 43 deletions

File tree

meorg_client/cli.py

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -397,78 +397,88 @@ def model_output_update(
397397
click.echo("Parameters of MO updated")
398398

399399

400-
@click.command("update")
400+
@click.command("list")
401401
@click.argument("model_output_id")
402402
@click.argument("exp_id")
403-
@click.argument("benchmarks", default="", callback=_parse_csv)
404-
def model_benchmark_update(model_output_id: str, exp_id: str, benchmarks: str):
405-
"""Update model benchmark
403+
def model_output_benchmarks_list(model_output_id: str, exp_id: str):
404+
"""List model benchmarks.
406405
407406
Parameters
408407
----------
409408
model_output_id : str
410-
_description_
409+
Model output ID
411410
exp_id : str
412-
_description_
413-
benchmarks : list[str]
414-
_description_
411+
Experiment ID
415412
"""
416413
client = _get_client()
417-
_ = _call(
418-
client.model_output_replace_benchmarks,
414+
response = _call(
415+
client.model_output_benchmarks_list,
419416
model_id=model_output_id,
420417
exp_id=exp_id,
421-
updated_benchmarks=benchmarks,
422418
)
423419

424420
if client.success():
425-
click.echo("Benchmark updated")
421+
click.echo(
422+
f"List of available benchmarks: {json.dumps(response.get("data").get("benchmarks"), indent=4)}"
423+
)
424+
click.echo(
425+
f"List of linked benchmarks: {json.dumps(response.get("data").get("current"), indent=4)}"
426+
)
426427

428+
return response.get("data")
427429

428-
@click.command("list")
430+
431+
@click.command("update")
429432
@click.argument("model_output_id")
430433
@click.argument("exp_id")
431-
def model_benchmark_list(model_output_id: str, exp_id: str):
432-
"""List model benchmarks
434+
@click.argument("benchmark_ids", default="", callback=_parse_csv)
435+
def model_output_benchmarks_replace(
436+
model_output_id: str, exp_id: str, benchmark_ids: str
437+
):
438+
"""
439+
Change benchmarks associated with Model output and Experiment.
433440
434441
Parameters
435442
----------
436443
model_output_id : str
437-
_description_
444+
Model output ID
438445
exp_id : str
439-
_description_
446+
Experiment ID
440447
benchmarks : list[str]
441-
_description_
448+
List of benchmarks IDs to fully replace existing
442449
"""
443450
client = _get_client()
444-
response = _call(
445-
client.model_output_list_benchmarks,
451+
_ = _call(
452+
client.model_output_benchmarks_replace,
446453
model_id=model_output_id,
447454
exp_id=exp_id,
455+
updated_benchmarks=benchmark_ids,
448456
)
449457

450458
if client.success():
451-
click.echo(response)
459+
click.echo("Benchmark updated")
452460

453461

454462
@click.command("update")
455463
@click.argument("model_output_id")
456-
@click.argument("experiments", default="", callback=_parse_csv)
457-
def model_experiments_extend(model_output_id: str, experiments: str):
458-
"""Update experiment associated with model output
464+
@click.argument("exp_ids", default="", callback=_parse_csv)
465+
def model_output_experiments_extend(model_output_id: str, exp_ids: list[str]):
466+
"""
467+
Extend existing set of experiment associations.
459468
460469
Parameters
461470
----------
462471
model_output_id : str
463-
_description_
472+
Model output ID
473+
464474
experiments : list[str]
465-
_description_
475+
List of experiment IDs
466476
"""
467477
client = _get_client()
468478
_ = _call(
469-
client.model_output_extend_experiments,
479+
client.model_output_experiments_extend,
470480
model_id=model_output_id,
471-
updated_experiments=experiments,
481+
updated_experiments=exp_ids,
472482
)
473483

474484
if client.success():
@@ -478,23 +488,24 @@ def model_experiments_extend(model_output_id: str, experiments: str):
478488
@click.command("delete")
479489
@click.argument("model_output_id")
480490
@click.argument("exp_id")
481-
def model_experiment_delete(model_output_id: str, exp_id: str):
491+
def model_output_experiment_delete(model_output_id: str, exp_id: str):
482492
"""Delete specific experiment associated with model output
483493
484494
Parameters
485495
----------
486496
model_output_id : str
487-
_description_
488-
experiment_id : str
489-
_description_
497+
Model output ID
498+
499+
experiment : str
500+
Experiment IDs
490501
"""
491502
client = _get_client()
492503
_ = _call(
493-
client.model_output_delete_experiment, model_id=model_output_id, exp_id=exp_id
504+
client.model_output_experiment_delete, model_id=model_output_id, exp_id=exp_id
494505
)
495506

496507
if client.success():
497-
click.echo("Experiments deleted")
508+
click.echo(f"Experiment ID: {exp_id} deleted")
498509

499510

500511
@click.command("delete")
@@ -633,12 +644,12 @@ def cli_model_experiments():
633644
cli_model_output.add_command(model_output_delete)
634645

635646
# Benchmarks command
636-
cli_model_benchmark.add_command(model_benchmark_list)
637-
cli_model_benchmark.add_command(model_benchmark_update)
647+
cli_model_benchmark.add_command(model_output_benchmarks_list)
648+
cli_model_benchmark.add_command(model_output_benchmarks_replace)
638649

639650
# Experiments command
640-
cli_model_experiments.add_command(model_experiments_extend)
641-
cli_model_experiments.add_command(model_experiment_delete)
651+
cli_model_experiments.add_command(model_output_experiments_extend)
652+
cli_model_experiments.add_command(model_output_experiment_delete)
642653

643654
# Add subparsers to the master
644655
cli.add_command(cli_endpoints)

meorg_client/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def model_output_update(
523523
json=updated_fields,
524524
)
525525

526-
def model_output_list_benchmarks(
526+
def model_output_benchmarks_list(
527527
self, model_id: str, exp_id: str
528528
) -> Union[dict, requests.Response]:
529529
return self._make_request(
@@ -532,7 +532,7 @@ def model_output_list_benchmarks(
532532
url_path_fields=dict(id=model_id, expId=exp_id),
533533
)
534534

535-
def model_output_replace_benchmarks(
535+
def model_output_benchmarks_replace(
536536
self, model_id: str, exp_id: str, updated_benchmarks: list[str]
537537
) -> Union[dict, requests.Response]:
538538
"""
@@ -559,7 +559,7 @@ def model_output_replace_benchmarks(
559559
json=dict(benchmarks=updated_benchmarks),
560560
)
561561

562-
def model_output_extend_experiments(
562+
def model_output_experiments_extend(
563563
self, model_id: str, updated_experiments: list[str]
564564
) -> Union[dict, requests.Response]:
565565
"""
@@ -586,8 +586,8 @@ def model_output_extend_experiments(
586586
json=dict(experiments=updated_experiments),
587587
)
588588

589-
def model_output_delete_experiment(
590-
self, model_id: str, exp_id
589+
def model_output_experiment_delete(
590+
self, model_id: str, exp_id: str
591591
) -> Union[dict, requests.Response]:
592592
return self._make_request(
593593
method=mcc.HTTP_DELETE,

meorg_client/tests/test_cli.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,46 @@ def test_model_output_update(
107107
assert result.exit_code == 0
108108

109109

110+
def test_model_output_experiments_extend(runner: CliRunner, experiment_id: str):
111+
result = runner.invoke(
112+
cli.model_output_experiments_extend,
113+
[store.get("model_output_id"), experiment_id],
114+
)
115+
assert result.exit_code == 0
116+
117+
118+
def test_model_output_experiment_delete(runner: CliRunner, experiment_id: str):
119+
result = runner.invoke(
120+
cli.model_output_experiment_delete,
121+
[store.get("model_output_id"), experiment_id],
122+
)
123+
assert result.exit_code == 0
124+
125+
126+
def test_model_output_benchmarks_list(runner: CliRunner, experiment_id: str):
127+
test_model_output_experiments_extend(runner, experiment_id)
128+
result = runner.invoke(
129+
cli.model_output_benchmarks_list,
130+
[store.get("model_output_id"), experiment_id],
131+
standalone_mode=False,
132+
)
133+
134+
benchmarks_list = result.return_value["benchmarks"]
135+
136+
assert len(benchmarks_list) > 0
137+
store.set("sample_benchmark_id", benchmarks_list[0]["id"])
138+
139+
assert result.exit_code == 0
140+
141+
142+
def test_model_output_benchmarks_replace(runner: CliRunner, experiment_id: str):
143+
result = runner.invoke(
144+
cli.model_output_benchmarks_replace,
145+
[store.get("model_output_id"), experiment_id, store.get("sample_benchmark_id")],
146+
)
147+
assert result.exit_code == 0
148+
149+
110150
def test_model_output_delete(runner: CliRunner):
111151
result = runner.invoke(cli.model_output_delete, [store.get("model_output_id")])
112152
assert result.exit_code == 0

meorg_client/tests/test_client.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,41 @@ def test_model_output_update(
134134
assert client.success()
135135

136136

137+
def test_model_output_benchmarks_list(client: Client, experiment_id: str):
138+
test_model_output_experiments_extend(client, experiment_id)
139+
response = client.model_output_benchmarks_list(
140+
store.get("model_output_id"), experiment_id
141+
)
142+
143+
benchmarks_list = response.get("data").get("benchmarks")
144+
145+
assert type(benchmarks_list) is list
146+
assert len(benchmarks_list) > 0
147+
148+
store.set("sample_benchmark_id", benchmarks_list[0]["id"])
149+
150+
assert client.success()
151+
152+
153+
def test_model_output_benchmarks_replace(client: Client, experiment_id: str):
154+
client.model_output_benchmarks_replace(
155+
store.get("model_output_id"), experiment_id, [store.get("sample_benchmark_id")]
156+
)
157+
assert client.success()
158+
159+
160+
def test_model_output_experiments_extend(client: Client, experiment_id: str):
161+
client.model_output_experiments_extend(
162+
store.get("model_output_id"), [experiment_id]
163+
)
164+
assert client.success()
165+
166+
167+
def test_model_output_experiment_delete(client: Client, experiment_id: str):
168+
client.model_output_experiment_delete(store.get("model_output_id"), experiment_id)
169+
assert client.success()
170+
171+
137172
def test_model_output_delete(client: Client):
138173
_ = client.model_output_query(store.get("model_output_id"))
139174
assert client.success()

0 commit comments

Comments
 (0)