diff --git a/django_typer/management/commands/shellcompletion.py b/django_typer/management/commands/shellcompletion.py index 82cbbb6..682beb9 100644 --- a/django_typer/management/commands/shellcompletion.py +++ b/django_typer/management/commands/shellcompletion.py @@ -218,10 +218,7 @@ def source_vars(self) -> t.Dict[str, t.Any]: else "--no-color" if self.command.force_color else "", - "fallback": ( - f" --fallback {self.command.fallback.__module__}." - f"{self.command.fallback.__name__}" - ) + "fallback": f" --fallback {self.command.fallback_import}" if self.command.fallback else "", "is_installed": not isinstance(self.command.manage_script, Path), @@ -555,6 +552,7 @@ def install( "The name of the template to use for the shell completion script." ), ) + # todo - add template name completer - see django-render-static ), ] = None, ): diff --git a/tests/shellcompletion/__init__.py b/tests/shellcompletion/__init__.py index 33dc09b..40c59ff 100644 --- a/tests/shellcompletion/__init__.py +++ b/tests/shellcompletion/__init__.py @@ -17,7 +17,10 @@ from django.test import TestCase from django_typer.management import get_command -from django_typer.management.commands.shellcompletion import Command as ShellCompletion +from django_typer.management.commands.shellcompletion import ( + Command as ShellCompletion, + DjangoTyperShellCompleter, +) from ..utils import rich_installed default_shell = None @@ -72,7 +75,14 @@ class _CompleteTestCase: @cached_property def command(self) -> ShellCompletion: - return get_command("shellcompletion", ShellCompletion) + cmd = get_command("shellcompletion", ShellCompletion) + cmd.init(shell=self.shell) + return cmd + + def get_completer(self, **kwargs) -> DjangoTyperShellCompleter: + return self.command.shell_class( + **{"prog_name": self.manage_script, "command": self.command, **kwargs} + ) def setUp(self): self.remove() diff --git a/tests/shellcompletion/test_bash.py b/tests/shellcompletion/test_bash.py index bb0bf12..fc3d2f4 100644 --- a/tests/shellcompletion/test_bash.py +++ b/tests/shellcompletion/test_bash.py @@ -61,3 +61,20 @@ def test_no_bashrc_file(self): finally: if bashrc: (Path.home() / ".bashrc").write_text(bashrc) + + def test_source_template(self): + self.assertEqual( + ( + Path(__file__).parent.parent.parent + / "django_typer/templates/shell_complete/bash.sh" + ).read_text(), + self.get_completer().source_template, + ) + + self.assertEqual( + ( + Path(__file__).parent.parent.parent + / "django_typer/templates/shell_complete/zsh.sh" + ).read_text(), + self.get_completer(template="shell_complete/zsh.sh").source_template, + )