Skip to content

Commit c59410c

Browse files
committed
Make cli.update test more flexible
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 05e2d2b commit c59410c

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

tests/test_dispatch_cli.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ async def test_create_command( # pylint: disable=too-many-arguments,too-many-lo
356356

357357
@pytest.mark.asyncio
358358
@pytest.mark.parametrize(
359-
"dispatches, field, value, update_field, update_value, expected_return_code, expected_output",
359+
"dispatches, args, fields, expected_return_code, expected_output",
360360
[
361361
(
362362
[
@@ -375,12 +375,13 @@ async def test_create_command( # pylint: disable=too-many-arguments,too-many-lo
375375
update_time=datetime(2023, 1, 1, 0, 0, 0),
376376
)
377377
],
378-
"--duration",
379-
"7200",
380-
"duration",
381-
timedelta(seconds=7200),
378+
[
379+
"--duration",
380+
"7200",
381+
],
382+
{"duration": timedelta(seconds=7200)},
382383
0,
383-
"Dispatch updated.",
384+
"duration=datetime.timedelta(seconds=7200)",
384385
),
385386
(
386387
[
@@ -399,12 +400,15 @@ async def test_create_command( # pylint: disable=too-many-arguments,too-many-lo
399400
update_time=datetime(2023, 1, 1, 0, 0, 0),
400401
)
401402
],
402-
"--active",
403-
"False",
404-
"active",
405-
False,
403+
[
404+
"--active",
405+
"False",
406+
],
407+
{
408+
"active": False,
409+
},
406410
0,
407-
"Dispatch updated.",
411+
"active=False",
408412
),
409413
(
410414
[
@@ -423,19 +427,23 @@ async def test_create_command( # pylint: disable=too-many-arguments,too-many-lo
423427
update_time=datetime(2023, 1, 1, 0, 0, 0),
424428
)
425429
],
426-
"--selector",
427-
"400, 401",
428-
"selector",
429-
[400, 401],
430+
[
431+
"--selector",
432+
"400, 401",
433+
],
434+
{
435+
"selector": [400, 401],
436+
},
430437
0,
431-
"Dispatch updated.",
438+
"selector=[400, 401]",
432439
),
433440
(
434441
[],
435-
"--duration",
436-
"frankly my dear, I don't give a damn",
437-
"",
438-
None,
442+
[
443+
"--duration",
444+
"frankly my dear, I don't give a damn",
445+
],
446+
{},
439447
2,
440448
"Error: Invalid value for '--duration': Could not parse time expression",
441449
),
@@ -445,20 +453,20 @@ async def test_update_command( # pylint: disable=too-many-arguments
445453
runner: CliRunner,
446454
fake_client: FakeClient,
447455
dispatches: list[Dispatch],
448-
field: str,
449-
value: str,
450-
update_field: str,
451-
update_value: Any,
456+
args: list[str],
457+
fields: dict[str, Any],
452458
expected_return_code: int,
453459
expected_output: str,
454460
) -> None:
455461
"""Test the update command."""
456462
fake_client.dispatches = dispatches
457-
result = await runner.invoke(cli, ["update", "1", field, value])
463+
result = await runner.invoke(cli, ["update", "1", *args])
458464
assert result.exit_code == expected_return_code
459465
assert expected_output in result.output
460-
if expected_return_code == 0:
461-
assert getattr(fake_client.dispatches[0], update_field) == update_value
466+
if dispatches:
467+
assert len(fake_client.dispatches) == 1
468+
for key, value in fields.items():
469+
assert getattr(fake_client.dispatches[0], key) == value
462470

463471

464472
@pytest.mark.asyncio

0 commit comments

Comments
 (0)