コード例 #1
0
 def test_organization_image(self):
     popolo = Popolo({
         'organizations': [{
             'name': 'ACME corporation',
             'image': 'http://example.org/acme.jpg',
         }]
     })
     o = popolo.organizations.first
     assert o.image == 'http://example.org/acme.jpg'
コード例 #2
0
 def test_person_membership_multiple_filtering(self):
     with example_file(EXAMPLE_MULTIPLE_MEMBERSHIPS) as fname:
         popolo = Popolo.from_filename(fname)
         person = popolo.persons.first
         person_memberships = person.memberships
         starfleet_memberships = \
             person_memberships.filter(organization_id="starfleet")
         latest_starfleet_membership = \
             starfleet_memberships.filter(start_date=date(2323, 12, 1))
         assert len(latest_starfleet_membership) == 1
コード例 #3
0
 def test_organization_seats(self):
     popolo = Popolo({
         'organizations': [
             {
                 'name': 'House of Commons',
                 'seats': 650,
             }
         ]})
     o = popolo.organizations.first
     assert o.seats == 650
コード例 #4
0
 def test_event_identifiers(self):
     with example_file(EXAMPLE_EVENT_JSON) as fname:
         popolo = Popolo.from_filename(fname)
         event = popolo.events.first
         assert event.identifiers == [
             {
                 "identifier": "Q967549",
                 "scheme": "wikidata"
             }
         ]
