示例#1
0
def test_import_bill_with_partial_bill_vote_id():
    # test a hack added for Rhode Island where vote bill_ids are missing
    # their prefix (ie. 7033 instead of HB 7033)
    # fixture's yz state has _partial_vote_bill_id enabled
    data = {'_type': 'bill', 'state': 'yz', 'bill_id': 'S1',
            'chamber': 'upper', 'session': 'S1a',
            'title': 'main title',
            'sponsors': [],
            'versions': [],
            'documents': [],
            'votes': [],
            'actions': [],
            'companions': [],
           }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1a', '1'): [
            {'motion': 'house passage', 'chamber': 'lower', 'date': None,
             'yes_count': 1, 'no_count': 0, 'other_count': 0,
             'yes_votes': [], 'no_votes': [], 'other_votes': [],
            }
        ]
    }

    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes),
                      None)

    bill = db.bills.find_one()
    assert bill['bill_id'] == 'S 1'
    vote = db.votes.find_one()
    assert vote['motion'] == 'house passage'
    assert vote['chamber'] == 'lower'
示例#2
0
def test_import_bill_with_partial_bill_vote_id():
    # test a hack added for Rhode Island where vote bill_ids are missing
    # their prefix (ie. 7033 instead of HB 7033)
    db.metadata.insert({'level': 'state', '_id': 'zz',
                        'terms': [{'name': 'T1', 'sessions': ['S1', 'S2']}],
                        '_partial_vote_bill_id': True,
                       })
    data = {'_type': 'bill', 'level': 'state', 'state': 'zz', 'bill_id': 'S1',
            'chamber': 'upper', 'session': 'S1',
            'title': 'main title',
            'sponsors': [],
            'versions': [],
            'documents': [],
            'votes': [],
           }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1', '1'): [
          {'motion': 'house passage', 'chamber': 'lower', 'date': None,
           'yes_count': 1, 'no_count': 0, 'other_count': 0,
           'yes_votes': [], 'no_votes': [], 'other_votes': [],
          }
        ]
    }

    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes),
                      None)

    bill = db.bills.find_one()
    assert bill['bill_id'] == 'S 1'
    assert bill['votes'][0]['motion'] == 'house passage'
    assert bill['votes'][0]['chamber'] == 'lower'
示例#3
0
def test_import_bill_with_partial_bill_vote_id():
    # test a hack added for Rhode Island where vote bill_ids are missing
    # their prefix (ie. 7033 instead of HB 7033)
    db.metadata.insert({
        'level': 'state',
        '_id': 'zz',
        'terms': [{
            'name': 'T1',
            'sessions': ['S1', 'S2']
        }],
        '_partial_vote_bill_id': True,
    })
    data = {
        '_type': 'bill',
        'level': 'state',
        'state': 'zz',
        'bill_id': 'S1',
        'chamber': 'upper',
        'session': 'S1',
        'title': 'main title',
        'sponsors': [],
        'versions': [],
        'documents': [],
        'votes': [],
    }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1', '1'): [{
            'motion': 'house passage',
            'chamber': 'lower',
            'date': None,
            'yes_count': 1,
            'no_count': 0,
            'other_count': 0,
            'yes_votes': [],
            'no_votes': [],
            'other_votes': [],
        }]
    }

    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes),
                      None)

    bill = db.bills.find_one()
    assert bill['bill_id'] == 'S 1'
    assert bill['votes'][0]['motion'] == 'house passage'
    assert bill['votes'][0]['chamber'] == 'lower'
