def test_add_unqualified_news_flash(self, utils): nf = NewsFlash(accident=False, resolution=["xxx"], road_segment_name="name") res = add_news_flash_to_cache(nf) utils.assert_not_called() assert res, "Should return True when no error occurred"
def test_add_news_flash_throws_exception(self, utils, get_engine): nf = NewsFlash(id=17, accident=True, resolution="כביש בינעירוני", road_segment_name="name") get_engine.side_effect = RuntimeError res = add_news_flash_to_cache(nf) assert not res, "Should return False when error occurred"
def test_add_qualified_news_flash(self, utils, get_engine): nf = NewsFlash(id=17, accident=True, resolution="כביש בינעירוני", road_segment_name="name") get_engine.execute.return_value = {} res = add_news_flash_to_cache(nf) invocations = utils.call_args_list utils.assert_has_calls( [unittest.mock.call(17, y, "he") for y in CONST.INFOGRAPHICS_CACHE_YEARS_AGO] ) for i in range(len(invocations)): self.assertEqual(invocations[i][0][0], 17, "incorrect news flash id") self.assertEqual(invocations[i][0][1], CONST.INFOGRAPHICS_CACHE_YEARS_AGO[i]) assert res, "Should return True when no error occurred"
def insert_new_newsflash(self, newsflash: NewsFlash) -> None: logging.info("Adding newsflash, is accident: {}, date: {}".format( newsflash.accident, newsflash.date)) self.db.session.add(newsflash) self.db.session.commit() infographics_data_cache_updater.add_news_flash_to_cache(newsflash)