def test_updateHistoryShouldUpdateLastUpdate(self, tmp_path): history = DownloadHistory() lastupdatePattern = re.compile(r'^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$') history.updateHistory('user1', '112233') lastupdate = history._history['user1']['lastUpdate'] assert lastupdate != TESTHISTORIES['user1']['lastUpdate'] assert lastupdatePattern.match(lastupdate)
def test_getHistoryFromExistingHistory(self, setup_tmp_path): history = DownloadHistory() history.loadFromFile(setup_tmp_path / constants.FILENAME_HISTORY) for username in TESTHISTORIES.keys(): assert history.getHistory(username) == TESTHISTORIES[username]['tweetId'] history.updateHistory('user1', '2') history.updateHistory('user1', '3') history.updateHistory('user1', '4') assert history.getHistory('user1') == '4'
def __init__(self, app_path): logging.info('Initializing objects') self._settings = Settings(app_path / constants.FILENAME_SETTINGS) self._history = DownloadHistory() self._retriever = TweetsRetriever_TwitterAPI(self._history, self._settings) self._scheduler = DltaskScheduler(app_path) self._abort = AbortFlag() logging.info('Finished initializing objects')
def test_writeToFileForExistingHistory(self, setup_tmp_path): history = DownloadHistory() usernames = ['user1', 'user2', 'user3'] tweetIds = ['1--1--1', '2--2--2', '3--3--3'] history_path = setup_tmp_path / constants.FILENAME_HISTORY history.loadFromFile(history_path) for username, tweetId in zip(usernames, tweetIds): history.updateHistory(username, tweetId) history.writeToFile(history_path) assert history_path.exists() with history_path.open('r', encoding='utf-8') as file: contentJson = json.load(file) for username, tweetId in zip(usernames, tweetIds): assert contentJson[username]['tweetId'] == tweetId
def test_writeToFileForNonExistantHistory(self, tmp_path): history = DownloadHistory() usernames = ['user1', 'user2', 'user3'] tweetIds = ['1111', '2222', '3333'] history_path = tmp_path / constants.FILENAME_HISTORY assert not history_path.exists() for username, tweetId in zip(usernames, tweetIds): history.updateHistory(username, tweetId) history.writeToFile(history_path) assert history_path.exists() with history_path.open('r', encoding='utf-8') as file: contentJson = json.load(file) for username, tweetId in zip(usernames, tweetIds): assert contentJson[username]['tweetId'] == tweetId
def test_GetHistoryFromNonExistantHistory(self, tmp_path): history = DownloadHistory() assert history.getHistory('user1') == None history.updateHistory('user1', '112233') assert history.getHistory('user1') == '112233' history.updateHistory('user1', '2') history.updateHistory('user1', '3') history.updateHistory('user1', '4') assert history.getHistory('user1') == '4'
def test_UpdateHistory(self, tmp_path, ): history = DownloadHistory() history.updateHistory('user1', '112233') assert history.getHistory('user1') == '112233'
def test_downloadHistoryConstruction_whenNotExist(self, tmp_path): DownloadHistory()
def test_downloadHistoryConstruction(self, setup_tmp_path): DownloadHistory()