Beispiel #1
0
    def test_deserialize_bill_with_valid_legislator_vote(self):
        """Most tests skip vote attribution because legislators been created.

        This test adds a legislator to the database so that a vote can be attributed to that
        legislator on the given bill.
        """
        bill_data = factories.fake_bill_detail()
        legislator_data = factories.fake_legislator()
        # Attribute vote on bill to legislator.
        bill_data['votes'][0]['yes_votes'][0]['leg_id'] = legislator_data['leg_id']

        with mock.patch.object(utils, 'LOG'):
            legislator = utils.deserialize_openstates_legislator(legislator_data)
            bill = utils.deserialize_openstates_bill(bill_data)
            # Deserializing a second time should not create a second vote.
            utils.deserialize_openstates_bill(bill_data)

        assert SingleVote.objects.all().count() == 1
        vote = SingleVote.objects.all().first()
        assert vote.legislator == legislator
        assert vote.vote_tally.bill == bill
Beispiel #2
0
    def test_deserialize_with_missing_required_field_raises(self):
        api_data = data.get_sample_legislator_detail()
        del api_data['first_name']  # Delete required key, first_name

        with pytest.raises(ValidationError):
            legislator = utils.deserialize_openstates_legislator(api_data)
Beispiel #3
0
 def test_deserialize_from_openstates_sample(self):
     api_data = data.get_sample_legislator_detail()
     legislator = utils.deserialize_openstates_legislator(api_data,
                                                          commit=False)
     testing.assert_legislator_fields_match_data(legislator, api_data)