def test_run_main_remove_app(self, own_app_mock, check_process_mock): """ tests that main with parameter -x removes app """ clone_app_mock(self.app_home) os.makedirs(os.path.join(self.fifo_dir, self.app_name)) mocks.alt_bool = Alternate([True]) sys.argv = ['djangoapp', '-x', '-l', 'DEBUG'] djangoapp.DIST_VERSION = self.dist_version try: main() except SystemExit as sysexit: self.assertEqual('0', str(sysexit), 'main returned: ' + str(sysexit)) self.assertEqual( [call(self.app_home, self.app_user, self.app_user)], own_app_mock.mock_calls, own_app_mock.mock_calls ) self.assertEqual( [call('uwsgi')], check_process_mock.mock_calls, check_process_mock.mock_calls ) msgs = [ 'INFO: stopped uwsgi server', 'INFO: removed %s' % self.app_name, ] for m in msgs: self.log(m)
def test_clone_app_mock(self): """ tests clone_app_mock creates media and static files """ if DIST_VERSION == '14.04': subprocess.check_call = MagicMock() else: if DIST_VERSION == '16.04': subprocess.run = MagicMock() clone_app_mock(APP_HOME_TMP) static_files = [ os.path.join(APP_HOME_TMP, 'app_name/static/static_file'), os.path.join(APP_HOME_TMP, 'app_name/media/media_file'), os.path.join(APP_HOME_TMP, 'app_name/uwsgi_params'), os.path.join(APP_HOME_TMP, 'app_name/static/base/site_down/index.html'), ] for static_file in static_files: self.assertTrue(os.path.isfile(static_file), static_file)
def test_run_main_create_venv(self): """ tests that main with parameter -x removes app """ clone_app_mock(self.app_home) os.makedirs(os.path.join(self.fifo_dir, self.app_name)) mocks.alt_bool = Alternate([True]) sys.argv = ['djangoapp', '-e', '-l', 'DEBUG'] djangoapp.DIST_VERSION = self.dist_version try: main() except SystemExit as sysexit: self.assertEqual('0', str(sysexit), 'main returned: ' + str(sysexit)) msgs = [ 'INFO: successfully created virtualenv %s' % self.venv, 'INFO: successfully updated pip for virtualenv %s' % self.venv, ] for m in msgs: self.log(m)
def test_remove_app(self): """ tests that remove_app removes all files in app """ user = getpass.getuser() clone_app_mock(self.app_home) site_files = [ os.path.join(self.app_home, self.app_name, 'static/static_file'), os.path.join(self.app_home, self.app_name, 'media/media_file'), os.path.join(self.app_home, '%s_uwsgi_params' % self.app_name), os.path.join(self.app_home, self.app_name, 'static/base/site_down/index.html'), os.path.join(self.app_home, self.app_name) ] install_django_app = InstallDjangoApp( self.dist_version, self.log_file, self.log_level, venv=self.venv, git_repo=self.git_repo, ) install_django_app.remove_app(self.app_home, user) for s in site_files: self.assertFalse(os.path.exists(s), s) self.log('INFO: removed %s' % self.app_name) self.assertTrue(os.path.exists(self.app_home))