def test_sync_func_is_failure(self): command = sync_legislators_from_openstate.Command() failure_info = ActionInfo.fail('error message') with mock_dependencies(command, return_sync_info=failure_info) as mocked: command.handle(max=None, leg_ids=None) mocked.sync_func.assert_called_once() mocked.stdout.write.assert_any_call(StringContaining('error message'))
def test_sync_func_is_successful(self): command = sync_legislators_from_openstate.Command() legislator = LegislatorFactory.build() success_info = ActionInfo.create(Action.ADDED, legislator) with mock_dependencies(command, return_sync_info=success_info) as mocked: command.handle(max=None, leg_ids=None) mocked.sync_func.assert_called_once() mocked.stdout.write.assert_any_call(StringContaining(legislator.first_name)) mocked.stdout.write.assert_any_call(StringContaining(legislator.last_name)) mocked.stdout.write.assert_any_call(StringContaining(legislator.openstates_leg_id))
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'))
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))