예제 #1
0
def test_subobject_duplicate(person):
    # this shouldn't actually be allowed most places (lint should catch)
    # but it was breaking committee imports when two members had the same name
    person.links = [
        Link(url="https://example.com"),
        Link(url="https://example.com"),
    ]
    # load twice, but second time no update should occur
    created, updated = load_person(person)
    created, updated = load_person(person)
    assert created is False
    assert updated is False
예제 #2
0
def test_person_party(person):
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    assert p.memberships.count() == 1
    assert p.memberships.get().organization.name == "Democratic"
    assert p.primary_party == "Democratic"

    person.party.append(Party(name="Republican", end_date="2018-10-06"))
    created, updated = load_person(person)
    assert updated is True
    assert p.primary_party == "Democratic"
    p = DjangoPerson.objects.get(pk=person.id)
    p.memberships.count() == 2
    p.memberships.exclude(end_date="").count() == 1
예제 #3
0
def test_basic_person_creation(person):
    created, updated = load_person(person)

    assert created is True
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.name == "Jane Smith"
    assert p.image == "https://example.com/image"
    assert p.extras["something"] == "special"
    assert p.current_role is None
예제 #4
0
def test_basic_person_updates(person):
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)
    created_at, updated_at = p.created_at, p.updated_at

    # ensure no change means no change
    created, updated = load_person(person)
    assert created is False
    assert updated is False
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.created_at == created_at
    assert p.updated_at == updated_at

    # ensure extra changes got captured
    person.extras["something"] = "changed"
    created, updated = load_person(person)
    assert created is False
    assert updated is True
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.updated_at > updated_at
    assert p.extras["something"] == "changed"
예제 #5
0
def test_person_identifiers(person):
    person.ids.twitter = "fakeaccount"
    person.ids.youtube = "fakeaccount"
    person.other_identifiers.append(
        OtherIdentifier(scheme="old_openstates", identifier="AR000001"))
    person.other_identifiers.append(
        OtherIdentifier(scheme="old_openstates", identifier="AR000002"))
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    assert p.identifiers.count() == 4
    assert p.identifiers.filter(scheme="old_openstates").count() == 2
    assert p.identifiers.filter(
        scheme="twitter")[0].identifier == "fakeaccount"
예제 #6
0
def test_subobject_update(person):
    person.links = [
        Link(url="https://example.com"),
        Link(url="https://example.com/2", note="some additional data"),
    ]
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)
    created_at, updated_at = p.created_at, p.updated_at

    # ensure no change means no change
    created, updated = load_person(person)
    assert created is False
    assert updated is False
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.created_at == created_at
    assert p.updated_at == updated_at

    # change one field
    person.links[0].url = "https://example.com/jane-smith"
    created, updated = load_person(person)

    assert created is False
    assert updated is True
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.links.count() == 2
    assert p.links.filter(url="https://example.com/jane-smith").count() == 1
    assert p.updated_at > updated_at

    # delete a field
    person.links.pop()
    created, updated = load_person(person)
    assert created is False
    assert updated is True
    p = DjangoPerson.objects.get(pk=person.id)
    assert p.links.count() == 1
    assert p.updated_at > updated_at
예제 #7
0
def test_basic_person_subobjects(person):
    person.links = [
        Link(url="https://example.com"),
        Link(url="https://example.com/2", note="some additional data"),
    ]
    person.sources = [Link(url="https://example.com/jane")]
    person.other_names = [
        OtherName(name="J. Smith"),
    ]

    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    assert p.links.count() == 2
    assert p.links.filter(note="some additional data").count() == 1
    assert p.sources.count() == 1
    assert p.other_names.count() == 1
예제 #8
0
def test_person_mayor_role(person):
    person.roles.append(
        Role(
            type="mayor",
            jurisdiction=
            "ocd-jurisdiction/country:us/state:nc/place:cary/government",
            end_date="2030-01-01",
        ))
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    assert p.memberships.count() == 2
    assert p.current_role == {
        "org_classification": "government",
        "district": None,
        "division_id": None,
        "title": "Mayor",
    }
    assert (p.current_jurisdiction_id ==
            "ocd-jurisdiction/country:us/state:nc/place:cary/government")
예제 #9
0
def test_person_contact_details(person):
    person.email = "*****@*****.**"
    person.contact_details.append(
        ContactDetail(
            note="Capitol Office",
            fax="111-222-3333",
            voice="555-555-5555",
            address="123 Main St; Washington DC",
        ))
    person.contact_details.append(
        ContactDetail(
            note="Primary Office",
            voice="333-333-5555",
        ))

    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    assert p.email == "*****@*****.**"
    assert p.contact_details.count() == 4
    assert p.contact_details.filter(note="Primary Office").count() == 1
예제 #10
0
def test_person_legislative_roles(person):
    person.roles.append(
        Role(
            type="lower",
            district=3,
            jurisdiction="ocd-jurisdiction/country:us/state:nc/government",
        ))
    created, updated = load_person(person)
    p = DjangoPerson.objects.get(pk=person.id)

    # party and legislative
    assert p.memberships.count() == 2
    assert p.memberships.get(
        organization__classification="lower").organization.name == "House"
    assert p.memberships.get(
        organization__classification="lower").post.label == "3"
    assert p.current_role == {
        "org_classification": "lower",
        "district": 3,
        "division_id": "ocd-division/country:us/state:nc/sldl:3",
        "title": "Representative",
    }
    assert p.current_jurisdiction_id == "ocd-jurisdiction/country:us/state:nc/government"