From b337ebac9b1094452f46d1e3f5e645bb37304cc6 Mon Sep 17 00:00:00 2001 From: amzker Date: Sat, 21 Dec 2024 00:05:16 +0530 Subject: [PATCH] sub entity ids returns --- api/schemas.py | 9 ++++--- api/tests/test_bills.py | 56 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/api/schemas.py b/api/schemas.py index 1860d31..602772d 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -1,6 +1,7 @@ import datetime from typing import Optional, List, Union from enum import Enum +from uuid import UUID from pydantic import BaseModel, Field @@ -245,17 +246,17 @@ class Config: class BillSponsorship(BaseModel): + id: UUID = Field(..., example="f0049138-1ad8-4506-a2a4-f4dd1251bbba") name: str = Field(..., example="JONES") entity_type: str = Field(..., example="person") organization: Optional[Organization] = Field(None, example=None) person: Optional[CompactPerson] primary: bool classification: str = Field(..., example="primary") - + class Config: orm_mode = True - class BillActionRelatedEntity(BaseModel): name: str = Field(..., example="Senate Committee of the Whole") entity_type: str = Field(..., example="organization") @@ -267,6 +268,7 @@ class Config: class BillAction(BaseModel): + id: UUID = Field(..., example="f0049138-1ad8-4506-a2a4-f4dd1251bbba") organization: Organization description: str = Field(..., example="Passed 1st Reading") date: str = Field(..., example="2020-03-14") @@ -288,6 +290,7 @@ class Config: class BillDocumentOrVersion(BaseModel): + id: UUID = Field(..., example="f0049138-1ad8-4506-a2a4-f4dd1251bbba") note: str = Field(..., example="Latest Version") date: str = Field(..., example="2020-10-01") links: List[BillDocumentLink] @@ -305,6 +308,7 @@ class Config: class PersonVote(BaseModel): + id: UUID = Field(..., example="f0049138-1ad8-4506-a2a4-f4dd1251bbba") option: str = Field(..., example="no") voter_name: str = Field(..., example="Wu") voter: Optional[CompactPerson] @@ -312,7 +316,6 @@ class PersonVote(BaseModel): class Config: orm_mode = True - class VoteEvent(BaseModel): id: str motion_text: str = Field(..., example="Shall the bill be passed?") diff --git a/api/tests/test_bills.py b/api/tests/test_bills.py index 1275ab2..6e05ca5 100644 --- a/api/tests/test_bills.py +++ b/api/tests/test_bills.py @@ -1,3 +1,4 @@ +import uuid from .conftest import query_logger from api.bills import BillSortOption @@ -201,11 +202,22 @@ def test_bills_include_documents_versions(client): for b in response.json()["results"]: assert len(b["documents"]) == 3 assert len(b["versions"]) == 2 - assert b["versions"][0] == { + version = b["versions"][0] + version_id = version.pop("id") # they are dynamic uuids so... + assert uuid.UUID(version_id) + assert isinstance(version_id, str) + assert version == { "note": "Version 0", "date": "2020", "links": [{"media_type": "text/html", "url": "https://example.com/0"}], } + + for doc in b["documents"]: + doc_id = doc.pop("id") + assert uuid.UUID(doc_id) + assert "note" in doc + assert "date" in doc + assert "links" in doc assert "other_titles" not in b @@ -214,6 +226,14 @@ def test_bills_include_votes(client): assert query_logger.count == 7 assert response.status_code == 200 b = response.json()["results"][0] + votes = b["votes"] + for vote in votes: + for person_vote in vote["votes"]: + vote_people_id = person_vote.pop("id") + assert uuid.UUID(vote_people_id) + assert isinstance(vote_people_id, str) + + assert b["votes"] == [ { "id": "ocd-vote/1", @@ -368,7 +388,11 @@ def test_bill_detail_sponsorship_resolution(client): assert response["id"] == "ocd-bill/1234" assert len(response["sponsorships"]) == 2 # uses the compact person representation, no more joins - assert response["sponsorships"][0] == { + sponsorship = response["sponsorships"][0] + sponsor_id = sponsorship.pop("id") + assert uuid.UUID(sponsor_id) + assert isinstance(sponsor_id, str) + assert sponsorship == { "name": "Ruth", "entity_type": "person", "classification": "sponsor", @@ -386,3 +410,31 @@ def test_bill_detail_sponsorship_resolution(client): }, } assert query_logger.count == 3 + +def test_bills_include_actions(client): + response = client.get("/bills?jurisdiction=ne&session=2020&include=actions") + + for bill in response.json()["results"]: + assert "actions" in bill + assert len(bill["actions"]) > 0 + + for action in bill["actions"]: + action_id = action.pop("id") + assert uuid.UUID(action_id) + + assert action["description"] + assert action["date"] + assert isinstance(action["classification"], list) + assert isinstance(action["organization"], dict) + assert isinstance(action["related_entities"], list) + + assert "id" in action["organization"] + org_id = action["organization"]["id"] + assert isinstance(org_id, str) + assert "name" in action["organization"] + assert "classification" in action["organization"] + + for entity in action["related_entities"]: + assert "id" in entity + assert "name" in entity + assert "type" in entity \ No newline at end of file