示例#4
0
def test_import_bill():
    companion_data = {'_type': 'bill', 'state': 'ex', 'bill_id': 'A1',
                      'chamber': 'upper', 'session': 'S1',
                      'title': 'companion', 'sponsors': [], 'versions': [],
                      'documents': [], 'votes': [], 'actions': [],
                      'companions': [],
                     }
    data = {'_type': 'bill', 'state': 'ex', 'bill_id': 'S1',
            'chamber': 'upper', 'session': 'S1',
            'subjects': ['Pigs', 'Sheep', 'Horses'],
            'sponsors': [{'name': 'Adams', 'type': 'primary'},
                         {'name': 'Jackson', 'type': 'cosponsor'}],
            'title': 'main title',
            'alternate_titles': ['second title'],
            'companions': [{'bill_id': 'A1', 'session': 'S1', 'chamber': None}
                          ],
            'versions': [{'title': 'old title',
                          'url': 'http://example.com/old'},
                         {'title': 'main title',
                          'url': 'http://example.com/current'},
                         ],
            'documents': [{'title': 'fiscal note',
                          'url': 'http://example.com/fn'}],
            'actions': [{'action': 'Introduced', 'type': ['bill:introduced'],
                         'actor': 'upper', 'date': 1331000000},
                        {'action': 'Referred to committee',
                         'type': ['committee:referred'], 'actor': 'upper',
                         'date': 1332000000},
                        {'action': 'Passed by voice vote',
                         'type': ['bill:passed'], 'actor': 'upper',
                         'date': 1333000000},
                        {'action': 'Signed', 'type': ['governor:signed'],
                         'actor': 'governor', 'date': 1334000000},
                       ],
            'votes': [{'motion': 'passage', 'chamber': 'upper', 'date': None,
                       'yes_count': 1, 'no_count': 1, 'other_count': 0,
                       'yes_votes': ['John Adams'],
                       'no_votes': ['John Quincy Adams'],
                       'other_votes': [],
                      },
                      {'motion': 'referral', 'chamber': 'upper', 'date': None,
                       'yes_count': 0, 'no_count': 0, 'other_count': 0,
                       'yes_votes': [], 'no_votes': [], 'other_votes': [],
                       'committee': 'Committee on Agriculture',
                      }],
           }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1', 'S 1'): [
            {'motion': 'house passage', 'chamber': 'lower', 'date': None,
             'yes_count': 1, 'no_count': 0, 'other_count': 0,
             'yes_votes': [], 'no_votes': [], 'other_votes': [],
            }
        ]
    }

    # deepcopy here so we can reinsert same data without modification
    bills.import_bill(copy.deepcopy(companion_data), {}, None)
    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes),
                      None)

    a1 = db.bills.find_one({'bill_id': 'A 1'})
    assert a1['_id'] == 'EXB00000001'

    # test that basics work
    bill = db.bills.find_one({'bill_id': 'S 1'})
    assert bill['_id'] == 'EXB00000002'
    assert bill['bill_id'] == 'S 1'
    assert bill['chamber'] == 'upper'
    assert bill['scraped_subjects'] == data['subjects']
    assert 'subjects' not in bill
    assert bill['_term'] == 'T1'
    assert bill['created_at'] == bill['updated_at']

    # assure sponsors are there and that John Adams gets matched
    assert len(bill['sponsors']) == 2
    assert bill['sponsors'][0]['leg_id'] == 'EXL000001'

    # test vote import
    bill_votes = db.votes.find()
    assert bill_votes.count() == 3
    assert bill_votes[0]['vote_id'] == 'EXV00000001'
    assert bill_votes[0]['yes_votes'][0]['leg_id'] == 'EXL000001'
    assert 'committee_id' in bill_votes[1]

    # test actions
    assert bill['action_dates']['first'] == 1331000000
    assert bill['action_dates']['last'] == 1334000000
    assert bill['action_dates']['passed_upper'] == 1333000000
    assert bill['action_dates']['signed'] == 1334000000
    assert bill['action_dates']['passed_lower'] is None

    # titles from alternate_titles & versions (not main title)
    assert 'main title' not in bill['alternate_titles']
    assert 'second title' in bill['alternate_titles']
    assert 'old title' in bill['alternate_titles']

    # test version/document import
    assert_equal(bill['versions'][0]['doc_id'], 'EXD00000001')
    assert bill['versions'][1]['doc_id'] == 'EXD00000002'
    assert bill['documents'][0]['doc_id'] == 'EXD00000003'

    # test companions
    bill['companions'][0]['internal_id'] == 'EXB000000001'

    # now test an update
    data['versions'].append({'title': 'third title',
                             'url': 'http://example.com/3rd'})
    data['sponsors'].pop()
    bills.import_bill(data, standalone_votes, None)

    # still only two bills
    assert db.bills.count() == 2
    bill = db.bills.find_one('EXB00000002')

    # votes haven't changed, versions, titles, and sponsors have
    bill_votes = db.votes.find()
    assert bill_votes.count() == 3
    assert bill_votes[0]['vote_id'] == 'EXV00000001'
    assert len(bill['versions']) == 3
    assert len(bill['sponsors']) == 1
    assert 'third title' in bill['alternate_titles']
    # check that old doc ids haven't changed, and new one is 4
    assert bill['versions'][0]['doc_id'] == 'EXD00000001'
    assert bill['versions'][1]['doc_id'] == 'EXD00000002'
    assert bill['versions'][2]['doc_id'] == 'EXD00000004'
    assert bill['documents'][0]['doc_id'] == 'EXD00000003'
