Example #1
0
    def test_no_data(self):
        command = sync_legislators_from_openstate.Command()
        with mock_dependencies(command, return_legislators=()) as mocked:
            command.handle(max=None, leg_ids=None)

        mocked.fetch.legislators.assert_called_once_with()
        mocked.stdout.write.assert_called_once_with(StringContaining('No data'))
Example #2
0
    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'))
Example #3
0
    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))