def test_guess_prod_settings_file(self): settings_path = os.path.join(self.project_dir, self.project_name, 'settings.py') prod_settings_path = os.path.join(self.project_dir, self.project_name, 'settings_prod.py') shutil.copyfile(settings_path, prod_settings_path) self.assertEqual(utils.guess_settings_path(self.project_dir), prod_settings_path)
def test_use_variable_for_settings_module(self): manage_py_path = os.path.join(self.project_dir, 'manage.py') with open(manage_py_path) as f: file_content = f.read() with open(manage_py_path, 'wt') as f: file_content = file_content.replace( '\'{}.settings\''.format(self.project_name), 'module_variable') f.write(file_content) path = utils.guess_settings_path(self.project_dir) self.assertIsNone(path)
def test_double_quotation_mark_for_module_name(self): manage_py_path = os.path.join(self.project_dir, 'manage.py') with open(manage_py_path) as f: file_content = f.read() with open(manage_py_path, 'wt') as f: file_content = file_content.replace( '\'{}.settings\''.format(self.project_name), '"{}.settings"'.format(self.project_name)) f.write(file_content) path = utils.guess_settings_path(self.project_dir) self.assertEqual( path, os.path.join(self.project_dir, self.project_name, 'settings.py'))
def test_settings_in_subdirectory(self): os.mkdir(os.path.join(self.project_dir, self.project_name, 'settings')) settings_path = os.path.join(self.project_dir, self.project_name, 'settings.py') new_settings_path = os.path.join(self.project_dir, self.project_name, 'settings', 'dev.py') shutil.move(settings_path, new_settings_path) prod_settings_path = os.path.join(self.project_dir, self.project_name, 'settings', 'prod.py') shutil.copyfile(new_settings_path, prod_settings_path) manage_py_path = os.path.join(self.project_dir, 'manage.py') with open(manage_py_path) as f: file_content = f.read() with open(manage_py_path, 'wt') as f: file_content = file_content.replace( '{}.settings'.format(self.project_name), '{}.settings.dev"'.format(self.project_name)) f.write(file_content) path = utils.guess_settings_path(self.project_dir) self.assertEqual(path, prod_settings_path)
def test_settings_module_in_manage_py_but_not_found(self): os.remove( os.path.join(self.project_dir, self.project_name, 'settings.py')) self.assertIsNone(utils.guess_settings_path(self.project_dir))
def test_manage_py_not_found(self): os.remove(os.path.join(self.project_dir, 'manage.py')) self.assertIsNone(utils.guess_settings_path(self.project_dir))
def test_guess_default_settings_file(self): path = utils.guess_settings_path(self.project_dir) self.assertEqual( path, os.path.join(self.project_dir, self.project_name, 'settings.py'))