Ejemplo n.º 1
0
 def test_update_settings(self):
     self.assertTrue(settings.DEBUG)
     args = ['manage.py', 'settings', '--django_debug=False', 'DEBUG']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     self.assertTrue('False' in self.output)
Ejemplo n.º 2
0
 def test_version_is_printed_once(self):
     args = ['manage.py', '--version']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     expected = get_version()
     self.assertEqual(1, self.output.count(expected))
Ejemplo n.º 3
0
 def test_version_is_printed_once(self):
     args = ['manage.py', '--version']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     expected = get_version()
     self.assertEqual(1, self.output.count(expected))
Ejemplo n.º 4
0
 def test_update_settings(self):
     self.assertTrue(settings.DEBUG)
     args = ['manage.py', 'settings', '--django_debug=False', 'DEBUG']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     self.assertTrue('False' in self.output)
Ejemplo n.º 5
0
 def test_noargs_doesnt_error(self):
     args = ['manage.py']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     except SystemExit:
         # Django <= 1.3 uses SystemExit to terminate management
         # command
         pass
     finally:
         self.end_capture()
     self.assertFalse('Unknown command' in self.output)
Ejemplo n.º 6
0
 def test_noargs_doesnt_error(self):
     args = ['manage.py']
     utility = GlueManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     except SystemExit:
         # Django <= 1.3 uses SystemExit to terminate management
         # command
         pass
     finally:
         self.end_capture()
     self.assertFalse('Unknown command' in self.output)
Ejemplo n.º 7
0
    def setUp(self):
        super(GlueManagementUtilityTestCase, self).setUp()

        self.util = GlueManagementUtility()
Ejemplo n.º 8
0
class GlueManagementUtilityTestCase(ConfigGlueDjangoCommandTestCase):
    def setUp(self):
        super(GlueManagementUtilityTestCase, self).setUp()

        self.util = GlueManagementUtility()

    def execute(self):
        self.begin_capture()
        try:
            self.util.execute()
        finally:
            self.end_capture()

    def test_execute_no_args(self):
        self.util.argv = ['']
        self.assertRaises(SystemExit, self.execute)
        self.assertEqual(self.capture['stderr'],
                         "Type '%s help' for usage.\n" % self.util.prog_name)

    def test_execute_help(self):
        self.util.argv = ['', 'help']
        self.assertRaises(SystemExit, self.execute)
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_help_option(self):
        self.util.argv = ['', '--help']
        self.execute()
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_help_for_command(self):
        self.util.argv = ['', 'help', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])

    def test_execute_version(self):
        from django import get_version
        self.util.argv = ['', '--version']
        self.execute()
        self.assertTrue(get_version() in self.capture['stdout'])

    def test_execute(self):
        self.util.argv = ['', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])

    def test_execute_settings_exception(self):
        from django.conf import settings
        wrapped = getattr(settings, self.wrapped_settings)
        old_CONFIGGLUE_PARSER = wrapped.__CONFIGGLUE_PARSER__
        del wrapped.__CONFIGGLUE_PARSER__

        try:
            self.util.argv = ['', 'help']
            self.assertRaises(SystemExit, self.execute)
            self.assertTrue(
                self.util.main_help_text() in self.capture['stderr'])
        finally:
            wrapped.__CONFIGGLUE_PARSER__ = old_CONFIGGLUE_PARSER

    @patch('django_configglue.utils.update_settings')
    def test_execute_configglue_exception(self, mock_update_settings):
        mock_update_settings.side_effect = Exception()

        self.util.argv = ['', 'help']
        self.assertRaises(SystemExit, self.execute)
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_with_schema_options(self):
        self.util.argv = ['', '--django_debug=False', 'help', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])
Ejemplo n.º 9
0
    def setUp(self):
        super(GlueManagementUtilityTestCase, self).setUp()

        self.util = GlueManagementUtility()
Ejemplo n.º 10
0
class GlueManagementUtilityTestCase(ConfigGlueDjangoCommandTestCase):
    def setUp(self):
        super(GlueManagementUtilityTestCase, self).setUp()

        self.util = GlueManagementUtility()

    def execute(self):
        self.begin_capture()
        try:
            self.util.execute()
        finally:
            self.end_capture()

    def test_execute_no_args(self):
        self.util.argv = ['']
        self.assertRaises(SystemExit, self.execute)
        self.assertEqual(self.capture['stderr'],
            "Type '%s help' for usage.\n" % self.util.prog_name)

    def test_execute_help(self):
        self.util.argv = ['', 'help']
        self.assertRaises(SystemExit, self.execute)
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_help_option(self):
        self.util.argv = ['', '--help']
        self.execute()
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_help_for_command(self):
        self.util.argv = ['', 'help', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])

    def test_execute_version(self):
        from django import get_version
        self.util.argv = ['', '--version']
        self.execute()
        self.assertTrue(get_version() in self.capture['stdout'])

    def test_execute(self):
        self.util.argv = ['', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])

    def test_execute_settings_exception(self):
        from django.conf import settings
        wrapped = getattr(settings, self.wrapped_settings)
        old_CONFIGGLUE_PARSER = wrapped.__CONFIGGLUE_PARSER__
        del wrapped.__CONFIGGLUE_PARSER__

        try:
            self.util.argv = ['', 'help']
            self.assertRaises(SystemExit, self.execute)
            self.assertTrue(
                self.util.main_help_text() in self.capture['stderr'])
        finally:
            wrapped.__CONFIGGLUE_PARSER__ = old_CONFIGGLUE_PARSER

    @patch('django_configglue.utils.update_settings')
    def test_execute_configglue_exception(self, mock_update_settings):
        mock_update_settings.side_effect = Exception()

        self.util.argv = ['', 'help']
        self.assertRaises(SystemExit, self.execute)
        self.assertTrue(self.util.main_help_text() in self.capture['stderr'])

    def test_execute_with_schema_options(self):
        self.util.argv = ['', '--django_debug=False', 'help', 'settings']
        self.execute()
        self.assertTrue('Show settings attributes' in self.capture['stdout'])