コード例 #5
0
    def test_single_organization_name(self):
        with example_file(b'''
{
    "organizations": [{"name": "Starfleet"}]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            assert len(popolo.organizations) == 1
            o = popolo.organizations[0]
            assert o.name == 'Starfleet'
コード例 #6
0
 def test_person_repr(self):
     json = b'{"persons": [{"name": "Paul l\'Astnam\u00e9"}]}'
     with example_file(json) as fname:
         popolo = Popolo.from_filename(fname)
         assert len(popolo.persons) == 1
         person = popolo.persons[0]
         if six.PY2:
             assert repr(person) == b"<Person: Paul l'Astnam\xc3\xa9>"
         else:
             assert repr(person) == u"<Person: Paul l'Astnamé>"
コード例 #7
0
    def test_membership_returns_legislative_period_start_and_end(self):
        #return sepcific start date and generic end date
        with example_file(EXAMPLE_MEMBERSHIP_ALL_FIELDS) as fname:
            popolo = Popolo.from_filename(fname)
            m = popolo.memberships[0]
            print(m.effective_start_date)
            assert m.effective_start_date == ApproxDate.from_iso8601(
                '1784-03-01')
            assert m.effective_end_date == ApproxDate.from_iso8601(
                '1784-05-23')

        #check it returns the start date when we are missing a more specific entry
        with example_file(EXAMPLE_MEMBERSHIP_ALL_FIELDS_NO_DATES) as fname:
            popolo = Popolo.from_filename(fname)
            m = popolo.memberships[0]
            assert m.effective_start_date == ApproxDate.from_iso8601(
                '1783-12-19')
            assert m.effective_end_date == ApproxDate.from_iso8601(
                '1801-01-01')
コード例 #8
0
 def test_organization_founding_and_dissolution_dates(self):
     popolo = Popolo({
         'organizations': [{
             'name': 'ACME corporation',
             'founding_date': '1950-01-20',
             'dissolution_date': '2000-11-15',
         }]
     })
     o = popolo.organizations.first
     assert o.founding_date == date(1950, 1, 20)
     assert o.dissolution_date == date(2000, 11, 15)
コード例 #9
0
    def test_organisation_equality(self):
        with example_file(b'''
{
    "organizations": [
        {
            "id": "starfleet",
            "name": "Starfleet",
            "identifiers": [
                {
                    "identifier": "Q288523",
                    "scheme": "wikidata"
                }
            ]
        }
    ]
}
''') as fname:
            o_a = Popolo.from_filename(fname).organizations[0]
            o_b = Popolo.from_filename(fname).organizations[0]
            assert o_a == o_b
            assert not (o_a != o_b)
コード例 #10
0
 def test_popolo_data_only_fetched_once(self, mocked_popolo_class):
     mocked_popolo_class.from_url.return_value = Popolo(
         {'persons': [{
             'name': 'Joe Bloggs'
         }]})
     l = self.legislatures[0]
     l.popolo()
     l.popolo()
     mocked_popolo_class.from_url.assert_called_once_with(
         u'https://cdn.rawgit.com/everypolitician/everypolitician-data/'
         u'd3afadff7d5a08e1745b7e48782a869ec4979e78/data/Argentina/'
         u'Diputados/ep-popolo-v1.0.json')
コード例 #11
0
 def test_popolo_call(self, mocked_popolo_class):
     mocked_popolo_class.from_url.return_value = Popolo(
         {'persons': [{
             'name': 'Joe Bloggs'
         }]})
     l = self.legislatures[0]
     popolo = l.popolo()
     mocked_popolo_class.from_url.assert_called_with(
         u'https://cdn.rawgit.com/everypolitician/everypolitician-data/ba00071/data/Argentina/Diputados/ep-popolo-v1.0.json'
     )
     assert len(popolo.persons) == 1
     assert popolo.persons.first.name == 'Joe Bloggs'
コード例 #12
0
 def test_organization_repr(self):
     json = b'{"organizations": ' \
            b'  [{"name": "M\u00e9decins Sans Fronti\u00e8res"}]}'
     with example_file(json) as fname:
         popolo = Popolo.from_filename(fname)
         assert len(popolo.organizations) == 1
         o = popolo.organizations[0]
         if six.PY2:
             assert repr(o) == \
                 b"<Organization: M\xc3\xa9decins Sans Fronti\xc3\xa8res>"
         else:
             assert repr(o) == u"<Organization: Médecins Sans Frontières>"
コード例 #13
0
def update_birthdates_from_file(popolo, update, output):
    """
    join updated birthdate information with the popolo file
    """
    qg = QuickGrid().open(update)
    pop = Popolo.from_filename(popolo)

    for r in qg:
        p = pop.persons.lookup_from_key[r["id"]]
        if r["birth_date"]:
            p.birth_date = r["birth_date"]
            print p.birth_date
    pop.to_filename(output)
コード例 #14
0
    def test_sort_name(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman",
            "sort_name": "Truman"
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.sort_name == 'Truman'
コード例 #15
0
    def test_no_matching_identifier(self):
        with example_file(b'''
{
    "organizations": [
        {
            "id": "starfleet",
            "name": "Starfleet"        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            assert len(popolo.organizations) == 1
            o = popolo.organizations.first
            assert o.wikidata is None
コード例 #16
0
    def test_person_no_other_names(self):
        with example_file(b'''
{
    "persons": [
        {
            "id": "john-q-public",
            "name": "Mr. John Q. Public, Esq."
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.other_names == []
コード例 #17
0
    def test_missing_birth_and_death_dates(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman"
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.birth_date == ApproxDate.PAST
            assert person.death_date == ApproxDate.FUTURE
コード例 #18
0
def merge_welsh_popolo():
    """
    merge the 1_2_3 file with the current data from EveryPolitician
    """
    download("Wales", "Assembly",r"welsh_assembly\current_ep_wales.json")
    file1 = r"welsh_assembly\welsh_assembly_1_2_3.json"
    file2 = r"welsh_assembly\current_ep_wales.json"
    to = r"welsh_assembly\welsh_assembly_complete.json"
    pop1 = Popolo.from_filename(file1)
    pop2 = Popolo.from_filename(file2)
    new = pop1.merge(pop2)
    
    """
    some timestamps are missing or wrong - amend manually and save
    """
    n = new.memberships.get(legislative_period_id="term/5",
                       person_id="1ee666d1-225f-4561-92da-cfcb94b91a6d",
                       on_behalf_of_id="party/plaid_cymru")
    n.end_date = datetime.datetime(2016,10,14)

    n = new.memberships.get(legislative_period_id="term/5",
                       person_id="1ee666d1-225f-4561-92da-cfcb94b91a6d",
                       on_behalf_of_id="party/independent")
    n.start_date = datetime.datetime(2016,10,14)
    
    n = new.memberships.get(legislative_period_id="term/5",
                       person_id="451236de-0f5e-448b-a11c-7923bd704fb8",
                       on_behalf_of_id="party/united_kingdom_independence_party_(ukip)")
    n.end_date = datetime.datetime(2016,8,12)

    n = new.memberships.get(legislative_period_id="term/5",
                       person_id="451236de-0f5e-448b-a11c-7923bd704fb8",
                       on_behalf_of_id="party/independent")
    n.start_date = datetime.datetime(2016,8,17)
    
    new.to_filename(to)
コード例 #19
0
    def test_full_birth_and_death_dates(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman",
            "birth_date": "1946-01-24",
            "death_date": "2099-12-31"
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.birth_date == date(1946, 1, 24)
            assert person.death_date == date(2099, 12, 31)
コード例 #20
0
 def test_area_other_names(self):
     popolo = Popolo({"areas": [EXAMPLE_AREA]})
     area = popolo.areas[0]
     assert area.other_names == [{
         "lang": "fr",
         "name": "Dixième circonscription législative d'Estonie",
         "note": "multilingual"
     }, {
         "lang": "et",
         "name": "Valimisringkond nr 10",
         "note": "multilingual"
     }, {
         "lang": "en",
         "name": "Electoral District 10 (Tartu)",
         "note": "multilingual"
     }]
コード例 #21
0
    def test_classification_property(self):
        with example_file(b'''
{
    "organizations": [
        {
            "id": "starfleet",
            "name": "Starfleet",
            "classification": "military"
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            assert len(popolo.organizations) == 1
            o = popolo.organizations[0]
            assert o.classification == 'military'
def get_id_lookup():
	"""
	create id lookup from popolo file
	convert datadotparl_id to parlparse
	"""
	people_url = "https://github.com/mysociety/parlparse/raw/master/members/people.json"
	pop = Popolo.from_url(people_url)
	count = 0
	lookup = {}
	print ("Creating id lookup")
	for p in pop.persons:
		id = p.id
		datadotparl = p.identifier_value("datadotparl_id")
		if datadotparl:
			lookup[datadotparl] = id[-5:]
			count += 1
	print (count, len(pop.persons))
	return lookup
コード例 #23
0
    def test_phone_and_fax(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman",
            "contact_details": [
                {"type": "phone", "value": "9304832"},
                {"type": "fax", "value": "9304833"}
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.phone == '9304832'
            assert person.fax == '9304833'
コード例 #24
0
    def test_organization_other_names(self):
        with example_file(b'''
{
    "organizations": [
        {
             "id": "abc-inc",
             "name": "ABC, Inc.",
             "other_names": [
                 {
                     "name": "Bob's Diner",
                     "start_date": "1950-01-01",
                     "end_date": "1954-12-31"
                 },
                 {
                     "name": "Joe's Diner",
                     "start_date": "1955-01-01"
                 },
                 {
                     "name": "Famous Joe's"
                 }
             ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            assert len(popolo.organizations) == 1
            o = popolo.organizations[0]
            assert o.other_names == [
                {
                    'name': "Bob's Diner",
                    'start_date': '1950-01-01',
                    'end_date': '1954-12-31'
                },
                {
                    'name': "Joe's Diner",
                    'start_date': '1955-01-01'
                },
                {
                    'name': "Famous Joe's"
                }
            ]
コード例 #25
0
    def test_person_name_at_historic_none_overlap(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Bob",
            "other_names": [
                {
                    "name": "Robert",
                    "start_date": "1989-01-01",
                    "end_date": "1999-12-31"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.name_at(date(2000, 1, 1)) == 'Bob'
コード例 #26
0
    def test_person_link_twitter(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman",
            "links": [
                {
                    "note": "twitter",
                    "url": "https://twitter.com/notarealtwitteraccountforharry"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.twitter == 'notarealtwitteraccountforharry'
            assert person.twitter_all == ['notarealtwitteraccountforharry']
コード例 #27
0
    def test_person_name_at_no_historic(self):
        # I don't quite understand why this behaviour is desirable,
        # but it's the logic of the Ruby version. TODO: check this.
        with example_file(b'''
{
    "persons": [
        {
            "name": "Bob",
            "other_names": [
                {
                    "name": "Robert",
                    "start_date": "2000-01-01"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.name_at(date(2016, 1, 11)) == 'Bob'
コード例 #28
0
    def test_wikidata_property_and_id(self):
        with example_file(b'''
{
    "organizations": [
        {
            "id": "starfleet",
            "name": "Starfleet",
            "identifiers": [
                {
                    "identifier": "Q288523",
                    "scheme": "wikidata"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            assert len(popolo.organizations) == 1
            o = popolo.organizations[0]
            assert o.wikidata == 'Q288523'
            assert o.id == 'starfleet'
コード例 #29
0
    def test_person_sources(self):
        with example_file(b'''
{
    "persons": [
        {
            "id": "john-q-public",
            "name": "Mr. John Q. Public, Esq.",
            "sources": [
                {
                    "note": "His homepage",
                    "url": "http://example.org/john-q-public"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.sources == [{
                'note': 'His homepage',
                'url': 'http://example.org/john-q-public'
            }]
コード例 #30
0
    def test_person_facebook_and_links_list(self):
        with example_file(b'''
{
    "persons": [
        {
            "name": "Harry Truman",
            "links": [
                {
                    "note": "facebook",
                    "url": "https://facebook.example.com/harry-s-truman"
                },
                {
                    "note": "wikia",
                    "url": "http://twinpeaks.wikia.com/wiki/Harry_S._Truman"
                }
            ]
        }
    ]
}
''') as fname:
            popolo = Popolo.from_filename(fname)
            person = popolo.persons.first
            assert person.facebook == \
                'https://facebook.example.com/harry-s-truman'
            assert person.facebook_all == \
                ['https://facebook.example.com/harry-s-truman']
            assert person.links == [{
                "note":
                "facebook",
                "url":
                "https://facebook.example.com/harry-s-truman"
            }, {
                "note":
                "wikia",
                "url":
                "http://twinpeaks.wikia.com/wiki/Harry_S._Truman"
            }]