Skip to content

Commit ebf5337

Browse files
committed
coverage
1 parent 43651c1 commit ebf5337

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

django_typer/tests/test_app/management/commands/completion.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,23 @@ def handle(
2525
shell_complete=completers.complete_app_label,
2626
),
2727
],
28+
option: Annotated[
29+
t.Optional[AppConfig],
30+
typer.Option(
31+
parser=parsers.parse_app_label,
32+
help=_("An app given as an option."),
33+
shell_complete=completers.complete_app_label,
34+
),
35+
] = None,
2836
):
2937
assert self.__class__ == Command
3038
for app in django_apps:
3139
assert isinstance(app, AppConfig)
40+
if option:
41+
return json.dumps(
42+
{
43+
"django_apps": [app.label for app in django_apps],
44+
"option": option.label,
45+
}
46+
)
3247
return json.dumps([app.label for app in django_apps])

django_typer/tests/tests.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,7 @@ def test_app_label_parser_completers(self):
18551855
call_command("completion", "django_typer_tests.polls")
18561856

18571857
poll_app = apps.get_app_config("django_typer_tests_polls")
1858+
test_app = apps.get_app_config("django_typer_tests_test_app")
18581859
cmd = get_command("completion")
18591860
self.assertEqual(
18601861
json.loads(cmd([poll_app])),
@@ -1865,6 +1866,52 @@ def test_app_label_parser_completers(self):
18651866
json.loads(cmd(django_apps=[poll_app])), ["django_typer_tests_polls"]
18661867
)
18671868

1869+
self.assertEqual(
1870+
json.loads(cmd(django_apps=[poll_app], option=test_app)),
1871+
{
1872+
"django_apps": ["django_typer_tests_polls"],
1873+
"option": "django_typer_tests_test_app",
1874+
},
1875+
)
1876+
1877+
self.assertEqual(
1878+
json.loads(
1879+
call_command("completion", "django_typer_tests_polls", option=test_app)
1880+
),
1881+
{
1882+
"django_apps": ["django_typer_tests_polls"],
1883+
"option": "django_typer_tests_test_app",
1884+
},
1885+
)
1886+
1887+
self.assertEqual(
1888+
json.loads(
1889+
call_command(
1890+
"completion",
1891+
"django_typer_tests_polls",
1892+
option="django_typer_tests_test_app",
1893+
)
1894+
),
1895+
{
1896+
"django_apps": ["django_typer_tests_polls"],
1897+
"option": "django_typer_tests_test_app",
1898+
},
1899+
)
1900+
1901+
self.assertEqual(
1902+
json.loads(
1903+
call_command(
1904+
"completion",
1905+
"django_typer_tests_polls",
1906+
"--option=django_typer_tests_test_app",
1907+
)
1908+
),
1909+
{
1910+
"django_apps": ["django_typer_tests_polls"],
1911+
"option": "django_typer_tests_test_app",
1912+
},
1913+
)
1914+
18681915
def test_char_field(self):
18691916
result = StringIO()
18701917
with contextlib.redirect_stdout(result):

0 commit comments

Comments
 (0)