def setUp(self): super(RunnerTest, self).setUp() self.fake_process = type("FakeProcess", (object,), {})() self.fake_process = Mock() self.fake_container = type("FakeContainer", (object,), {})() self.fake_container.config = {} self.fake_process_constructor = Mock(return_value=self.fake_process) MonkeyPatcher.patch(multiprocessing, "Process", self.fake_process_constructor) self.runner = Runner(self.fake_container)
def setUp(self): super(RunnerTest, self).setUp() self.fake_process = type("FakeProcess", (object, ), {})() self.fake_process = Mock() self.fake_container = type("FakeContainer", (object, ), {})() self.fake_container.config = {} self.fake_process_constructor = Mock(return_value=self.fake_process) MonkeyPatcher.patch(multiprocessing, "Process", self.fake_process_constructor) self.runner = Runner(self.fake_container)
def test_update_search_index(self): container = type("FakeContainer", (object,), {})() container.search_updater = type("FakeSearchUpdater", (object,), {})() container.search_updater.run = Mock() _create_container = Mock(return_value=container) MonkeyPatcher.patch(utils, "_create_container", _create_container) fake_config = {"fake": "blah"} utils.update_search_index(fake_config) _create_container.assert_called_with(fake_config) self.assertTrue(container.search_updater.run.called)
def setup_storage(self): """ This is important for comparing metadata later on because we "assertEqual" but the date would be different every time the test was run. The solution was to patch _to_utc to always return the same date. """ get_created_date = Mock(return_value=meta_utils.CREATED_DATE) MonkeyPatcher.patch(Initializer, "_get_created_date", get_created_date)
def test_update_search_index(self): container = type("FakeContainer", (object, ), {})() container.search_updater = type("FakeSearchUpdater", (object, ), {})() container.search_updater.run = Mock() _create_container = Mock(return_value=container) MonkeyPatcher.patch(utils, "_create_container", _create_container) fake_config = {"fake": "blah"} utils.update_search_index(fake_config) _create_container.assert_called_with(fake_config) self.assertTrue(container.search_updater.run.called)
def mock_configure_logger(self): logger = logging.getLogger() configure_file_logger = Mock(return_value=logger) MonkeyPatcher.patch(background_utils, "configure_file_logger", configure_file_logger) return configure_file_logger
def setUp(self): super(UtilsTest, self).setUp() self.run_process_mock = Mock() MonkeyPatcher.patch(Runner, "_run_process", self.run_process_mock)