Author: russellm
Date: 2009-11-18 05:10:50 -0600 (Wed, 18 Nov 2009)
New Revision: 11745

Added:
   django/trunk/tests/regressiontests/bash_completion/
   django/trunk/tests/regressiontests/bash_completion/__init__.py
   django/trunk/tests/regressiontests/bash_completion/management/
   django/trunk/tests/regressiontests/bash_completion/management/__init__.py
   django/trunk/tests/regressiontests/bash_completion/management/commands/
   
django/trunk/tests/regressiontests/bash_completion/management/commands/__init__.py
   
django/trunk/tests/regressiontests/bash_completion/management/commands/test_command.py
   django/trunk/tests/regressiontests/bash_completion/models.py
   django/trunk/tests/regressiontests/bash_completion/tests.py
Log:
Added tests for the bash completion script from [11526]. Thanks to Eric 
Holscher.

Added: django/trunk/tests/regressiontests/bash_completion/__init__.py
===================================================================

Added: django/trunk/tests/regressiontests/bash_completion/management/__init__.py
===================================================================

Added: 
django/trunk/tests/regressiontests/bash_completion/management/commands/__init__.py
===================================================================

Added: 
django/trunk/tests/regressiontests/bash_completion/management/commands/test_command.py
===================================================================
--- 
django/trunk/tests/regressiontests/bash_completion/management/commands/test_command.py
                              (rev 0)
+++ 
django/trunk/tests/regressiontests/bash_completion/management/commands/test_command.py
      2009-11-18 11:10:50 UTC (rev 11745)
@@ -0,0 +1,13 @@
+import sys, os
+from optparse import OptionParser, make_option
+
+from django.core.management.base import BaseCommand
+
+class Command(BaseCommand):
+    option_list = BaseCommand.option_list + (
+        make_option("--list", action="store_true", dest="list",
+                    help="Print all options"),
+    )
+
+    def handle(self, *args, **options):
+        pass

Added: django/trunk/tests/regressiontests/bash_completion/models.py
===================================================================

Added: django/trunk/tests/regressiontests/bash_completion/tests.py
===================================================================
--- django/trunk/tests/regressiontests/bash_completion/tests.py                 
        (rev 0)
+++ django/trunk/tests/regressiontests/bash_completion/tests.py 2009-11-18 
11:10:50 UTC (rev 11745)
@@ -0,0 +1,87 @@
+"""
+A series of tests to establish that the command-line bash completion works.
+"""
+import os
+import unittest
+import sys
+import StringIO
+
+from django.conf import settings
+from django.core.management import ManagementUtility
+
+class BashCompletionTests(unittest.TestCase):
+    """
+    Testing the Python level bash completion code.
+    This requires setting up the environment as if we got passed data
+    from bash.
+    """
+
+    def setUp(self):
+        self.old_DJANGO_AUTO_COMPLETE = os.environ.get('DJANGO_AUTO_COMPLETE')
+        os.environ['DJANGO_AUTO_COMPLETE'] = '1'
+        self.output = StringIO.StringIO()
+        self.old_stdout = sys.stdout
+        sys.stdout = self.output
+
+    def tearDown(self):
+        sys.stdout = self.old_stdout
+        if self.old_DJANGO_AUTO_COMPLETE:
+            os.environ['DJANGO_AUTO_COMPLETE'] = self.old_DJANGO_AUTO_COMPLETE
+        else:
+            del os.environ['DJANGO_AUTO_COMPLETE']
+
+    def _user_input(self, input_str):
+        os.environ['COMP_WORDS'] = input_str
+        os.environ['COMP_CWORD'] = str(len(input_str.split()) - 1)
+        sys.argv = input_str.split(' ')
+
+    def _run_autocomplete(self):
+        util = ManagementUtility(argv=sys.argv)
+        try:
+            util.autocomplete()
+        except SystemExit:
+            pass
+        return self.output.getvalue().strip().split('\n')
+
+    def test_django_admin_py(self):
+        "django_admin.py will autocomplete option flags"
+        self._user_input('django-admin.py sqlall --v')
+        output = self._run_autocomplete()
+        self.assertEqual(output, ['--verbosity='])
+
+    def test_manage_py(self):
+        "manage.py will autocomplete option flags"
+        self._user_input('manage.py sqlall --v')
+        output = self._run_autocomplete()
+        self.assertEqual(output, ['--verbosity='])
+
+    def test_custom_command(self):
+        "A custom command can autocomplete option flags"
+        self._user_input('django-admin.py test_command --l')
+        output = self._run_autocomplete()
+        self.assertEqual(output, ['--list'])
+
+    def test_subcommands(self):
+        "Subcommands can be autocompleted"
+        self._user_input('django-admin.py sql')
+        output = self._run_autocomplete()
+        self.assertEqual(output, ['sqlinitialdata sqlclear sqlreset 
sqlsequencereset sql sqlall sqlflush sqlcustom sqlindexes'])
+
+    def test_help(self):
+        "No errors, just an empty list if there are no autocomplete options"
+        self._user_input('django-admin.py help --')
+        output = self._run_autocomplete()
+        self.assertEqual(output, [''])
+
+    def test_runfcgi(self):
+        "Command arguments will be autocompleted"
+        self._user_input('django-admin.py runfcgi h')
+        output = self._run_autocomplete()
+        self.assertEqual(output, ['host='])
+
+    def test_app_completion(self):
+        "Application names will be autocompleted for an AppCommand"
+        self._user_input('django-admin.py sqlall a')
+        output = self._run_autocomplete()
+        app_labels = [name.split('.')[-1] for name in settings.INSTALLED_APPS]
+        self.assertEqual(set(output), set(label for label in app_labels if 
label.startswith('a')))

--

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=.


Reply via email to