From de714d0382431bc59e5e5bc7162e243dce04db64 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Mon, 7 Dec 2015 11:49:31 +0100 Subject: [PATCH] Force os.environ keys to correct string type --- djangocms_installer/django/__init__.py | 12 ++++++------ tests/config.py | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/djangocms_installer/django/__init__.py b/djangocms_installer/django/__init__.py index 64e0c44..92cc4a4 100644 --- a/djangocms_installer/django/__init__.py +++ b/djangocms_installer/django/__init__.py @@ -28,8 +28,8 @@ def create_project(config_data): Call django-admin to create the project structure """ env = deepcopy(dict(os.environ)) - env['DJANGO_SETTINGS_MODULE'] = ('{0}.settings'.format(config_data.project_name)) - env['PYTHONPATH'] = os.pathsep.join(map(shlex_quote, sys.path)) + env[str('DJANGO_SETTINGS_MODULE')] = str('{0}.settings'.format(config_data.project_name)) + env[str('PYTHONPATH')] = str(os.pathsep.join(map(shlex_quote, sys.path))) kwargs = {} args = [] if config_data.template: @@ -388,8 +388,8 @@ def _build_settings(config_data): def setup_database(config_data): with chdir(config_data.project_directory): env = deepcopy(dict(os.environ)) - env['DJANGO_SETTINGS_MODULE'] = ('{0}.settings'.format(config_data.project_name)) - env['PYTHONPATH'] = os.pathsep.join(map(shlex_quote, sys.path)) + env[str('DJANGO_SETTINGS_MODULE')] = str('{0}.settings'.format(config_data.project_name)) + env[str('PYTHONPATH')] = str(os.pathsep.join(map(shlex_quote, sys.path))) commands = [] if config_data.django_version < 1.7: @@ -431,8 +431,8 @@ def load_starting_page(config_data): """ with chdir(config_data.project_directory): env = deepcopy(dict(os.environ)) - env['DJANGO_SETTINGS_MODULE'] = ('{0}.settings'.format(config_data.project_name)) - env['PYTHONPATH'] = os.pathsep.join(map(shlex_quote, sys.path)) + env[str('DJANGO_SETTINGS_MODULE')] = str('{0}.settings'.format(config_data.project_name)) + env[str('PYTHONPATH')] = str(os.pathsep.join(map(shlex_quote, sys.path))) subprocess.check_call([sys.executable, 'starting_page.py'], env=env) for ext in ['py', 'pyc', 'json']: try: diff --git a/tests/config.py b/tests/config.py index dd20ab9..93edf86 100644 --- a/tests/config.py +++ b/tests/config.py @@ -755,7 +755,6 @@ class TestBaseConfig(unittest.TestCase): def __init__(self, *args, **kwargs): self.config_not_exists = self.conf('config-dump.ini') - super(TestBaseConfig, self).__init__(*args, **kwargs) def tearDown(self): @@ -774,12 +773,10 @@ def unused(self, config_data): if hasattr(config_data, 'requirements'): delattr(config_data, 'requirements') - #@patch('sys.stdout') - #@patch('sys.stderr') def test_parse_config_file(self, *args): """Tests .config.__init__._parse_config_file function.""" with self.assertRaises(SystemExit) as error: - config_data = config.parse(self.args[0:1] + [self.conf('config-not-exists.ini')] + self.args[1:]) + config.parse(self.args[0:1] + [self.conf('config-not-exists.ini')] + self.args[1:]) self.assertEqual(7, error.exception.code) args = self.args[0:1] + [self.conf('config-01.ini')] + self.args[1:] @@ -835,10 +832,10 @@ def test_dump_config_file(self, *args): config_exists = self.conf('config-01.ini') with self.assertRaises(SystemExit) as error: - config_data = config.parse(['--config-dump', config_exists] + self.args[1:] + ['-p', '.']) + config.parse(['--config-dump', config_exists] + self.args[1:] + ['-p', '.']) self.assertEqual(8, error.exception.code) - config_data = config.parse(['--config-dump', self.config_not_exists] + self.args[1:] + ['-p', '.']) + config.parse(['--config-dump', self.config_not_exists] + self.args[1:] + ['-p', '.']) self.assertTrue(os.path.isfile(self.config_not_exists)) fixture = copy.copy(self.config_fixture)