def test_get_most_recent_when_many_have_same_latest(self): updates = UpdateCollection([ Update(TestUpdateCollection._TARGET, datetime.max, self.metadata), Update(TestUpdateCollection._TARGET, datetime.min, self.metadata), Update(TestUpdateCollection._TARGET, datetime.max, self.metadata) ]) self.assertCountEqual(updates.get_most_recent(), [updates[0], updates[2]])
def update_since_file(update_collection: UpdateCollection): nonlocal since_file if update_collection: last_retrieval_time = update_collection.get_most_recent()[0].timestamp with open(since_file, "w") as f: f.write(str(int(last_retrieval_time.timestamp())))
def _assert_logged_updated(self, updates: UpdateCollection): """ TODO :param updates: :return: """ self.assertEqual(self.logger.record.call_count, 1) args = self.logger.record.call_args[0] self.assertEqual(args[0], MEASURED_RETRIEVAL) self.assertEqual(DatetimeISOFormatJSONDecoder().decode(args[1][MEASURED_RETRIEVAL_STARTED_AT]), CURRENT_CLOCK_TIME) self.assertGreaterEqual(args[1][MEASURED_RETRIEVAL_DURATION], TIME_TAKEN_TO_DO_RETRIEVE) self.assertEqual(args[1][MEASURED_RETRIEVAL_UPDATE_COUNT], len(updates)) logged_most_recent_retrived = args[1][MEASURED_RETRIEVAL_MOST_RECENT_RETRIEVED] if len(updates) > 0: self.assertEqual(DatetimeISOFormatJSONDecoder().decode(logged_most_recent_retrived), updates.get_most_recent()[0].timestamp) else: self.assertIsNone(logged_most_recent_retrived)