Ticket #12221: completion_tests.diff

File completion_tests.diff, 4.4 KB (added by Eric Holscher, 14 years ago)

Tests for current bash completion.

  • new file tests/regressiontests/bash_completion/management/commands/test_command.py

    commit eceda439ab1a950230bd5f792d3f8baef86a56a7
    Author: Eric Holscher <eric@ericholscher.com>
    Date:   Sun Nov 15 14:36:58 2009 -0600
    
        Add tests for bash completion before mucking with it.
    
    diff --git a/tests/regressiontests/bash_completion/__init__.py b/tests/regressiontests/bash_completion/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/bash_completion/management/__init__.py b/tests/regressiontests/bash_completion/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/bash_completion/management/commands/__init__.py b/tests/regressiontests/bash_completion/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/bash_completion/management/commands/test_command.py b/tests/regressiontests/bash_completion/management/commands/test_command.py
    new file mode 100644
    index 0000000..7e47806
    - +  
     1import sys, os
     2from optparse import OptionParser, make_option
     3
     4from django.core.management.base import BaseCommand
     5
     6class Command(BaseCommand):
     7    option_list = BaseCommand.option_list + (
     8        make_option("--list", action="store_true", dest="list",
     9                    help="Print all options"),
     10    )
     11
     12    def handle(self, *args, **options):
     13        pass
  • new file tests/regressiontests/bash_completion/tests.py

    diff --git a/tests/regressiontests/bash_completion/models.py b/tests/regressiontests/bash_completion/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/bash_completion/tests.py b/tests/regressiontests/bash_completion/tests.py
    new file mode 100644
    index 0000000..74e860e
    - +  
     1"""
     2A series of tests to establish that the command-line bash completion works.
     3"""
     4import os
     5import unittest
     6import sys
     7import StringIO
     8
     9from django.core.management import ManagementUtility
     10
     11class BashCompletionTests(unittest.TestCase):
     12    """
     13    Testing the Python level bash completion code.
     14    This requires settings up the environment like if we got passed data
     15    from bash.
     16    """
     17
     18    def setUp(self):
     19        os.environ['DJANGO_AUTO_COMPLETE'] = '1'
     20        self.output = StringIO.StringIO()
     21        self.old_stdout = sys.stdout
     22        sys.stdout = self.output
     23
     24    def tearDown(self):
     25        sys.stdout = self.old_stdout
     26
     27    def _user_input(self, input_str):
     28        os.environ['COMP_WORDS'] = input_str
     29        os.environ['COMP_CWORD'] = str(len(input_str.split()) - 1)
     30        sys.argv = input_str.split(' ')
     31
     32    def _run_autocomplete(self):
     33        util = ManagementUtility(argv=sys.argv)
     34        try:
     35            util.autocomplete()
     36        except SystemExit:
     37            pass
     38        return self.output.getvalue().strip().split('\n')
     39
     40    def test_django_admin_py(self):
     41        self._user_input('django-admin.py sqlall --v')
     42        output = self._run_autocomplete()
     43        self.assertEqual(output, ['--verbosity='])
     44
     45    def test_manage_py(self):
     46        self._user_input('manage.py sqlall --v')
     47        output = self._run_autocomplete()
     48        self.assertEqual(output, ['--verbosity='])
     49
     50    def test_custom_command(self):
     51        self._user_input('django-admin.py test_command --l')
     52        output = self._run_autocomplete()
     53        self.assertEqual(output, ['--list'])
     54
     55    def test_subcommands(self):
     56        self._user_input('django-admin.py sql')
     57        output = self._run_autocomplete()
     58        self.assertEqual(output, ['sqlinitialdata sqlclear sqlreset sqlsequencereset sql sqlall sqlflush sqlcustom sqlindexes'])
     59
     60    def test_help(self):
     61        #Help should return nothing since it takes no args.
     62        self._user_input('django-admin.py help --')
     63        output = self._run_autocomplete()
     64        self.assertEqual(output, [''])
     65
     66    def test_runfcgi(self):
     67        #Help should return nothing since it takes no args.
     68        self._user_input('django-admin.py runfcgi h')
     69        output = self._run_autocomplete()
     70        self.assertEqual(output, ['host='])
     71
     72    def test_app_completion(self):
     73        #Help should return nothing since it takes no args.
     74        self._user_input('django-admin.py sqlall a')
     75        output = self._run_autocomplete()
     76        self.assertEqual(output, ['auth', 'admin'])
     77 No newline at end of file
Back to Top