Synchronous helper for tests to add artifacts.
(
self,
*,
app_name: str,
user_id: str,
session_id: str,
filename: str,
artifact: types.Part,
custom_metadata: Optional[dict[str, Any]] = None,
canonical_uri: Optional[str] = None,
mime_type: Optional[str] = None,
)
| 312 | return version |
| 313 | |
| 314 | def add_artifact( |
| 315 | self, |
| 316 | *, |
| 317 | app_name: str, |
| 318 | user_id: str, |
| 319 | session_id: str, |
| 320 | filename: str, |
| 321 | artifact: types.Part, |
| 322 | custom_metadata: Optional[dict[str, Any]] = None, |
| 323 | canonical_uri: Optional[str] = None, |
| 324 | mime_type: Optional[str] = None, |
| 325 | ) -> int: |
| 326 | """Synchronous helper for tests to add artifacts.""" |
| 327 | key = _artifact_key(app_name, user_id, session_id, filename) |
| 328 | entries = artifacts.setdefault(key, []) |
| 329 | version = len(entries) |
| 330 | artifact_version = ArtifactVersion( |
| 331 | version=version, |
| 332 | canonical_uri=( |
| 333 | canonical_uri |
| 334 | or _canonical_uri( |
| 335 | app_name, user_id, session_id, filename, version |
| 336 | ) |
| 337 | ), |
| 338 | custom_metadata=custom_metadata or {}, |
| 339 | ) |
| 340 | if mime_type: |
| 341 | artifact_version.mime_type = mime_type |
| 342 | elif artifact.inline_data is not None: |
| 343 | artifact_version.mime_type = artifact.inline_data.mime_type |
| 344 | elif artifact.text is not None: |
| 345 | artifact_version.mime_type = "text/plain" |
| 346 | elif artifact.file_data is not None: |
| 347 | artifact_version.mime_type = artifact.file_data.mime_type |
| 348 | |
| 349 | entries.append({ |
| 350 | "version": version, |
| 351 | "artifact": artifact, |
| 352 | "metadata": artifact_version, |
| 353 | }) |
| 354 | return version |
| 355 | |
| 356 | async def load_artifact( |
| 357 | self, app_name, user_id, session_id, filename, version=None |
no test coverage detected