Esempio n. 1
0
    def test_basic_auth(self, mock_acceptor_pool: mock.Mock,
                        mock_flags: mock.Mock, mock_sleep: mock.Mock) -> None:
        mock_sleep.side_effect = KeyboardInterrupt()

        input_args = ['--basic-auth', 'user:pass']
        flags = Flags.initialize(input_args=input_args)
        mock_flags.initialize = lambda *args, **kwargs: flags

        main(input_args=input_args)
        mock_acceptor_pool.assert_called_with(flags=flags,
                                              work_klass=HttpProtocolHandler)
        self.assertEqual(flags.auth_code, b'Basic dXNlcjpwYXNz')
Esempio n. 2
0
    def test_main_py3_runs(self, mock_is_py3: mock.Mock,
                           mock_acceptor_pool: mock.Mock,
                           mock_flags: mock.Mock, mock_print: mock.Mock,
                           mock_sleep: mock.Mock) -> None:
        mock_sleep.side_effect = KeyboardInterrupt()

        input_args = ['--basic-auth', 'user:pass']
        flags = Flags.initialize(input_args=input_args)
        mock_flags.initialize = lambda *args, **kwargs: flags

        mock_is_py3.return_value = True
        main(num_workers=1)
        mock_is_py3.assert_called()
        mock_print.assert_not_called()
        mock_acceptor_pool.assert_called()
        mock_acceptor_pool.return_value.setup.assert_called()
Esempio n. 3
0
    def test_init_with_no_arguments(self, mock_logging_config: mock.Mock,
                                    mock_acceptor_pool: mock.Mock,
                                    mock_flags: mock.Mock,
                                    mock_sleep: mock.Mock) -> None:
        mock_sleep.side_effect = KeyboardInterrupt()

        input_args: List[str] = []
        flags = Flags.initialize(input_args=input_args)
        mock_flags.initialize = lambda *args, **kwargs: flags

        main()

        mock_logging_config.assert_called_with(level=logging.INFO,
                                               format=DEFAULT_LOG_FORMAT)
        mock_acceptor_pool.assert_called_with(
            flags=flags,
            work_klass=HttpProtocolHandler,
        )
        mock_acceptor_pool.return_value.setup.assert_called()
        mock_acceptor_pool.return_value.shutdown.assert_called()
        mock_sleep.assert_called()