示例#5
0
def test_import_bill():
    data = {'_type': 'bill', 'level': 'state', 'state': 'ex', 'bill_id': 'S1',
            'chamber': 'upper', 'session': 'S1',
            'subjects': ['Pigs', 'Sheep', 'Horses'],
            'sponsors': [{'name': 'Adams', 'type': 'primary'},
                         {'name': 'Jackson', 'type': 'cosponsor'}],
            'title': 'main title',
            'alternate_titles': ['second title'],
            'versions': [{'title': 'old title'},
                         {'title': 'main title'}],
            'votes': [{'motion': 'passage', 'chamber': 'upper', 'date': None,
                       'yes_count': 1, 'no_count': 1, 'other_count': 0,
                       'yes_votes': ['John Adams'],
                       'no_votes': ['John Quincy Adams'],
                       'other_votes': [],
                      },
                      {'motion': 'referral', 'chamber': 'upper', 'date': None,
                       'yes_count': 0, 'no_count': 0, 'other_count': 0,
                       'yes_votes': [], 'no_votes': [], 'other_votes': [],
                       'committee': 'Committee on Agriculture',
                      }],
           }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1', 'S 1'): [
          {'motion': 'house passage', 'chamber': 'lower', 'date': None,
           'yes_count': 1, 'no_count': 0, 'other_count': 0,
           'yes_votes': [], 'no_votes': [], 'other_votes': [],
          }
        ]
    }

    # deepcopy both so we can reinsert same data without modification
    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes))

    # test that basics work
    bill = db.bills.find_one()
    assert bill['bill_id'] == 'S 1'
    assert bill['chamber'] == 'upper'
    assert bill['scraped_subjects'] == data['subjects']
    assert 'subjects' not in bill
    assert bill['_term'] == 'T1'
    assert '_keywords' in bill
    assert bill['created_at'] == bill['updated_at']

    # assure sponsors are there and that John Adams gets matched
    assert len(bill['sponsors']) == 2
    assert bill['sponsors'][0]['leg_id'] == 'EXL000001'

    # test vote import
    assert len(bill['votes']) == 3
    assert bill['votes'][0]['vote_id'] == 'EXV00000001'
    assert bill['votes'][0]['yes_votes'][0]['leg_id'] == 'EXL000001'
    assert 'committee_id' in bill['votes'][1]

    # titles from alternate_titles & versions (not main title)
    assert 'main title' not in bill['alternate_titles']
    assert 'second title' in bill['alternate_titles']
    assert 'old title' in bill['alternate_titles']

    # now test an update
    data['versions'].append({'title': 'third title'})
    data['sponsors'].pop()
    bills.import_bill(data, standalone_votes)

    # still only one bill
    assert db.bills.count() == 1
    bill = db.bills.find_one()

    # votes haven't changed, versions, titles, and sponsors have
    assert len(bill['votes']) == 3
    assert bill['votes'][0]['vote_id'] == 'EXV00000001'
    assert len(bill['versions']) == 3
    assert len(bill['sponsors']) == 1
    assert 'third title' in bill['alternate_titles']
