From 28dd12ac440fce3cf127940c662cce8cd832833d Mon Sep 17 00:00:00 2001 From: Christopher <131207452+PetrefiedThunder@users.noreply.github.com> Date: Sun, 25 Oct 2026 00:07:47 -0700 Subject: [PATCH 1/3] test(admin): replace invented facility/TLC values with data-free placeholders --- .../test_supplier_facilities_routes_1342.py | 78 ++++++++++++------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/services/admin/tests/test_supplier_facilities_routes_1342.py b/services/admin/tests/test_supplier_facilities_routes_1342.py index 114ed8081..c851de5c9 100644 --- a/services/admin/tests/test_supplier_facilities_routes_1342.py +++ b/services/admin/tests/test_supplier_facilities_routes_1342.py @@ -27,7 +27,7 @@ from __future__ import annotations from unittest.mock import MagicMock, patch -from uuid import UUID +from uuid import UUID, uuid4 import pytest from app.sqlalchemy_models import ( @@ -45,6 +45,26 @@ from sqlalchemy.orm import Session, sessionmaker from sqlalchemy.pool import StaticPool + +# Data-free placeholders: opaque random tokens, not invented domain records. +# Tests only assert that values round-trip, never what they mean. +def _opaque() -> str: + return uuid4().hex + + +TLC_CREATE = _opaque() +TLC_EVENT = _opaque() +TLC_BADFAC = _opaque() +TLC_DUP = _opaque() +TLC_FILTER = _opaque() +PRODUCT = _opaque() +FACILITY_NAME = _opaque() +FACILITY_NAME_BADID = _opaque() +FACILITY_NAME_NEW = _opaque() +STREET = _opaque() +CITY = _opaque() +POSTAL_CODE = _opaque() + TEST_TENANT_ID = UUID("00000000-0000-0000-0000-000000000001") TEST_USER_ID = UUID("00000000-0000-0000-0000-000000000002") @@ -155,15 +175,15 @@ def _get_user(): # --------------------------------------------------------------------------- -def _make_facility(db: Session, name: str = "Warehouse A") -> SupplierFacilityModel: +def _make_facility(db: Session, name: str = FACILITY_NAME) -> SupplierFacilityModel: f = SupplierFacilityModel( tenant_id=TEST_TENANT_ID, supplier_user_id=TEST_USER_ID, name=name, - street="1 Main St", - city="Salinas", + street=STREET, + city=CITY, state="CA", - postal_code="93901", + postal_code=POSTAL_CODE, roles=["Grower"], ) db.add(f) @@ -210,7 +230,7 @@ def test_returns_facility(self, client: TestClient, db_session: Session): body = resp.json() assert body["total"] == 1 assert len(body["items"]) == 1 - assert body["items"][0]["name"] == "Warehouse A" + assert body["items"][0]["name"] == FACILITY_NAME def test_pagination_params_forwarded(self, client: TestClient, db_session: Session): """Lines 63-97: pagination skip/limit reflected in response.""" @@ -240,11 +260,11 @@ def test_no_tenant_returns_400(self, client_no_tenant: TestClient): resp = client_no_tenant.post( "/v1/supplier/facilities", json={ - "name": "Warehouse X", - "street": "1 Main St", - "city": "Salinas", + "name": FACILITY_NAME_BADID, + "street": STREET, + "city": CITY, "state": "CA", - "postal_code": "93901", + "postal_code": POSTAL_CODE, "roles": [], }, ) @@ -255,17 +275,17 @@ def test_create_facility_happy_path(self, client: TestClient): resp = client.post( "/v1/supplier/facilities", json={ - "name": "New Packhouse", + "name": FACILITY_NAME_NEW, "street": "100 Depot Rd", - "city": "Salinas", + "city": CITY, "state": "CA", - "postal_code": "93901", + "postal_code": POSTAL_CODE, "roles": ["Packer"], }, ) assert resp.status_code == 200 body = resp.json() - assert body["name"] == "New Packhouse" + assert body["name"] == FACILITY_NAME_NEW assert body["state"] == "CA" assert "id" in body @@ -387,7 +407,7 @@ def test_no_tenant_returns_400(self, client_no_tenant: TestClient): f"/v1/supplier/facilities/{uuid.uuid4()}/cte-events", json={ "cte_type": "harvesting", - "tlc_code": "TLC-001", + "tlc_code": TLC_CREATE, "event_time": "2026-03-01T00:00:00Z", "kde_data": {}, }, @@ -400,7 +420,7 @@ def test_invalid_uuid_returns_400(self, client: TestClient): "/v1/supplier/facilities/not-a-uuid/cte-events", json={ "cte_type": "harvesting", - "tlc_code": "TLC-001", + "tlc_code": TLC_CREATE, "event_time": "2026-03-01T00:00:00Z", "kde_data": {}, }, @@ -415,8 +435,8 @@ def test_submit_cte_event_happy_path(self, client: TestClient, db_session: Sessi tenant_id=TEST_TENANT_ID, supplier_user_id=TEST_USER_ID, facility_id=f.id, - tlc_code="TLC-EVENT-001", - product_description="Baby Spinach", + tlc_code=TLC_EVENT, + product_description=PRODUCT, status="active", ) db_session.add(lot) @@ -426,14 +446,14 @@ def test_submit_cte_event_happy_path(self, client: TestClient, db_session: Sessi f"/v1/supplier/facilities/{f.id}/cte-events", json={ "cte_type": "harvesting", - "tlc_code": "TLC-EVENT-001", + "tlc_code": TLC_EVENT, "event_time": "2026-03-01T12:00:00Z", "kde_data": {"quantity": 50, "unit_of_measure": "cases"}, }, ) assert resp.status_code == 200 body = resp.json() - assert body["tlc_code"] == "TLC-EVENT-001" + assert body["tlc_code"] == TLC_EVENT assert body["cte_type"] == "harvesting" assert body["merkle_hash"] is not None @@ -452,8 +472,8 @@ def test_no_tenant_returns_400(self, client_no_tenant: TestClient): "/v1/supplier/tlcs", json={ "facility_id": str(uuid.uuid4()), - "tlc_code": "TLC-X", - "product_description": "Spinach", + "tlc_code": TLC_BADFAC, + "product_description": PRODUCT, }, ) assert resp.status_code == 400 @@ -464,8 +484,8 @@ def test_invalid_facility_uuid_returns_400(self, client: TestClient): "/v1/supplier/tlcs", json={ "facility_id": "not-a-uuid", - "tlc_code": "TLC-X", - "product_description": "Spinach", + "tlc_code": TLC_BADFAC, + "product_description": PRODUCT, }, ) assert resp.status_code == 400 @@ -476,8 +496,8 @@ def test_duplicate_tlc_returns_409(self, client: TestClient, db_session: Session f = _make_facility(db_session) payload = { "facility_id": str(f.id), - "tlc_code": "TLC-DUP-001", - "product_description": "Baby Spinach", + "tlc_code": TLC_DUP, + "product_description": PRODUCT, } r1 = client.post("/v1/supplier/tlcs", json=payload) assert r1.status_code == 200 @@ -518,8 +538,8 @@ def test_lots_with_facility_filter(self, client: TestClient, db_session: Session tenant_id=TEST_TENANT_ID, supplier_user_id=TEST_USER_ID, facility_id=f.id, - tlc_code="TLC-FILTER-001", - product_description="Spinach", + tlc_code=TLC_FILTER, + product_description=PRODUCT, status="active", ) db_session.add(lot) @@ -529,7 +549,7 @@ def test_lots_with_facility_filter(self, client: TestClient, db_session: Session assert resp.status_code == 200 body = resp.json() assert body["total"] == 1 - assert body["items"][0]["tlc_code"] == "TLC-FILTER-001" + assert body["items"][0]["tlc_code"] == TLC_FILTER assert body["items"][0]["event_count"] == 0 From 45d2ef85ce05e7812798905cf6eef7adf52ddf18 Mon Sep 17 00:00:00 2001 From: Christopher <131207452+PetrefiedThunder@users.noreply.github.com> Date: Sun, 25 Oct 2026 00:08:17 -0700 Subject: [PATCH 2/3] style(admin): ruff format facility routes test --- services/admin/tests/test_supplier_facilities_routes_1342.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/admin/tests/test_supplier_facilities_routes_1342.py b/services/admin/tests/test_supplier_facilities_routes_1342.py index c851de5c9..6a9726444 100644 --- a/services/admin/tests/test_supplier_facilities_routes_1342.py +++ b/services/admin/tests/test_supplier_facilities_routes_1342.py @@ -97,9 +97,7 @@ def db_session() -> Session: SM = sessionmaker(bind=engine, autoflush=False, autocommit=False, expire_on_commit=False, future=True) session = SM() session.add(TenantModel(id=TEST_TENANT_ID, name="T", slug="t", status="active", settings={})) - session.add( - UserModel(id=TEST_USER_ID, email="u@example.com", status="active", is_sysadmin=False) - ) + session.add(UserModel(id=TEST_USER_ID, email="u@example.com", status="active", is_sysadmin=False)) session.commit() try: @@ -615,4 +613,3 @@ def _deny_owner(): with TestClient(app) as member_client: resp = member_client.delete("/v1/supplier/facilities/00000000-0000-0000-0000-000000000000") assert resp.status_code == 403 - From bd5d927a7b827949c4a4972612fbf922b06d6576 Mon Sep 17 00:00:00 2001 From: Christopher <131207452+PetrefiedThunder@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:17:48 -0700 Subject: [PATCH 3/3] test(admin): replace invented facility values with opaque tokens --- .../admin/tests/test_supplier_facilities_routes_1342.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/admin/tests/test_supplier_facilities_routes_1342.py b/services/admin/tests/test_supplier_facilities_routes_1342.py index 6a9726444..afcc1b224 100644 --- a/services/admin/tests/test_supplier_facilities_routes_1342.py +++ b/services/admin/tests/test_supplier_facilities_routes_1342.py @@ -62,6 +62,7 @@ def _opaque() -> str: FACILITY_NAME_BADID = _opaque() FACILITY_NAME_NEW = _opaque() STREET = _opaque() +STREET_NEW = _opaque() CITY = _opaque() POSTAL_CODE = _opaque() @@ -233,7 +234,7 @@ def test_returns_facility(self, client: TestClient, db_session: Session): def test_pagination_params_forwarded(self, client: TestClient, db_session: Session): """Lines 63-97: pagination skip/limit reflected in response.""" for i in range(3): - _make_facility(db_session, name=f"Facility {i}") + _make_facility(db_session, name=_opaque()) resp = client.get("/v1/supplier/facilities?skip=1&limit=1") assert resp.status_code == 200 body = resp.json() @@ -274,7 +275,7 @@ def test_create_facility_happy_path(self, client: TestClient): "/v1/supplier/facilities", json={ "name": FACILITY_NAME_NEW, - "street": "100 Depot Rd", + "street": STREET_NEW, "city": CITY, "state": "CA", "postal_code": POSTAL_CODE, @@ -364,7 +365,7 @@ def test_graph_payload_returned_when_present( f = _make_facility(db_session) graph_response = { - "categories": [{"id": "1", "name": "Leafy Greens", "ctes": ["harvesting"]}], + "categories": [{"id": "1", "name": _opaque(), "ctes": ["harvesting"]}], "required_ctes": ["harvesting"], "source": "neo4j", } @@ -446,7 +447,7 @@ def test_submit_cte_event_happy_path(self, client: TestClient, db_session: Sessi "cte_type": "harvesting", "tlc_code": TLC_EVENT, "event_time": "2026-03-01T12:00:00Z", - "kde_data": {"quantity": 50, "unit_of_measure": "cases"}, + "kde_data": {}, }, ) assert resp.status_code == 200