11import pytest
22from django .core .management import call_command
33from django .core .management .base import CommandError
4+ from ellar .common .constants import MODULE_METADATA
5+ from ellar .reflect import reflect
6+
7+ from ellar_django .module import DjangoModule , _default_blacklisted_commands
8+
9+ HELP_OUTPUT = """Usage: django [OPTIONS] COMMAND [ARGS]...
10+
11+ Ellar Django Commands
12+
13+ Options:
14+ -v, --version Show the version and exit.
15+ --help Show this message and exit.
16+
17+ Commands:
18+ """
419
520
621def test_command_succeeds () -> None :
@@ -10,3 +25,77 @@ def test_command_succeeds() -> None:
1025def test_nonexistent_command_fails () -> None :
1126 with pytest .raises (CommandError , match = "Unknown command" ):
1227 call_command ("nonexistent_command" )
28+
29+
30+ def test_command_help (cli_runner ):
31+ with reflect .context ():
32+ DjangoModule .setup (
33+ settings_module = "example_app.wsgi_django.settings"
34+ ).apply_configuration ()
35+ django_command_group = reflect .get_metadata (
36+ MODULE_METADATA .COMMANDS , DjangoModule
37+ )[0 ]
38+
39+ res = cli_runner .invoke (django_command_group , ["--help" ])
40+ assert res .exit_code == 0
41+ assert HELP_OUTPUT in res .stdout
42+
43+
44+ def test_check_help (cli_runner ):
45+ with reflect .context ():
46+ DjangoModule .setup (
47+ settings_module = "example_app.wsgi_django.settings"
48+ ).apply_configuration ()
49+ django_command_group = reflect .get_metadata (
50+ MODULE_METADATA .COMMANDS , DjangoModule
51+ )[0 ]
52+
53+ res = cli_runner .invoke (django_command_group , ["check" , "--help" ])
54+ assert res .exit_code == 0
55+ assert (
56+ "usage: manage.py check [-h] [--tag TAGS] [--list-tags] [--deploy]"
57+ in res .stdout
58+ )
59+
60+
61+ @pytest .mark .parametrize ("command_name" , list (_default_blacklisted_commands ))
62+ def test_default_blacklist_command (cli_runner , command_name ):
63+ with reflect .context ():
64+ DjangoModule .setup (
65+ settings_module = "example_app.wsgi_django.settings"
66+ ).apply_configuration ()
67+ django_command_group = reflect .get_metadata (
68+ MODULE_METADATA .COMMANDS , DjangoModule
69+ )[0 ]
70+
71+ res = cli_runner .invoke (django_command_group , [command_name ])
72+ assert res .exit_code == 2
73+ assert f"Error: No such command '{ command_name } '" in res .stdout
74+
75+
76+ def test_django_version (cli_runner ):
77+ with reflect .context ():
78+ DjangoModule .setup (
79+ settings_module = "example_app.wsgi_django.settings"
80+ ).apply_configuration ()
81+ django_command_group = reflect .get_metadata (
82+ MODULE_METADATA .COMMANDS , DjangoModule
83+ )[0 ]
84+
85+ res = cli_runner .invoke (django_command_group , ["-v" ])
86+ assert res .exit_code == 0
87+ assert "Django Version: " in res .stdout
88+
89+
90+ def test_collect_static_version (cli_runner ):
91+ with reflect .context ():
92+ DjangoModule .setup (
93+ settings_module = "example_app.wsgi_django.settings"
94+ ).apply_configuration ()
95+ django_command_group = reflect .get_metadata (
96+ MODULE_METADATA .COMMANDS , DjangoModule
97+ )[0 ]
98+
99+ res = cli_runner .invoke (django_command_group , ["check" , "db_models" ])
100+ assert res .exit_code == 0
101+ assert res .stdout == "System check identified no issues (0 silenced).\n "
0 commit comments