コード例 #1
0
def test_import_legislator():
    leg1 = {'_type': 'person', 'state': 'ex',
            'full_name': 'T. Rex Hagan',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': '2009-2010', 'district': '1',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}
    leg1_roles = leg1['roles']

    leg2 = {'_type': 'person', 'state': 'ex',
            'full_name': 'T. Rex Hagan',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': '2011-2012', 'district': '1',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg3 = {'_type': 'person', 'state': 'ex',
            'full_name': 'Joe Heck',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': '2009-2010', 'district': '2',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg4 = {'_type': 'person', 'state': 'ex',
            'full_name': 'Bob Dold',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': '2011-2012', 'district': '2',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}


    legislators.import_legislator(leg1)
    assert db.legislators.count() == 1

    legislators.import_legislator(leg2)
    t_rex = db.legislators.find_one({'_scraped_name': 'T. Rex Hagan'})
    assert db.legislators.count() == 1
    assert t_rex['roles'][0]['term'] == '2011-2012'
    assert '2009-2010' in t_rex['old_roles']

    legislators.import_legislator(leg3)
    assert db.legislators.count() == 2


    legislators.import_legislator(leg4)
    assert db.legislators.count() == 3
コード例 #2
0
def test_import_legislator():
    leg1 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'T. Rex Hagan',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T1',
            'district': '1',
            'party': 'Democrat',
            'start_date': None,
            'end_date': None
        }]
    }

    leg2 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'T. Rex Hagan',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T2',
            'district': '1',
            'party': 'Democrat',
            'start_date': None,
            'end_date': None
        }]
    }

    leg3 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'Joe Heck',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T1',
            'district': '2',
            'party': 'Democrat',
            'start_date': None,
            'end_date': None
        }]
    }

    leg4 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'Bob Dold',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T2',
            'district': '2',
            'party': 'Democrat',
            'start_date': None,
            'end_date': None
        }]
    }

    leg5 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'Bob Dold',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T0',
            'district': '2',
            'party': 'Democrat',
            'start_date': None,
            'end_date': None
        }]
    }

    leg6 = {
        '_type':
        'person',
        'state':
        'ex',
        'full_name':
        'Grey Sun',
        'roles': [{
            'role': 'member',
            'chamber': 'upper',
            'state': 'ex',
            'term': 'T0',
            'district': '9',
            'party': 'Libertarian',
            'start_date': None,
            'end_date': None
        }]
    }

    # T. Rex
    legislators.import_legislator(leg1)
    assert db.legislators.count() == 1

    # T. Rex's second role
    legislators.import_legislator(leg2)
    t_rex = db.legislators.find_one({'_scraped_name': 'T. Rex Hagan'})
    assert db.legislators.count() == 1
    assert t_rex['roles'][0]['term'] == 'T2'
    assert 'T1' in t_rex['old_roles']

    # Joe Heck in district 2
    legislators.import_legislator(leg3)
    assert db.legislators.count() == 2

    # Bob Dold replaces Joe Heck
    legislators.import_legislator(leg4)
    assert db.legislators.count() == 3

    # import a prior role for Bob Dold
    legislators.import_legislator(leg5)
    assert db.legislators.count() == 3
    dold = db.legislators.find_one({'_scraped_name': 'Bob Dold'})
    assert 'T0' in dold['old_roles']
    assert dold['roles'][0]['term'] == 'T2'

    # Grey Sun - old role only
    legislators.import_legislator(leg6)
    # moves the role to old _roles
    legislators.deactivate_legislators('T2', 'ex')
    # reimport should find him
    legislators.import_legislator(leg6)
    assert db.legislators.count() == 4

    # reimport all, make sure nothing changes
    for l in [leg1, leg2, leg3, leg4, leg5, leg6]:
        legislators.import_legislator(l)
        assert db.legislators.count() == 4
コード例 #3
0
ファイル: test_legislators.py プロジェクト: MdmCoffee/billy
def test_import_legislator():
    leg1 = {'_type': 'person', 'state': 'ex', 'full_name': 'T. Rex Hagan',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T1', 'district': '1',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg2 = {'_type': 'person', 'state': 'ex', 'full_name': 'T. Rex Hagan',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T2', 'district': '1',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg3 = {'_type': 'person', 'state': 'ex', 'full_name': 'Joe Heck',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T1', 'district': '2',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg4 = {'_type': 'person', 'state': 'ex', 'full_name': 'Bob Dold',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T2', 'district': '2',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg5 = {'_type': 'person', 'state': 'ex', 'full_name': 'Bob Dold',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T0', 'district': '2',
                       'party': 'Democrat',
                       'start_date': None, 'end_date': None}]}

    leg6 = {'_type': 'person', 'state': 'ex', 'full_name': 'Grey Sun',
            'roles': [{'role': 'member', 'chamber': 'upper', 'state': 'ex',
                       'term': 'T0', 'district': '9',
                       'party': 'Libertarian',
                       'start_date': None, 'end_date': None}]}

    # T. Rex
    legislators.import_legislator(leg1)
    assert db.legislators.count() == 1

    # T. Rex's second role
    legislators.import_legislator(leg2)
    t_rex = db.legislators.find_one({'_scraped_name': 'T. Rex Hagan'})
    assert db.legislators.count() == 1
    assert t_rex['roles'][0]['term'] == 'T2'
    assert 'T1' in t_rex['old_roles']

    # Joe Heck in district 2
    legislators.import_legislator(leg3)
    assert db.legislators.count() == 2

    # Bob Dold replaces Joe Heck
    legislators.import_legislator(leg4)
    assert db.legislators.count() == 3

    # import a prior role for Bob Dold
    legislators.import_legislator(leg5)
    assert db.legislators.count() == 3
    dold = db.legislators.find_one({'_scraped_name': 'Bob Dold'})
    assert 'T0' in dold['old_roles']
    assert dold['roles'][0]['term'] == 'T2'

    # Grey Sun - old role only
    legislators.import_legislator(leg6)
    # moves the role to old _roles
    legislators.deactivate_legislators('T2', 'ex')
    # reimport should find him
    legislators.import_legislator(leg6)
    assert db.legislators.count() == 4

    # reimport all, make sure nothing changes
    for l in [leg1, leg2, leg3, leg4, leg5, leg6]:
        legislators.import_legislator(l)
        assert db.legislators.count() == 4