async def load( payload: None, context: EventContext, *, item_id: str, update_status: bool = False) -> Union[Something, SomethingNotFound]: """ Loads json file from filesystem as `Something` instance :param payload: unused :param context: EventContext :param item_id: str, item id to load :return: Loaded `Something` object or None if not found or validation fails """ assert fs my_id = item_id + str(randrange(0, 1999)) logger.info(context, "load", extra=extra(something_id=my_id, path=fs.path)) something = await fs.get(key=my_id, datatype=Something) if something is None: logger.warning(context, "item not found", extra=extra(something_id=my_id, path=fs.path)) return SomethingNotFound(str(fs.path), my_id) return something
async def load( payload: Status, context: EventContext, *, item_id: str, partition_key: str, update_status: bool = False) -> Union[Something, SomethingNotFound]: """ Loads json file from filesystem as `Something` instance, sets status to specified payload :param payload: Status, status change for the retrieved object :param context: EventContext :param item_id: str, item id to load :return: Loaded `Something` object or SomethingNotFound if not found or validation fails """ assert fs logger.info(context, "load", extra=extra(something_id=item_id, path=fs.path)) something = await fs.get(key=item_id, datatype=Something, partition_key=partition_key) if something is None: logger.warning(context, "item not found", extra=extra(something_id=item_id, path=fs.path)) return SomethingNotFound(str(fs.path / partition_key), item_id) if something.status and (something.status not in something.history): something.history.append(something.status) something.status = payload return something
async def load_second( collector: Collector, context: EventContext) -> Union[Something, SomethingNotFound]: """ Loads json file from filesystem as `Something` instance :param collector: collector with payload :param context: EventContext :return: Loaded `Something` object or SomethingNotFound if not found or validation fails """ assert fs items_to_read = await collector['payload'] item_id = items_to_read.item2_id await asyncio.sleep(0.1) logger.info(context, "load_first", extra=extra(something_id=item_id, path=fs.path)) something = await fs.get(key=item_id, datatype=Something) if something is None: logger.warning(context, "item not found", extra=extra(something_id=item_id, path=fs.path)) return SomethingNotFound(str(fs.path), item_id) return something
async def test_query_item_not_found(app_config): # noqa: F811 item_id = str(uuid.uuid4()) result, pp_result, res = await execute_event(app_config=app_config, event_name='query_something', payload=None, postprocess=True, item_id=item_id) assert res.status == 404 assert result == pp_result assert result == SomethingNotFound( path=f'/tmp/simple_example.{APP_VERSION}.fs.data_path', id=item_id)
async def test_query_item_not_found(app_config): # noqa: F811 status = Status(datetime.now(tz=timezone.utc), StatusType.LOADED) item_id = str(uuid.uuid4()) result, pp_result, res = await execute_event( app_config=app_config, event_name='query_something_extended', payload=status, postprocess=True, item_id=item_id) assert res.status == 404 assert result == pp_result assert result == SomethingNotFound( path=f'/tmp/simple_example.{APP_VERSION}.fs.data_path', id=item_id)