コード例 #1
0
    def test_data_rendering(self):
        bill = factories.fake_bill_detail()
        bill_id = bill['bill_id']
        session = bill['session']

        with mock_fetch() as fetch:
            fetch.bill_detail.return_value = bill
            html = render_view('openstates:bill-detail',
                               kwargs={
                                   'session': session,
                                   'id': bill_id
                               })

        fetch.bill_detail.assert_called_once_with(session=session, pk=bill_id)

        assert bill_id in html
        assert bill['title'] in html
        assert bill['subjects'][0] in html
        assert str(session) in html

        action, date = list(bill['action_dates'].items())[0]
        date, timestamp = date.split()
        assert action in html
        assert date in html
        assert timestamp not in html

        vote = bill['votes'][0]
        date, timestamp = vote['date'].split()
        assert date in html
        assert timestamp not in html
        assert str(vote['yes_count']) in html
        assert str(vote['no_count']) in html
        assert vote['chamber'] in html
コード例 #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
コード例 #3
0
    def test_sync_func_is_failure(self):
        command = sync_bills_from_openstate.Command()

        failure_info = ActionInfo.fail('error message')
        with mock_dependencies(command,
                               return_sync_info=failure_info) as mocked:
            mocked.fetch.bills.return_value = [factories.fake_bill()]
            mocked.fetch.bill_detail.return_value = factories.fake_bill_detail(
            )
            command.handle(max=None, force_update=False)

        mocked.sync_func.assert_called_once()
        mocked.stdout.write.assert_any_call(StringContaining('error message'))
コード例 #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
コード例 #5
0
    def test_sync_func_is_successful(self):
        command = sync_bills_from_openstate.Command()

        bill = BillFactory.build()
        bill_item = factories.fake_bill()
        bill_detail_data = factories.fake_bill_detail()
        success_info = ActionInfo.create(Action.ADDED, bill)
        with mock_dependencies(command,
                               return_sync_info=success_info) as mocked:
            mocked.fetch.bills.return_value = [bill_item]
            mocked.fetch.bill_detail.return_value = bill_detail_data
            command.handle(max=None, force_update=False)

        # `fetch.bill_detail` should be called with official `bill_id` not openstates `id`.
        mocked.fetch.bill_detail.assert_called_once_with(
            bill_item['session'], bill_item['bill_id'])
        mocked.sync_func.assert_called_once_with(bill_detail_data,
                                                 force_update=False)
        mocked.stdout.write.assert_any_call(
            StringContaining(bill.openstates_bill_id))
コード例 #6
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
コード例 #7
0
    def test_sync_bill_with_long_bill_id(self):
        bad_data = fake_bill_detail()
        bad_data['id'] = 'X' * 100

        info = services.sync_bill_data(bad_data)
        assert info.action == services.Action.FAILED
コード例 #8
0
 def test_deserialize_bill_detail_with_no_subjects(self):
     bill_detail = factories.fake_bill_detail()
     del bill_detail['subjects']
     self.assert_data_adds_single_row(bill_detail)
コード例 #9
0
 def test_deserialize_fake_bill_detail(self):
     self.assert_data_adds_single_row(factories.fake_bill_detail())