Beispiel #1
0
    def test_deserialize_bill_item_fails(self):
        """Assert that syncing using bill-list data (not bill-detail data) fails."""
        api_data = factories.fake_bill()

        with mock.patch.object(utils, 'LOG') as mock_log:
            with self.assertRaises(Exception):
                utils.deserialize_openstates_bill(api_data)
Beispiel #2
0
    def test_deserialize_same_bill_id_twice_adds_single_row(self):
        """Assert that identitical Open States bill id used to detect and prevent duplicates."""
        api_data = factories.fake_bill_detail()

        with mock.patch.object(utils, 'LOG') as mock_log:
            utils.deserialize_openstates_bill(api_data)
            bill = utils.deserialize_openstates_bill(api_data)

        assert Bill.objects.all().count() == 1
Beispiel #3
0
    def assert_data_adds_single_row(self, api_data):
        assert not Bill.objects.all().exists()

        with mock.patch.object(utils, 'LOG') as mock_log:
            bill = utils.deserialize_openstates_bill(api_data)

        testing.assert_bill_fields_match_data(bill, api_data)
        assert Bill.objects.all().count() == 1
Beispiel #4
0
    def test_deserialize_same_vote_id_twice_adds_single_row(self):
        """Assert that identitical Open States vote id used to detect and prevent duplicates."""
        api_data = factories.fake_bill_detail()

        with mock.patch.object(utils, 'LOG'):
            utils.deserialize_openstates_bill(api_data)

        assert VoteTally.objects.all().count() == 1

        bill = Bill.objects.all().first()

        # Deserializing vote data from fake-bill should not add the same vote tally again.
        with mock.patch.object(utils, 'LOG'):
            vote_data = api_data['votes'][0]
            vote_data['bill'] = bill.id
            utils.adapt_openstates_vote_tally(vote_data)  # modifies data in-place.
            utils.deserialize_vote_tally(vote_data)

        assert VoteTally.objects.all().count() == 1
Beispiel #5
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