コード例 #1
0
 def test_run_main_install(self, own_app_mock, copy_config_mock, add_app_to_path_mock):
     """
     tests run main script with install parameter returns no error
     """
     sys.argv = ['djangoapp', '-i', '-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),
          call(os.path.dirname(self.venv), self.app_user, self.app_user)],
         own_app_mock.mock_calls,
         own_app_mock.mock_calls
     )
     self.assertEqual([call(self.app_home, uwsgi=True)], copy_config_mock.mock_calls, copy_config_mock.mock_calls)
     self.assertEqual([call(self.app_home)], add_app_to_path_mock.mock_calls, add_app_to_path_mock.mock_calls)
     msgs = [
         'INFO: successfully cloned app_name to %s' % self.app_home,
         'INFO: successfully created virtualenv %s' % self.venv,
         'INFO: successfully installed: numpy==1.11.0',
         'INFO: successfully installed: biopython(1.66) cssselect(0.9.1) Django(1.9.5) django-debug-toolbar(1.4) '
         'django-with-asserts(0.0.1) lxml(3.6.0) numpy(1.11.0) psycopg2(2.6.1) requests(2.9.1) sqlparse(0.1.19)',
         'INFO: successfully installed: libpq-dev python3-numpy libxml2-dev libxslt1-dev zlib1g-dev',
         'INFO: changed ownership of %s to %s:%s' % (self.app_home, 'app_user', 'app_user'),
         'INFO: changed permissions of %s files to 400 and directories to 500' % self.app_home,
         'INFO: changed ownership of %s to %s:%s' % (os.path.dirname(self.venv), 'app_user', 'app_user'),
         'INFO: changed permissions of %s to %s' % (os.path.dirname(self.venv), '500'),
         'INFO: install django app exited with code 0'
     ]
     for m in msgs:
         self.log(m)
コード例 #2
0
 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)
コード例 #3
0
 def test_run_main_restart_uwsgi(self, sleep_mock, check_process_mock):
     """
     tests that main with parameter -u stop stops uwsgi
     """
     os.makedirs(os.path.join(self.fifo_dir, self.app_name))
     mocks.alt_bool = Alternate([True, False])
     sys.argv = ['djangoapp', '-u', 'restart', '-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(1)], sleep_mock.mock_calls, sleep_mock.mock_calls)
     self.assertEqual(
         [call('uwsgi')] * 2,
         check_process_mock.mock_calls,
         check_process_mock.mock_calls
     )
     msgs = [
         'INFO: stopped uwsgi server',
         'INFO: started uwsgi server',
         'INFO: changed permissions of %s to %s' % (os.path.join('/tmp', self.app_name), '777')
     ]
     for m in msgs:
         self.log(m)
コード例 #4
0
 def test_run_main_start_celery(self):
     """
     tests run main script with celery start parameter returns no error
     """
     sys.argv = ['djangoapp', '-c', 'start', '-l', 'DEBUG']
     djangoapp.DIST_VERSION = self.dist_version
     try:
         main()
     except SystemExit as sysexit:
         self.assertEqual('0', str(sysexit), 'main returned: ' + str(sysexit))
     msg = 'INFO: started celery and beat'
     self.log(msg)
コード例 #5
0
 def test_run_main_stop_celery(self):
     """
     tests run main script with celery stop parameter returns no error
     """
     os.makedirs(self.celery_pid_path, exist_ok=True)
     with open(os.path.join(self.celery_pid_path, 'w1.pid'), 'w') as pid:
         pid.write('celery pid')
     sys.argv = ['djangoapp', '-c', 'stop', '-l', 'DEBUG']
     djangoapp.DIST_VERSION = self.dist_version
     try:
         main()
     except SystemExit as sysexit:
         self.assertEqual('0', str(sysexit), 'main returned: ' + str(sysexit))
     msg = 'INFO: stopped celery and beat'
     self.log(msg)
コード例 #6
0
 def test_run_main_stop_uwsgi(self, check_process_mock):
     """
     tests that main with parameter -u stop stops uwsgi
     """
     os.makedirs(os.path.join(self.fifo_dir, self.app_name))
     mocks.alt_bool = Alternate([True])
     sys.argv = ['djangoapp', '-u', 'stop', '-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('uwsgi')],
         check_process_mock.mock_calls,
         check_process_mock.mock_calls
     )
     self.log('INFO: stopped uwsgi server')
コード例 #7
0
    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)
コード例 #8
0
 def test_run_main_restart_celery(self, stop_celery_mock):
     """
     tests run main script with celery stop parameter returns no error
     """
     os.makedirs(self.celery_pid_path, exist_ok=True)
     with open(os.path.join(self.celery_pid_path, 'w1.pid'), 'w') as pid:
         pid.write('celery pid')
     sys.argv = ['djangoapp', '-c', 'restart', '-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)],
         stop_celery_mock.mock_calls,
         stop_celery_mock.mock_calls
     )
     msgs = ['INFO: stopped celery and beat', 'INFO: started celery and beat']
     for msg in msgs:
         self.log(msg)
コード例 #9
0
 def test_run_main_start_uwsgi(self, check_process_mock):
     """
     tests run main script with uwsgi start parameter returns no error
     """
     mocks.alt_bool = Alternate([False])
     sys.argv = ['djangoapp', '-u', 'start', '-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('uwsgi')],
         check_process_mock.mock_calls,
         check_process_mock.mock_calls
     )
     msgs = [
         'INFO: started uwsgi server',
         'INFO: changed permissions of %s to %s' % (os.path.join('/tmp', self.app_name), '777'),
     ]
     for m in msgs:
         self.log(m)