示例#1
0
def main_config():
    """
    django-develop-config CLI entry point.
    """
    if not utils.is_inside_virtual_env():
        _fail('Run django-develop-config inside a virtualenv')

    dd = _get_DjangoDevelop()  # type: DjangoDevelop
    try:
        [base_settings_module] = sys.argv[1:2]
    except ValueError:
        print('Usage: django-develop-config <base_settings_module>')
        print()

        # Show current configuration
        if dd.instance_path.exists():
            print('Instance directory: {}'.format(dd.instance_path))
            print()
        config = dd.read_config()
        base_settings_module = config.get('django-develop', 'base_settings_module', fallback=None)
        print('Current base settings module: {}'.format(
            utils.SUCCESS(base_settings_module) if base_settings_module else
            'not configured'))
        print()

        # TODO: Add CLI flag for include_problems?
        utils.print_candidate_settings()

        raise SystemExit(2)
    else:
        dd.init_instance(base_settings_module)
示例#2
0
    def test_no_candidates(self):
        """
        Printing out no candidates.
        """
        with mock.patch('sys.path', []):
            with self._patch_stdout() as stdout:
                utils.print_candidate_settings()

        self.assertEqual(stdout.getvalue(), dedent("""\
            Looking for usable Django settings modules in Python path... None found.

            """))
示例#3
0
    def test_likely_candidates(self):
        """
        Printing a likely candidate.
        """
        with self._patch_stdout() as stdout:
            utils.print_candidate_settings()

        self.assertEqual(stdout.getvalue(), dedent("""\
            Looking for usable Django settings modules in Python path... Found:

                In {}:

                    test_examples.likely_settings

            """.format(TEST_ROOT)))
示例#4
0
    def test_all_candidates(self):
        """
        Printing and reporting problematic candidates too.
        """
        with mock.patch('sys.path', [TEST_ROOT]):
            with self._patch_stdout() as stdout:
                utils.print_candidate_settings(include_problems=True)

        self.assertEqual(stdout.getvalue(), dedent("""\
            Looking for usable Django settings modules in Python path... Found:

                In {}:

                    test_examples.error_settings (import raised NameError)
                    test_examples.likely_settings
                    test_examples.no_likely_settings (no likely setting names)
                    test_examples.no_settings (no uppercase names)

            """.format(TEST_ROOT)))