Example #1
0
 def test_create_log_for_stdout(self):
     opts = FakeOptions(app_path="/some/path",
                        no_daemon=True,
                        stdout=True,
                        debug=None,
                        chroot=None)
     with patch('logging.StreamHandler'):
         cli = Cli()
         cli._set_loggers(opts)
         self.assertEquals(1, logging.StreamHandler.call_count)
Example #2
0
 def test_daemon_should_create_normal_logs(self):
     opts = FakeOptions(app_path="/some/path",
                        no_daemon=True,
                        stdout=False,
                        debug=None,
                        chroot=None)
     with patch('logging.FileHandler'):
         cli = Cli()
         cli._set_loggers(opts)
         self.assertEquals(1, logging.FileHandler.call_count)
         self.assertEquals((("/some/path/logs/wsgid.log", ), {}),
                           logging.FileHandler.call_args)
Example #3
0
    def setUp(self, *args):
        self.cli = Cli()
        # As we are dealing with a command line test, we have do clean the passed arguments
        # so the tested applications does not try to use them
        sys.argv[1:] = []
        self.fake_app_path = os.path.join(fullpath(__file__), 'app-path')

        # Ok, not pretty but better than re-implementing this in python
        os.system("rm -rf {0}".format(os.path.join(self.fake_app_path,
                                                   'pid/')))
        self.cli.options = parser._parse_args()
        self.cli.options.app_path = self.fake_app_path

        CommandInit().run(FakeOptions(app_path=self.fake_app_path))
Example #4
0
 def test_start_workers_when_nodaemon(self, *args):
     path = os.path.join(FIXTURES_PATH, 'nodaemon-app')
     initcmd = CommandInit()
     initcmd.run(FakeOptions(app_path=path))
     with patch('daemon.DaemonContext', new=MagicMock()):
         with patch.object(Cli, '_create_worker'):
             with patch.object(Cli, 'validate_input_params'):
                 with patch.object(Cli, '_wait_workers'):
                     daemon.DaemonContext.__enter__ = Mock()
                     daemon.DaemonContext.__exit__ = Mock()
                     sys.argv[1:] = [
                         '--workers=3', '--no-daemon',
                         '--app-path={0}'.format(path)
                     ]
                     cli = Cli()
                     cli.run()
                     self.assertEquals(3, cli._create_worker.call_count)
                     self.assertEquals(1, cli._wait_workers.call_count)
Example #5
0
 def test_clean_pid_files_on_keyboard_interrupt(self):
     path = os.path.join(FIXTURES_PATH, 'clean-pids-app')
     initcmd = CommandInit()
     opts = FakeOptions(app_path=path)
     initcmd.run(opts)
     open(os.path.join(path, 'pid/master/3340.pid'), 'w')
     open(os.path.join(path, 'pid/worker/2736.pid'), 'w')
     open(os.path.join(path, 'pid/worker/3847.pid'), 'w')
     with patch('os.wait'):
         with patch('os.getpid'):
             os.getpid.side_effect = lambda: 3340
             os.wait.side_effect = KeyboardInterrupt()
             cli = Cli()
             cli.options = opts
             cli.log = Mock()
             cli.workers = [2736, 3847]
             cli._wait_workers()
             app = WsgidApp(path)
             self.assertEquals([], app.master_pids())
             self.assertEquals([], app.worker_pids())