|
| 1 | +from pathlib import Path |
| 2 | +import tomllib |
| 3 | + |
| 4 | +from unstructured_client.models import shared |
| 5 | +from unstructured_client.utils.forms import serialize_multipart_form |
| 6 | + |
| 7 | + |
| 8 | +REPO_ROOT = Path(__file__).resolve().parents[2] |
| 9 | + |
| 10 | + |
| 11 | +def _load_pyproject() -> dict: |
| 12 | + return tomllib.loads((REPO_ROOT / "pyproject.toml").read_text()) |
| 13 | + |
| 14 | + |
| 15 | +def test_pyproject_invariants(): |
| 16 | + data = _load_pyproject() |
| 17 | + project = data["project"] |
| 18 | + |
| 19 | + assert project["dynamic"] == ["version"] |
| 20 | + assert "version" not in project |
| 21 | + assert project["requires-python"] == ">=3.11" |
| 22 | + assert "httpcore >=1.0.9" in project["dependencies"] |
| 23 | + assert "pydantic >=2.12.5" in project["dependencies"] |
| 24 | + assert not any("cryptography" in d for d in project["dependencies"]), \ |
| 25 | + "cryptography is unused and must not be a runtime dependency" |
| 26 | + |
| 27 | + dynamic_version = data["tool"]["setuptools"]["dynamic"]["version"] |
| 28 | + assert dynamic_version == {"attr": "unstructured_client._version.__version__"} |
| 29 | + |
| 30 | + build = data["build-system"] |
| 31 | + assert build["build-backend"] == "setuptools.build_meta" |
| 32 | + assert "setuptools>=80" in build["requires"] |
| 33 | + |
| 34 | + |
| 35 | +def test_publish_script_is_hardened(): |
| 36 | + publish_script = (REPO_ROOT / "scripts" / "publish.sh").read_text() |
| 37 | + |
| 38 | + assert "set -euo pipefail" in publish_script |
| 39 | + assert "sys.version_info < (3, 11)" in publish_script |
| 40 | + assert 'uv publish --token "${PYPI_TOKEN}" --check-url https://pypi.org/simple' in publish_script |
| 41 | + |
| 42 | + |
| 43 | +def test_body_create_job_input_files_are_serialized_as_multipart_files(): |
| 44 | + request = shared.BodyCreateJob( |
| 45 | + request_data="{}", |
| 46 | + input_files=[ |
| 47 | + shared.InputFiles( |
| 48 | + content=b"hello", |
| 49 | + file_name="hello.pdf", |
| 50 | + content_type="application/pdf", |
| 51 | + ) |
| 52 | + ], |
| 53 | + ) |
| 54 | + |
| 55 | + media_type, form, files = serialize_multipart_form("multipart/form-data", request) |
| 56 | + |
| 57 | + assert media_type == "multipart/form-data" |
| 58 | + assert form == {"request_data": "{}"} |
| 59 | + assert files == [("input_files[]", ("hello.pdf", b"hello", "application/pdf"))] |
| 60 | + |
| 61 | + |
| 62 | +def test_body_run_workflow_input_files_are_serialized_as_multipart_files(): |
| 63 | + request = shared.BodyRunWorkflow( |
| 64 | + input_files=[ |
| 65 | + shared.BodyRunWorkflowInputFiles( |
| 66 | + content=b"hello", |
| 67 | + file_name="hello.pdf", |
| 68 | + content_type="application/pdf", |
| 69 | + ) |
| 70 | + ] |
| 71 | + ) |
| 72 | + |
| 73 | + media_type, form, files = serialize_multipart_form("multipart/form-data", request) |
| 74 | + |
| 75 | + assert media_type == "multipart/form-data" |
| 76 | + assert form == {} |
| 77 | + assert files == [("input_files[]", ("hello.pdf", b"hello", "application/pdf"))] |
0 commit comments