def test_no_person_updates_with_committee(person): created, updated = load_person(person) DjangoPerson.objects.get(pk=person.id) parent_com = Committee( id="ocd-organization/00000000-1111-1111-1111-222222222222", name="Finance", chamber="lower", jurisdiction="ocd-jurisdiction/country:us/state:nc/government", members=[Membership(name="Steve", role="chair")], ) created, updated = committee_to_db(parent_com) sub_com = Committee( id="ocd-organization/00000000-1111-1111-1111-333333333333", name="Education", chamber="lower", classification="subcommittee", parent="ocd-organization/00000000-1111-1111-1111-222222222222", jurisdiction="ocd-jurisdiction/country:us/state:nc/government", members=[Membership(name="Steve", role="chair", person_id=person.id)], ) created, updated = committee_to_db(sub_com) assert created and not updated created, updated = load_person(person) assert not created and not updated
def test_get_new_filename(): comdir = CommitteeDir( abbr="wa", directory=TEST_DATA_PATH / "committees", ) simple = Committee( id="ocd-organization/00001111-2222-3333-4444-555566667777", jurisdiction=JURISDICTION_ID, name="Simple", chamber="lower", members=[Membership(name="Someone", role="member")], ) longer = Committee( id="ocd-organization/00001111-2222-3333-4444-999999999999", jurisdiction=JURISDICTION_ID, name="Ways, Means & Taxes", chamber="upper", members=[Membership(name="Someone", role="member")], ) assert ( comdir.get_new_filename(simple) == "lower-Simple-00001111-2222-3333-4444-555566667777.yml" ) assert ( comdir.get_new_filename(longer) == "upper-Ways-Means--Taxes-00001111-2222-3333-4444-999999999999.yml" )
def test_committee_to_db_memberships(): com_id = "ocd-organization/00000000-1111-1111-1111-222222222222" new_com = Committee( id=com_id, name="Education", chamber="lower", jurisdiction="ocd-jurisdiction/country:us/state:nc/government", members=[Membership(name="Steve", role="chair")], ) created, updated = committee_to_db(new_com) org = Organization.objects.get(pk=com_id) assert org.memberships.count() == 1 s_mem = org.memberships.get() assert s_mem.person_name == "Steve" assert s_mem.role == "chair" person_id = "ocd-person/33333333-4444-4444-4444-555555555555" wendy = DjangoPerson.objects.create(id=person_id, name="Wendy") new_com.add_member("Wendy", role="chair") new_com.members[-1].person_id = person_id created, updated = committee_to_db(new_com) assert updated and not created org = Organization.objects.get(pk=com_id) assert org.memberships.count() == 2 w_mem = org.memberships.filter(person_name="Wendy")[0] assert w_mem.person == wendy
def test_merge_committees_links(): comdir = CommitteeDir(abbr="wa", directory=TEST_DATA_PATH / "committees") id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee( id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education", links=[ Link(url="https://example.com/1"), Link(url="https://example.com/2"), ], members=[Membership(name="Someone", role="member")], ) c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education & Children", links=[ Link(url="https://example.com/1", note="first"), Link(url="https://example.com/3"), ], members=[Membership(name="Someone", role="member")], ) merged = comdir.merge_committees(c1, c2) assert merged.links == [ Link(url="https://example.com/1", note="first"), Link(url="https://example.com/2"), Link(url="https://example.com/3"), ]
def test_merge_committees_members(): comdir = CommitteeDir(abbr="wa", directory=TEST_DATA_PATH / "committees") id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" person_id = "ocd-person/00000000-0000-0000-0000-000000000002" c1 = Committee( id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education", members=[ Membership(name="Amy", role="chair"), Membership(name="Bo", role="chair"), ], ) c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education & Children", members=[ Membership(name="Amy", role="chair", person_id=person_id), Membership(name="Charlize", role="member"), ], ) merged = comdir.merge_committees(c1, c2) assert merged.members == [ Membership(name="Amy", role="chair", person_id=person_id), Membership(name="Bo", role="chair"), Membership(name="Charlize", role="member"), ]
def test_merge_committees_links(): id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee( id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education", links=[ Link(url="https://example.com/1"), Link(url="https://example.com/2"), ], ) c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education & Children", links=[ Link(url="https://example.com/1", note="first"), Link(url="https://example.com/3"), ], ) merged = merge_committees(c1, c2) assert merged.links == [ Link(url="https://example.com/1", note="first"), Link(url="https://example.com/2"), Link(url="https://example.com/3"), ]
def test_committee_dict_order(): c = Committee( name="Health", chamber="upper", id=VALID_ORG_ID, jurisdiction=VALID_JURISDICTION_ID, ) assert list(c.to_dict().keys())[:4] == [ "id", "jurisdiction", "classification", "name", ]
def test_committee(): assert Committee( name="Health", chamber="upper", id=VALID_ORG_ID, jurisdiction=VALID_JURISDICTION_ID, ) with pytest.raises(ValidationError): Committee( name="Health", chamber="upper", id="123", jurisdiction=VALID_JURISDICTION_ID ) with pytest.raises(ValidationError): Committee( name="Health", chamber="upper", id=VALID_ORG_ID, jurisdiction="canada" )
def test_merge_committees_invalid(): id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee(id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education") c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="lower", name="Education & Children", ) with pytest.raises(ValueError): merge_committees(c1, c2)
def test_merge_committees_name(): id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee(id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education") c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education & Children", ) merged = merge_committees(c1, c2) assert merged.id == c1.id assert merged.name == c2.name
def test_merge_committees_invalid(): comdir = CommitteeDir(abbr="wa", directory=TEST_DATA_PATH / "committees") id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee( id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education", members=[Membership(name="Someone", role="member")], ) c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="lower", name="Education & Children", members=[Membership(name="Someone", role="member")], ) with pytest.raises(ValueError): comdir.merge_committees(c1, c2)
def test_merge_committees_name(): comdir = CommitteeDir(abbr="wa", directory=TEST_DATA_PATH / "committees") id_one = "ocd-organization/00000000-0000-0000-0000-000000000001" id_two = "ocd-organization/00000000-0000-0000-0000-000000000002" c1 = Committee( id=id_one, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education", members=[Membership(name="Someone", role="member")], ) c2 = Committee( id=id_two, jurisdiction=JURISDICTION_ID, chamber="upper", name="Education & Children", members=[Membership(name="Someone", role="member")], ) merged = comdir.merge_committees(c1, c2) assert merged.id == c1.id assert merged.name == c2.name
def test_committee_to_db_simple(): com_id = "ocd-organization/00000000-1111-1111-1111-222222222222" new_com = Committee( id=com_id, name="Education", chamber="lower", jurisdiction="ocd-jurisdiction/country:us/state:nc/government", sources=[{ "url": "https://example.com" }], ) created, updated = committee_to_db(new_com) assert created and not updated org = Organization.objects.get(pk=com_id) assert org.sources == new_com.sources new_com.links = [{"url": "https://example.com"}] created, updated = committee_to_db(new_com) assert updated and not created org = Organization.objects.get(pk=com_id) assert org.links == new_com.links
def test_committee(): assert Committee( name="Health", chamber="upper", id=VALID_ORG_ID, jurisdiction=VALID_JURISDICTION_ID, members=[Membership(name="someone", role="member")], ) with pytest.raises(ValidationError): Committee( name="Health", chamber="upper", id="123", jurisdiction=VALID_JURISDICTION_ID, members=[Membership(name="someone", role="member")], ) with pytest.raises(ValidationError): Committee( name="Health", chamber="upper", id=VALID_ORG_ID, jurisdiction="canada", members=[Membership(name="someone", role="member")], )