def test_remove( self, mock_echo, mock_detail, mock_update, mock_version, ): """Validate standard behavior.""" mock_detail.return_value = self._get_bundle(patches=[{ 'id': 1 }, { 'id': 2 }, { 'id': 3 }], ) mock_update.return_value = self._get_bundle() runner = CLIRunner() result = runner.invoke(bundle.remove_cmd, ['1', '1', '2']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('bundles', '1') mock_update.assert_called_once_with( 'bundles', '1', [('patches', (3, ))], )
def test_list_with_filters(self, mock_echo, mock_index, mock_version): """Validate behavior with filters applied. Apply all filters, including those for pagination. """ submitter_rsp = [self._get_person()] delegate_rsp = [self._get_person()] patch_rsp = [self._get_patch()] mock_index.side_effect = [submitter_rsp, delegate_rsp, patch_rsp] runner = CLIRunner() result = runner.invoke(patch.list_cmd, [ '--state', 'new', '--submitter', '*****@*****.**', '--submitter', '2', '--delegate', '*****@*****.**', '--delegate', '2', '--hash', 'foo', '--archived', '--limit', 1, '--page', 1, '--sort', '-name', 'test']) assert result.exit_code == 0, result calls = [ mock.call('people', [('q', '*****@*****.**')]), mock.call('users', [('q', '*****@*****.**')]), mock.call('patches', [ ('state', 'new'), ('submitter', 1), ('submitter', '2'), ('delegate', 1), ('delegate', '2'), ('hash', 'foo'), ('q', 'test'), ('archived', 'true'), ('page', 1), ('per_page', 1), ('order', '-name')])] mock_index.assert_has_calls(calls)
def test_remove_empty( self, mock_log, mock_echo, mock_detail, mock_update, mock_version, ): """Validate behavior when deleting would remove all patches.""" mock_detail.return_value = self._get_bundle(patches=[{ 'id': 1 }, { 'id': 2 }, { 'id': 3 }], ) mock_update.return_value = self._get_bundle() runner = CLIRunner() result = runner.invoke(bundle.remove_cmd, ['1', '1', '2', '3']) assert result.exit_code == 1, result.output assert mock_log.error.called mock_detail.assert_called_once_with('bundles', '1') mock_update.assert_not_called()
def test_list_api_v1_1(self, mock_log, mock_echo, mock_index, mock_version): """Validate behavior with API v1.1.""" mock_version.return_value = (1, 1) people_rsp = [self._get_people()] series_rsp = [self._get_series()] mock_index.side_effect = [people_rsp, series_rsp] runner = CLIRunner() result = runner.invoke(series.list_cmd, [ '--submitter', '*****@*****.**', '--submitter', 'John Doe']) assert result.exit_code == 0, result # We should have only made a single call to '/people' since API v1.1 # supports filtering with emails natively calls = [ mock.call('people', [('q', 'John Doe')]), mock.call('series', [ ('submitter', '*****@*****.**'), ('submitter', 1), ('q', None), ('page', None), ('per_page', None), ('order', '-date')])] mock_index.assert_has_calls(calls) # We shouldn't see a warning about multiple versions either assert not mock_log.warning.called
def test_list_api_v1_1(self, mock_log, mock_echo, mock_index, mock_version): """Validate behavior with API v1.1.""" mock_version.return_value = (1, 1) user_rsp = [self._get_users()] bundle_rsp = [self._get_bundle()] mock_index.side_effect = [user_rsp, bundle_rsp] runner = CLIRunner() result = runner.invoke(bundle.list_cmd, [ '--owner', 'john.doe', '--owner', 'user.b', '--owner', '*****@*****.**' ]) assert result.exit_code == 0, result # We should have only made a single call to '/users' (for the user # specified by an email address) since API v1.1 supports filtering with # usernames natively calls = [ mock.call('users', [('q', '*****@*****.**')]), mock.call('bundles', [('owner', 'john.doe'), ('owner', 'user.b'), ('owner', 1), ('q', None), ('page', None), ('per_page', None), ('order', 'name')]) ] mock_index.assert_has_calls(calls) # We shouldn't see a warning about multiple versions either assert not mock_log.warning.called
def test_list_with_filters(self, mock_echo, mock_index, mock_version): """Validate behavior with filters applied. Apply all filters, including those for pagination. """ user_rsp = [self._get_users()] bundle_rsp = [self._get_bundle()] mock_index.side_effect = [user_rsp, bundle_rsp] runner = CLIRunner() result = runner.invoke(bundle.list_cmd, [ '--owner', 'john.doe', '--owner', '2', '--limit', 1, '--page', 1, '--sort', '-name', 'test' ]) assert result.exit_code == 0, result calls = [ mock.call('users', [('q', 'john.doe')]), mock.call('bundles', [('owner', 1), ('owner', '2'), ('q', 'test'), ('page', 1), ('per_page', 1), ('order', '-name')]) ] mock_index.assert_has_calls(calls)
def test_update_no_arguments(self, mock_states, mock_show, mock_update): """Validate behavior with no arguments.""" runner = CLIRunner() result = runner.invoke(patch.update_cmd, ['123']) assert result.exit_code == 0, result mock_update.assert_called_once_with('patches', 123, []) mock_show.assert_called_once_with(mock_update.return_value, None)
def test_create_api_v1_1(self, mock_log, mock_echo, mock_create, mock_version): mock_version.return_value = (1, 1) runner = CLIRunner() result = runner.invoke(bundle.create_cmd, ['hello', '1', '2']) assert result.exit_code == 1, result assert mock_log.error.called
def test_delete(self, mock_echo, mock_delete, mock_version): """Validate standard behavior.""" mock_delete.return_value = None runner = CLIRunner() result = runner.invoke(bundle.delete_cmd, ['hello']) assert result.exit_code == 0, result mock_delete.assert_called_once_with('bundles', 'hello')
def test_show(self, mock_detail): """Validate standard behavior.""" rsp = self._get_series() mock_detail.return_value = rsp runner = CLIRunner() result = runner.invoke(series.show_cmd, ['123']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('series', 123)
def test_show(self, mock_get_bundle): """Validate standard behavior.""" rsp = self._get_bundle() mock_get_bundle.return_value = rsp runner = CLIRunner() result = runner.invoke(bundle.show_cmd, ['123']) assert result.exit_code == 0, result mock_get_bundle.assert_called_once_with('123')
def test_list_with_formatting(self, mock_echo, mock_index, mock_version): rsp = [self._get_patch()] mock_index.return_value = rsp runner = CLIRunner() result = runner.invoke(patch.list_cmd, [ '--format', 'simple', '--column', 'ID', '--column', 'Name']) assert result.exit_code == 0, result mock_echo.assert_called_once_with(mock.ANY, ('ID', 'Name'), fmt='simple')
def test_download(self, mock_download, mock_detail): """Validate standard behavior.""" rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'} mock_detail.return_value = rsp runner = CLIRunner() result = runner.invoke(series.download_cmd, ['123']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('series', 123) mock_download.assert_called_once_with(rsp['mbox'], output=None)
def test_create(self, mock_echo, mock_create, mock_version): """Validate standard behavior.""" mock_create.return_value = self._get_bundle() runner = CLIRunner() result = runner.invoke(bundle.create_cmd, ['hello', '1', '2']) assert result.exit_code == 0, result mock_create.assert_called_once_with('bundles', [('name', 'hello'), ('patches', (1, 2)), ('public', False)])
def test_list(self, mock_echo, mock_index, mock_version): """Validate standard behavior.""" rsp = [self._get_series()] mock_index.return_value = rsp runner = CLIRunner() result = runner.invoke(series.list_cmd, []) assert result.exit_code == 0, result mock_index.assert_called_once_with('series', [ ('q', None), ('page', None), ('per_page', None), ('order', '-date')])
def test_update_with_arguments(self, mock_states, mock_show, mock_update): """Validate behavior with all arguments except delegate.""" mock_states.return_value = ['new'] runner = CLIRunner() result = runner.invoke(patch.update_cmd, [ '123', '--commit-ref', '3ed8fb12', '--state', 'new', '--archived', '1', '--format', 'table']) assert result.exit_code == 0, result mock_update.assert_called_once_with('patches', 123, [ ('commit_ref', '3ed8fb12'), ('state', 'new'), ('archived', True)]) mock_show.assert_called_once_with(mock_update.return_value, 'table')
def test_apply_without_deps(self, mock_git_am, mock_download, mock_detail): """Validate behavior without using dependencies.""" rsp = {'mbox': 'hello, world'} mock_detail.return_value = rsp mock_download.return_value = object() runner = CLIRunner() result = runner.invoke(patch.apply_cmd, ['123', '--no-deps']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('patches', 123) mock_download.assert_called_once_with(rsp['mbox'], {'series': None}) mock_git_am.assert_called_once_with(mock_download.return_value, ())
def test_download(self, mock_log, mock_download, mock_detail): """Validate standard behavior.""" rsp = {'mbox': 'hello, world', 'diff': 'test'} mock_detail.return_value = rsp mock_download.return_value = '/tmp/abc123.patch' runner = CLIRunner() result = runner.invoke(patch.download_cmd, ['123']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('patches', 123) mock_download.assert_called_once_with(rsp['mbox'], output=None) assert mock_log.info.called
def test_list_with_formatting(self, mock_echo, mock_index, mock_version): """Validate behavior with formatting applied.""" rsp = [self._get_series()] mock_index.return_value = rsp runner = CLIRunner() result = runner.invoke(series.list_cmd, [ '--format', 'simple', '--column', 'ID', '--column', 'Name']) assert result.exit_code == 0, result mock_echo.assert_called_once_with(mock.ANY, ('ID', 'Name'), fmt='simple')
def test_apply_without_args(self, mock_git_am, mock_download, mock_detail): """Validate calling with no arguments.""" rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'} mock_detail.return_value = rsp mock_download.return_value = 'test.patch' runner = CLIRunner() result = runner.invoke(series.apply_cmd, ['123']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('series', 123) mock_download.assert_called_once_with(rsp['mbox']) mock_git_am.assert_called_once_with(mock_download.return_value, ())
def test_download(self, mock_get, mock_download, mock_get_bundle): """Validate standard behavior.""" rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'} mock_get_bundle.return_value = rsp mock_download.return_value = 'test.patch' runner = CLIRunner() result = runner.invoke(bundle.download_cmd, ['123']) assert result.exit_code == 0, result mock_get_bundle.assert_called_once_with('123') mock_download.assert_called_once_with(rsp['mbox']) mock_get.assert_not_called()
def test_download_to_file(self, mock_download, mock_detail): """Validate downloading to a file.""" rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'} mock_detail.return_value = rsp runner = CLIRunner() result = runner.invoke(series.download_cmd, ['123', 'test.patch']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('series', 123) mock_download.assert_called_once_with(rsp['mbox'], output=mock.ANY) assert isinstance( mock_download.call_args[1]['output'], click_utils.LazyFile, )
def test_update_with_invalid_state( self, mock_states, mock_show, mock_update): """Validate behavior with invalid state.""" mock_states.return_value = ['foo'] runner = CLIRunner() result = runner.invoke(patch.update_cmd, [ '123', '--state', 'bar']) assert result.exit_code == 2, result if version.parse(click.__version__) >= version.Version('7.1'): assert "Invalid value for '--state'" in result.output, result else: assert 'Invalid value for "--state"' in result.output, result
def test_update_with_delegate( self, mock_index, mock_states, mock_show, mock_update): """Validate behavior with delegate argument.""" mock_index.return_value = [self._get_person()] runner = CLIRunner() result = runner.invoke(patch.update_cmd, [ '123', '--delegate', '*****@*****.**']) assert result.exit_code == 0, result mock_index.assert_called_once_with('users', [('q', '*****@*****.**')]) mock_update.assert_called_once_with('patches', 123, [ ('delegate', mock_index.return_value[0]['id'])]) mock_show.assert_called_once_with(mock_update.return_value, None)
def test_apply_with_args(self, mock_git_am, mock_download, mock_detail): """Validate passthrough of arbitrary arguments to git-am.""" rsp = {'mbox': 'hello, world'} mock_detail.return_value = rsp mock_download.return_value = object() runner = CLIRunner() result = runner.invoke(patch.apply_cmd, ['123', '-3']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('patches', 123) mock_download.assert_called_once_with(rsp['mbox'], {'series': '*'}) mock_git_am.assert_called_once_with(mock_download.return_value, ('-3',))
def test_download_diff(self, mock_log, mock_download, mock_detail): """Validate behavior if downloading a diff instead of mbox.""" rsp = {'mbox': 'hello, world', 'diff': 'test'} mock_detail.return_value = rsp runner = CLIRunner() result = runner.invoke(patch.download_cmd, ['123', '--diff']) assert result.exit_code == 0, result mock_detail.assert_called_once_with('patches', 123) mock_download.assert_called_once_with( rsp['mbox'].replace('mbox', 'raw'), output=None, ) assert mock_log.info.called
def test_update_api_v1_1( self, mock_log, mock_echo, mock_detail, mock_update, mock_version, ): mock_version.return_value = (1, 1) runner = CLIRunner() result = runner.invoke(bundle.update_cmd, ['1', '--name', 'hello']) assert result.exit_code == 1, result assert mock_log.error.called
def test_delete_api_v1_1( self, mock_log, mock_echo, mock_delete, mock_version, ): """Validate standard behavior.""" mock_version.return_value = (1, 1) runner = CLIRunner() result = runner.invoke(bundle.delete_cmd, ['hello']) assert result.exit_code == 1, result assert mock_log.error.called
def test_list_with_wildcard_filters(self, mock_log, mock_echo, mock_index, mock_version): """Validate behavior with a "wildcard" filter. Patchwork API v1.0 did not support multiple filters correctly. Ensure the user is warned as necessary if a filter has multiple matches. """ people_rsp = [self._get_people(), self._get_people()] series_rsp = [self._get_series()] mock_index.side_effect = [people_rsp, series_rsp] runner = CLIRunner() runner.invoke(series.list_cmd, ['--submitter', '*****@*****.**']) assert mock_log.warning.called
def test_apply_with_args(self, mock_git_am, mock_download, mock_get_bundle): """Validate passthrough of arbitrary arguments to git-am.""" rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'} mock_get_bundle.return_value = rsp mock_download.return_value = 'test.patch' runner = CLIRunner() result = runner.invoke(bundle.apply_cmd, ['123', '-3']) assert result.exit_code == 0, result mock_get_bundle.assert_called_once_with('123') mock_download.assert_called_once_with(rsp['mbox']) mock_git_am.assert_called_once_with(mock_download.return_value, ('-3', ))