def test_copy_config_copies_config_files_to_app(self): """ tests that config files are copied to app and action is logged """ os.makedirs(os.path.join(self.app_home, self.app_name, self.app_name)) os.makedirs(os.path.join(os.path.dirname(self.app_home), 'conf.d')) conf = [ {'file': 'settings.json', 'move_to': os.path.join(self.app_home, self.app_name)}, {'file': '%s_uwsgi.ini' % self.app_name, 'move_to': self.app_home} ] for f in conf: with open(os.path.join(os.path.dirname(self.app_home), 'conf.d', f['file']), 'w') as config: config.write('%s file\n' % f['file']) install_django_app = InstallDjangoApp( self.dist_version, self.log_file, self.log_level, venv=self.venv, git_repo=self.git_repo ) install_django_app.copy_config(self.app_home) for f in conf: self.assertTrue(os.path.isfile(os.path.join(f['move_to'], f['file'])), f['file']) with open(os.path.join(f['move_to'], f['file'])) as file: file_list = [l for l in file] self.assertEqual(['%s file\n' % f['file']], file_list, file_list) self.log('INFO: app configuration file %s was copied to app' % f['file'])
def copy_config_exits_when_conf_file_missing(self, conf): """ helper function that tests that copy_config exits when the conf file is missing :param conf: missing conf file """ install_django_app = InstallDjangoApp( self.dist_version, self.log_file, self.log_level, venv=self.venv, git_repo=self.git_repo ) try: install_django_app.copy_config(self.app_home) except SystemExit as error: self.assertEqual(1, error.code, 'copy_config' + ' exited with: ' + str(error)) self.log('ERROR: could not copy %s' % conf)
def test_copy_config_does_nothing_when_config_files_are_already_present_in_app(self): """ tests that copy_config does nothing when config files are already present in app """ conf = [ {'file': 'settings.json', 'move_to': os.path.join(self.app_home, self.app_name)}, {'file': '%s_uwsgi.ini' % self.app_name, 'move_to': self.app_home} ] os.makedirs(os.path.join(self.app_home, self.app_name, self.app_name)) for f in conf: with open(os.path.join(f['move_to'], f['file']), 'w') as file: file.write('%s file\n' % f['file']) install_django_app = InstallDjangoApp( self.dist_version, self.log_file, self.log_level, venv=self.venv, git_repo=self.git_repo ) install_django_app.copy_config(self.app_home) for f in conf: self.log('INFO: %s is already present in %s' % (f['file'], self.app_name))