async def test_main_exploits_exception(self, mock_cfg_load): mock_cfg_load.return_value = Future() mock_cfg_load.return_value.set_result(True) args = PropertyMock() args.configure_mock(cmd='scan') with patch('argparse.ArgumentParser.parse_args', return_value=args): with self.assertRaises(SystemExit): await main()
async def test_aucote_run_already(self, mock_fcntl, mock_cfg_load): mock_cfg_load.return_value = Future() mock_cfg_load.return_value.set_result(True) mock_fcntl.lockf = MagicMock(side_effect=IOError()) args = PropertyMock() args.configure_mock(cmd='service') with patch('argparse.ArgumentParser.parse_args', return_value=args): with patch('aucote.Aucote.run_scan'): with self.assertRaises(SystemExit): await main()
async def test_main_syncdb(self, cfg, mock_aucote, mock_cfg_load): mock_cfg_load.return_value = Future() mock_cfg_load.return_value.set_result(True) cfg._cfg = self.cfg._cfg args = PropertyMock() args.configure_mock(cmd='syncdb') with patch('argparse.ArgumentParser.parse_args', return_value=args): await main() self.assertEqual(mock_aucote.return_value.run_syncdb.call_count, 1)
async def test_scan_without_kudu(self, cfg, mock_cfg_load): mock_cfg_load.return_value = Future() mock_cfg_load.return_value.set_result(True) args = PropertyMock() args.configure_mock(cmd='scan') cfg._cfg = self.cfg._cfg cfg._cfg['kuduworker']['enable'] = False run_scan_future = Future() run_scan_future.set_result(MagicMock()) with patch('argparse.ArgumentParser.parse_args', return_value=args): with patch('aucote.Aucote.run_scan', return_value=run_scan_future): await main() self.assertIsInstance(self.aucote._kudu_queue, MagicMock)
async def test_main_service(self, mock_aucote, mock_cfg, mock_cfg_load): mock_cfg_load.return_value = Future() mock_cfg_load.return_value.set_result(True) args = PropertyMock() args.configure_mock(cmd='service') future = Future() future.set_result(MagicMock()) mock_aucote.return_value.run_scan.side_effect = ( future, SystemExit(), ) with patch('argparse.ArgumentParser.parse_args', return_value=args): with self.assertRaises(SystemExit): await main() mock_aucote.return_value.run_scan.assert_any_call() self.assertEqual(mock_aucote.return_value.run_scan.call_count, 2) mock_cfg.reload.assert_called_once_with( mock_cfg.__getitem__.return_value)