示例#6
0
def test_import_bill():
    data = {
        '_type':
        'bill',
        'level':
        'state',
        'state':
        'ex',
        'bill_id':
        'S1',
        'chamber':
        'upper',
        'session':
        'S1',
        'subjects': ['Pigs', 'Sheep', 'Horses'],
        'sponsors': [{
            'name': 'Adams',
            'type': 'primary'
        }, {
            'name': 'Jackson',
            'type': 'cosponsor'
        }],
        'title':
        'main title',
        'alternate_titles': ['second title'],
        'versions': [{
            'title': 'old title'
        }, {
            'title': 'main title'
        }],
        'votes': [{
            'motion': 'passage',
            'chamber': 'upper',
            'date': None,
            'yes_count': 1,
            'no_count': 1,
            'other_count': 0,
            'yes_votes': ['John Adams'],
            'no_votes': ['John Quincy Adams'],
            'other_votes': [],
        }, {
            'motion': 'referral',
            'chamber': 'upper',
            'date': None,
            'yes_count': 0,
            'no_count': 0,
            'other_count': 0,
            'yes_votes': [],
            'no_votes': [],
            'other_votes': [],
            'committee': 'Committee on Agriculture',
        }],
    }
    standalone_votes = {
        # chamber, session, bill id -> vote list
        ('upper', 'S1', 'S 1'): [{
            'motion': 'house passage',
            'chamber': 'lower',
            'date': None,
            'yes_count': 1,
            'no_count': 0,
            'other_count': 0,
            'yes_votes': [],
            'no_votes': [],
            'other_votes': [],
        }]
    }

    # deepcopy both so we can reinsert same data without modification
    bills.import_bill(copy.deepcopy(data), copy.deepcopy(standalone_votes))

    # test that basics work
    bill = db.bills.find_one()
    assert bill['bill_id'] == 'S 1'
    assert bill['chamber'] == 'upper'
    assert bill['scraped_subjects'] == data['subjects']
    assert 'subjects' not in bill
    assert bill['_term'] == 'T1'
    assert '_keywords' in bill
    assert bill['created_at'] == bill['updated_at']

    # assure sponsors are there and that John Adams gets matched
    assert len(bill['sponsors']) == 2
    assert bill['sponsors'][0]['leg_id'] == 'EXL000001'

    # test vote import
    assert len(bill['votes']) == 3
    assert bill['votes'][0]['vote_id'] == 'EXV00000001'
    assert bill['votes'][0]['yes_votes'][0]['leg_id'] == 'EXL000001'
    assert 'committee_id' in bill['votes'][1]

    # titles from alternate_titles & versions (not main title)
    assert 'main title' not in bill['alternate_titles']
    assert 'second title' in bill['alternate_titles']
    assert 'old title' in bill['alternate_titles']

    # now test an update
    data['versions'].append({'title': 'third title'})
    data['sponsors'].pop()
    bills.import_bill(data, standalone_votes)

    # still only one bill
    assert db.bills.count() == 1
    bill = db.bills.find_one()

    # votes haven't changed, versions, titles, and sponsors have
    assert len(bill['votes']) == 3
    assert bill['votes'][0]['vote_id'] == 'EXV00000001'
    assert len(bill['versions']) == 3
    assert len(bill['sponsors']) == 1
    assert 'third title' in bill['alternate_titles']