def test_get_entity_updates(self):
     updates = UpdateCollection([
         Update(TestUpdateCollection._TARGET, datetime.max, self.metadata),
         Update(TestUpdateCollection._TARGET + "/other", datetime.max, self.metadata),
         Update(TestUpdateCollection._TARGET, datetime.min, self.metadata)
     ])
     self.assertCountEqual(updates.get_entity_updates(TestUpdateCollection._TARGET), [updates[0], updates[2]])
 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]])
Example #3
0
 def _data_object_updates_to_generic_update_collection(updates: Sequence[DataObjectUpdate]) -> UpdateCollection:
     """
     Converts the given data object updates to a generic collection of updates that can be stored in the knowledge
     base (`CookieJar`).
     :param updates: the data object updates to convert
     :return: the equivalent generic updates
     """
     generic_update_collection = UpdateCollection()
     for update in updates:
         modification_as_json = BatonUpdateMapper.DATA_OBJECT_MODIFICATION_JSON_ENCODER.default(update.modification)
         metadata = Metadata(modification_as_json)
         update = Update(update.entity.path, update.timestamp, metadata)
         generic_update_collection.append(update)
     return generic_update_collection
Example #4
0
    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())))
Example #5
0
    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)