Esempio n. 1
0
    def test_sync_existing_bill_skips_older(self):
        instance = BillFactory.create()
        older_data = {
            'id':
            instance.openstates_bill_id,
            'updated_at':
            utils.format_datetime(instance.openstates_updated_at - ONE_DAY),
        }

        with mock.patch.object(
                utils, 'deserialize_openstates_bill') as mock_deserialize:
            info = services.sync_bill_data(older_data)

        mock_deserialize.assert_not_called()
        assert info.action == services.Action.SKIPPED
Esempio n. 2
0
    def test_sync_existing_bill_updates_given_newer_data(self):
        instance = BillFactory.create()
        newer_data = {
            'id':
            instance.openstates_bill_id,
            'updated_at':
            utils.format_datetime(instance.openstates_updated_at + ONE_DAY),
        }

        with mock.patch.object(
                utils, 'deserialize_openstates_bill') as mock_deserialize:
            info = services.sync_bill_data(newer_data)

        mock_deserialize.assert_called_once_with(newer_data, instance=instance)
        assert info.action == services.Action.UPDATED
Esempio n. 3
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))