Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sub entity ids returns #38

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/schemas.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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]
Expand All @@ -305,14 +308,14 @@ 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]

class Config:
orm_mode = True


class VoteEvent(BaseModel):
id: str
motion_text: str = Field(..., example="Shall the bill be passed?")
Expand Down
56 changes: 54 additions & 2 deletions api/tests/test_bills.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from .conftest import query_logger
from api.bills import BillSortOption

Expand Down Expand Up @@ -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


Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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
Loading