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)
Exemple #2
0
    def test_bill_detail_fails(self):
        command = sync_bills_from_openstate.Command()

        with mock_dependencies(command) as mocked:
            mocked.fetch.bills.return_value = [factories.fake_bill()]
            mocked.fetch.bill_detail.return_value = mock.Mock(
                status_code=404, reason='Not Found')
            command.handle(max=None, force_update=False)

        mocked.sync_func.assert_not_called()
        mocked.stdout.write.assert_any_call(StringContaining('Not Found'))
Exemple #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'))
Exemple #4
0
    def test_data_rendering(self):
        bill = factories.fake_bill()
        detail_url = reverse('openstates:bill-detail',
                             args=(bill['session'], bill['bill_id']))

        with mock_fetch() as fetch:
            fetch.bills.return_value = [bill]
            html = render_view('openstates:bill-list')

        assert detail_url in html
        assert bill['bill_id'] in html
        assert bill['title'] in html
        assert bill['subjects'] in html
        assert bill['session'] in html
Exemple #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))