Beispiel #1
0
    def test_us_adapter(self):
        f = open('tests/data/us_congress_representative.yaml', 'r')
        data = yaml.load(f.read())[0]
        f.close()

        data['bioguide_id'] = data['id']['bioguide']
        data['first_name'] = data['name']['first']
        data['last_name'] = data['name']['last']
        data['phone'] = data['terms'][0]['phone']
        data['title'] = "Senator" if data['terms'][0][
            'type'] == "sen" else "Representative"

        data_provider = USDataProvider({})
        key = data_provider.KEY_BIOGUIDE.format(**data)

        adapter = adapt_by_key(key)
        target = adapter.target(data)
        target['offices'] = adapter.offices(data)

        self.assertEqual(target['uid'], data['id']['bioguide'])
        self.assertEqual(target['name'], data['name']['official_full'])
        self.assertEqual(target['title'], 'Representative')
        self.assertEqual(target['number'], data['phone'])
        self.assertEqual(target['offices'][0]['number'],
                         data['offices'][0]['phone'])
Beispiel #2
0
    def setUpClass(cls):
        # quiet logging
        logging.getLogger('cache').setLevel(logging.WARNING)
        logging.getLogger(__name__).setLevel(logging.WARNING)

        cls.mock_cache = {}  # mock flask-cache outside of application context
        cls.us_data = USDataProvider(cls.mock_cache, 'localmem')
        cls.us_data.load_data()
Beispiel #3
0
    def test_usstate_adapter(self):
        f = open('tests/data/openstates_representative.json', 'r')
        data = json.loads(f.read())[0]
        f.close()

        data_provider = USDataProvider({})
        key = data_provider.KEY_OPENSTATES.format(**data)

        adapter = adapt_by_key(key)
        target = adapter.target(data)
        target['offices'] = adapter.offices(data)

        self.assertEqual(target['uid'], data['id'])
        self.assertEqual(target['name'], data['full_name'])
        self.assertEqual(target['title'], 'Senator')
        self.assertEqual(target['number'], data['offices'][0]['phone'])
        self.assertEqual(target['offices'][0]['number'],
                         data['offices'][1]['phone'])
Beispiel #4
0
 def setUpClass(cls):
     cls.mock_cache = {}  # mock flask-cache outside of application context
     cls.us_data = USDataProvider(cls.mock_cache, 'localmem')
     cls.us_data.load_data()