def test_party_on_person(): p = Person( id=VALID_PERSON_ID, name="Tony Tigre", party=[Party(name="Democratic")], roles=[], ) with pytest.raises(ValidationError): # no such party p.party = [Party(name="Vampire")]
def test_party_required_on_legislator(): p = Person( id=VALID_PERSON_ID, name="Tony Tigre", party=[Party(name="Democratic")], roles=[ Role(type=RoleType.UPPER, district=1, jurisdiction=VALID_JURISDICTION_ID) ], ) with pytest.raises(ValidationError): # no party! p.party = []
def test_person_commas(): with pytest.raises(ValidationError): Person( id="ocd-person/11111111-2222-3333-4444-555555555555", name="Jones, Joan", party=[Party(name="Democratic")], roles=[], ) good_comma = Person( id="ocd-person/11111111-2222-3333-4444-555555555555", name="Joan Jones, Jr.", party=[Party(name="Democratic")], roles=[], ) assert good_comma.name
def test_retire_person(): person = Person( id="ocd-person/11110000-2222-3333-4444-555555555555", name="Test Person", party=[ Party(name="Democratic"), ], roles=[ Role(type="lower", end_date="2000-01-01", district="1", jurisdiction=JID), # leave old end date alone Role(type="upper", start_date="2018-01-01", district="2", jurisdiction=JID), # add end date Role(type="governor", end_date="2030-01-01", jurisdiction=JID), # move up future end date ], ) person, num = retire_person(person, "2018-10-01") assert num == 2 assert person.roles[0].end_date == "2000-01-01" assert person.roles[1].end_date == "2018-10-01" assert person.roles[2].end_date == "2018-10-01" # idempotent person, num = retire_person(person, "2018-11-01") assert num == 0
def test_multiple_parties(): p = Person( id=VALID_PERSON_ID, name="Tony Tigre", party=[Party(name="Democratic")], roles=[], ) with pytest.raises(ValidationError): # can't have two active major parties p.party = [Party(name="Democratic"), Party(name="Republican")] # can be in multiple parties as long as one is non-major p.party = [Party(name="Democratic"), Party(name="Green")] # or if one is obsolete p.party = [ Party(name="Democratic", end_date="2010"), Party(name="Republican") ]
def test_person_summary(): s = Summarizer() people = [ Person( id=ocd_uuid("person"), name="Jorna Corno", gender="F", image="https://example.com/image1", party=[Party(name="Democratic"), Party(name="Democratic", end_date="1990")], roles=[], ), Person( id=ocd_uuid("person"), name="Linda Under", gender="F", image="https://example.com/image2", party=[Party(name="Democratic"), Party(name="Progressive")], extras={"religion": "Zoroastrian"}, contact_details=[ContactDetail(fax="123-435-9999", note="Capitol Office")], other_identifiers=[OtherIdentifier(scheme="fake", identifier="abc")], ids=PersonIdBlock(twitter="fake"), roles=[], ), Person( id=ocd_uuid("person"), name="Phil Gort", gender="M", image="https://example.com/image3", party=[Party(name="Republican")], contact_details=[ContactDetail(voice="123-435-9999", note="Capitol Office")], other_identifiers=[OtherIdentifier(scheme="fake", identifier="123")], roles=[], ), ] for p in people: s.summarize(p) assert s.parties == {"Republican": 1, "Democratic": 2, "Progressive": 1} assert s.contact_counts == {"Capitol Office voice": 1, "Capitol Office fax": 1} assert s.id_counts == {"fake": 2, "twitter": 1} assert s.optional_fields == {"gender": 3, "image": 3} assert s.extra_counts == {"religion": 1}
def person(): PERSON_ID = "ocd-person/abcdefab-0000-1111-2222-1234567890ab" return Person( id=PERSON_ID, name="Jane Smith", party=[Party(name="Democratic")], roles=[], image="https://example.com/image", extras={"something": "special"}, )
def test_person_basics(): with pytest.raises(ValidationError): Person(name="missing fields") good = Person( id="ocd-person/11111111-2222-3333-4444-555555555555", name="Joan Jones", party=[Party(name="Democratic")], roles=[], ) assert good.name with pytest.raises(ValidationError): good.death_date = "X" with pytest.raises(ValidationError): good.birth_date = "X" with pytest.raises(ValidationError): good.birth_date = "X" with pytest.raises(ValidationError): good.id = "123" with pytest.raises(ValidationError): good.image = "/fragment"