def get_hsps_by_inventory_id(inventory_id, limit, offset): """ return a list of historical system profiles for a given inventory id """ validate_uuids([inventory_id]) account_number = view_helpers.get_account_number(request) query_results = db_interface.get_hsps_by_inventory_id( inventory_id, account_number, limit, offset) valid_profiles = _filter_old_hsps(query_results) if not valid_profiles: raise HTTPError( HTTPStatus.NOT_FOUND, message="no historical profiles found for inventory_id %s" % inventory_id, ) # TODO: request just these three fields from the DB, instead of fetching # the full records, then slicing and sorting profile_metadata = [] for profile in valid_profiles: profile_metadata.append({ "captured_date": profile.captured_date, "id": profile.id, "system_id": profile.inventory_id, }) sorted_profile_metadata = sorted(profile_metadata, key=lambda p: p["captured_date"], reverse=True) result = {"profiles": sorted_profile_metadata} return {"data": [result]}
def test_archive_profile(self): message = MagicMock() message.value = fixtures.EVENT_MESSAGE_VALUE with self.test_flask_app.app_context(): # save the same profile twice on purpose archiver._archive_profile(message, MagicMock(), MagicMock()) archiver._archive_profile(message, MagicMock(), MagicMock()) hsps = [] with self.test_flask_app.app_context(): hsps = db_interface.get_hsps_by_inventory_id( "6388350e-b18d-11ea-ad7f-98fa9b07d419", "5432", "10", "0") # ensure we didnt save the duplicate self.assertEquals(1, len(hsps)) # cleanup with self.test_flask_app.app_context(): db_interface.delete_hsps_by_inventory_id( "6388350e-b18d-11ea-ad7f-98fa9b07d419")
def get_hsps_by_inventory_id(inventory_id): """ return a list of historical system profiles for a given inventory id """ account_number = view_helpers.get_account_number(request) query_results = db_interface.get_hsps_by_inventory_id(inventory_id, account_number) valid_profiles = _filter_old_hsps(query_results) profile_metadata = [] for profile in valid_profiles: profile_metadata.append( { "captured_date": profile.captured_date, "id": profile.id, "system_id": profile.inventory_id, } ) sorted_profile_metadata = sorted( profile_metadata, key=lambda p: p["captured_date"], reverse=True ) result = {"profiles": sorted_profile_metadata} return {"data": [result]}