def test_person_party(): yaml_text = """ id: abcdefab-0000-1111-2222-1234567890ab name: Jane Smith party: - name: Democratic """ data = yaml.load(yaml_text) created, updated = load_person(data) p = Person.objects.get(pk="abcdefab-0000-1111-2222-1234567890ab") assert p.memberships.count() == 1 assert p.memberships.get().organization.name == "Democratic" data["party"].append({"name": "Republican", "end_date": "2018-10-06"}) created, updated = load_person(data) assert updated is True p = Person.objects.get(pk="abcdefab-0000-1111-2222-1234567890ab") p.memberships.count() == 2 p.memberships.exclude(end_date="").count() == 1
def test_basic_person_creation(): data = yaml.safe_load(""" id: abcdefab-0000-1111-2222-1234567890ab name: Jane Smith image: https://example.com/image extras: something: special """) created, updated = load_person(data) assert created is True p = Person.objects.get(pk="abcdefab-0000-1111-2222-1234567890ab") assert p.name == "Jane Smith" assert p.image == "https://example.com/image" assert p.extras["something"] == "special"
def test_person_identifiers(): yaml_text = """ id: abcdefab-0000-1111-2222-1234567890ab name: Jane Smith ids: twitter: fakeaccount youtube: fakeYT other_identifiers: - scheme: old_openstates identifier: AR000001 - scheme: old_openstates identifier: AR000002 """ data = yaml.load(yaml_text) created, updated = load_person(data) p = Person.objects.get(pk='abcdefab-0000-1111-2222-1234567890ab') assert p.identifiers.count() == 4 assert p.identifiers.filter(scheme='old_openstates').count() == 2 assert p.identifiers.filter(scheme='twitter')[0].identifier == 'fakeaccount'