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}
示例#2
0
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")]
示例#3
0
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 = []
示例#4
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")]
示例#5
0
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
示例#6
0
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
示例#7
0
def test_validate_offices(offices, expected):
    person = Person(
        id=EXAMPLE_OCD_PERSON_ID,
        name="Example Person",
        roles=[],
        offices=[Office(**c) for c in offices],
    )
    assert validate_offices(person) == expected
示例#8
0
def test_validate_roles_retired(roles, expected):
    person = Person(
        id=EXAMPLE_OCD_PERSON_ID,
        name="Example Person",
        roles=roles,
        party=[Party(name="Republican")],
    )
    assert validate_roles(person, "roles", retired=True) == expected
示例#9
0
def test_validate_offices(contacts, expected):
    person = Person(
        id=EXAMPLE_OCD_PERSON_ID,
        name="Example Person",
        roles=[],
        contact_details=[ContactDetail(**c) for c in contacts],
    )
    assert validate_offices(person) == expected
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"},
    )
示例#11
0
def test_validate_name_fixes():
    person = Person(id=EXAMPLE_OCD_PERSON_ID, name="Phillip Swoozle", roles=[])
    result = validate_name(person, PersonType.LEGISLATIVE, fix=True)
    assert result.errors == []
    assert len(result.fixes) == 2
    assert person.given_name == "Phillip"
    assert person.family_name == "Swoozle"

    # no fixes on an OK name
    result = validate_name(person, PersonType.LEGISLATIVE, fix=True)
    assert result.errors == result.fixes == []
示例#12
0
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"
示例#13
0
    compare_districts,
    Validator,
    BadVacancy,
    PersonType,
)  # noqa
from openstates.models.people import Person, Role, Party, Office

EXAMPLE_OCD_JURISDICTION_ID = "ocd-jurisdiction/country:us/government"
EXAMPLE_OCD_PERSON_ID = "ocd-person/12345678-0000-1111-2222-1234567890ab"
EXAMPLE_OCD_ORG_ID = "ocd-organization/00001111-2222-3333-aaaa-444455556666"


@pytest.mark.parametrize(
    "person,expected",
    [
        (Person(id=EXAMPLE_OCD_PERSON_ID, name="Phillip J Swoozle",
                roles=[]), []),
        (
            Person(id=EXAMPLE_OCD_PERSON_ID, name="Phillip Swoozle", roles=[]),
            [
                "missing given_name that could be set to 'Phillip', run with --fix",
                "missing family_name that could be set to 'Swoozle', run with --fix",
            ],
        ),
        (
            Person(
                id=EXAMPLE_OCD_PERSON_ID,
                name="Phillip Swoozle",
                given_name="Phil",
                roles=[],
            ),
            [