def test_check_info(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['check-info', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1)
def test_check_list(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['check-list']) mock_action.assert_called_once_with(mock_server.return_value)
def test_states(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['states']) mock_action.assert_called_once_with(mock_server.return_value)
def test_get__numeric_id(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() mock_action.return_value = None shell.main(['get', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1)
def test_help(capsys): with pytest.raises(SystemExit): shell.main(['-h']) captured = capsys.readouterr() assert 'usage: pwclient [-h]' in captured.out assert captured.err == ''
def test_git_am__threeway_option(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() mock_action.return_value = 0 shell.main(['git-am', '1', '-3']) mock_action.assert_called_once_with(mock_server.return_value, 1, ['git', 'am', '-3'])
def test_git_am__threeway_project_conf(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig({DEFAULT_PROJECT: { '3way': True, }}) mock_action.return_value = 0 shell.main(['git-am', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1, ['git', 'am', '-3'])
def test_git_am__threeway_global_conf(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig({'options': { '3way': True, }}) mock_action.return_value = 0 shell.main(['git-am', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1, ['git', 'am', '-3'])
def test_get__hash_ids(mock_action, mock_hash, mock_server, mock_config): mock_config.return_value = FakeConfig() mock_action.return_value = 0 mock_hash.return_value = 1 shell.main(['get', '-h', '698fa7f']) mock_action.assert_called_once_with(mock_server.return_value, 1) mock_hash.assert_called_once_with(mock_server.return_value, 'defaultproject', '698fa7f')
def test_missing_project(mock_config, capsys): mock_config.return_value = FakeConfig() with pytest.raises(SystemExit): shell.main(['get', '1', '-p', 'foo']) captured = capsys.readouterr() assert 'No section for project foo' in captured.err assert captured.out == ''
def test_git_am__signoff_global_conf(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig({'options': { 'signoff': True, }}) mock_action.return_value = 0 shell.main(['git-am', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1, ['git', 'am', '-s']) mock_action.reset_mock()
def test_list__no_options(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['list']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('project', mock.ANY), ]
def test_get__multiple_ids(mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig() mock_action.return_value = None shell.main(['get', '1', '2', '3']) mock_action.assert_has_calls([ mock.call(mock_server.return_value, 1), mock.call(mock_server.return_value, 2), mock.call(mock_server.return_value, 3), ])
def test_server_error(mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() mock_server.side_effect = IOError('foo') with pytest.raises(SystemExit): shell.main(['get', '1']) captured = capsys.readouterr() assert 'Unable to connect' in captured.err assert captured.out == ''
def test_view(mock_server, mock_config, mock_view, capsys): fake_config = FakeConfig() mock_config.return_value = fake_config mock_server.return_value.patch_get_mbox.return_value = 'foo' # test firstly with a single patch ID shell.main(['view', '1']) mock_view.assert_called_once_with(mock_server.return_value, [1])
def test_no_project_url(mock_config, capsys): fake_config = FakeConfig() del fake_config._data[DEFAULT_PROJECT]['url'] mock_config.return_value = fake_config with pytest.raises(SystemExit): shell.main(['get', '1']) captured = capsys.readouterr() assert 'No URL for project %s' % DEFAULT_PROJECT in captured.err assert captured.out == ''
def test_update__no_auth(mock_transport, mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() with pytest.raises(SystemExit): shell.main(['update', '1', '-a', 'yes']) captured = capsys.readouterr() mock_action.assert_not_called() mock_transport.return_value.set_credentials.assert_not_called() assert 'The update action requires authentication,' in captured.err
def test_no_project(mock_config, capsys): fake_config = FakeConfig() del fake_config._data['options']['default'] mock_config.return_value = fake_config with pytest.raises(SystemExit): shell.main(['get', '1']) captured = capsys.readouterr() assert 'No default project configured' in captured.err assert captured.out == ''
def test_list__name_filter(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['list', 'fake patch name']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('project', mock.ANY), mock.call('name__icontains', 'fake patch name'), ]
def test_list__limit_reverse_filter(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['list', '-N', '5']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('max_count', -5), mock.call('project', mock.ANY), ]
def test_list__archived_filter(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['list', '-a', 'yes']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('project', mock.ANY), mock.call('archived', True), ]
def test_list__state_filter(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig() shell.main(['list', '-s', 'Accepted']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('project', mock.ANY), mock.call('state', 'Accepted'), ]
def test_get__no_ids(mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() mock_action.return_value = None with pytest.raises(SystemExit): shell.main(['get']) captured = capsys.readouterr() if sys.version_info >= (3, 5): assert 'the following arguments are required: PATCH_ID' in captured.err else: assert 'pwclient get: error: too few arguments' in captured.err assert captured.out == ''
def test_git_am__failure(mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() mock_action.return_value = 1 with pytest.raises(SystemExit): shell.main(['git-am', '1']) mock_action.assert_called_once_with(mock_server.return_value, 1, ['git', 'am']) mock_action.reset_mock() captured = capsys.readouterr() assert "'git am' failed with exit status 1\n" in captured.err assert captured.out == ''
def test_apply__failed(mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() mock_action.side_effect = [0, 0, 1] with pytest.raises(SystemExit): shell.main(['apply', '1', '2', '3']) captured = capsys.readouterr() mock_action.assert_has_calls([ mock.call(mock_server.return_value, 1), mock.call(mock_server.return_value, 2), mock.call(mock_server.return_value, 3), ]) assert captured.err == 'Apply failed with exit status 1\n', captured
def test_check_create__no_auth(mock_transport, mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig() with pytest.raises(SystemExit): shell.main([ 'check-create', '-c', 'testing', '-s', 'pending', '-u', 'https://example.com/', '-d', 'hello, world', '1' ]) captured = capsys.readouterr() mock_action.assert_not_called() mock_transport.return_value.set_credentials.assert_not_called() assert 'The check_create action requires authentication,' in captured.err
def test_list__project_filter(mock_action, mock_filter, mock_server, mock_config): mock_config.return_value = FakeConfig( {'fakeproject': { 'url': 'https://example.com/fakeproject', }}) shell.main(['list', '-p', 'fakeproject']) mock_action.assert_called_once_with(mock_server.return_value, mock_filter.return_value, None, None, None) assert mock_filter.return_value.add.mock_calls == [ mock.call('project', 'fakeproject'), ]
def test_update__no_options(mock_transport, mock_action, mock_server, mock_config, capsys): mock_config.return_value = FakeConfig({ DEFAULT_PROJECT: { 'username': '******', 'password': '******', }, }) with pytest.raises(SystemExit): shell.main(['update', '1']) captured = capsys.readouterr() assert 'Must specify one or more update options (-a or -s)' in captured.err assert captured.out == ''
def test_update__commitref_option(mock_transport, mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig({ DEFAULT_PROJECT: { 'username': '******', 'password': '******', }, }) shell.main(['update', '1', '-s', 'Accepted', '-c', '698fa7f']) mock_action.assert_called_once_with(mock_server.return_value, 1, state='Accepted', archived=None, commit='698fa7f') mock_transport.return_value.set_credentials.assert_called_once_with( 'user', 'pass')
def test_update__archive_option(mock_transport, mock_action, mock_server, mock_config): mock_config.return_value = FakeConfig({ DEFAULT_PROJECT: { 'username': '******', 'password': '******', }, }) shell.main(['update', '1', '-a', 'yes']) mock_action.assert_called_once_with(mock_server.return_value, 1, state=None, archived='yes', commit=None) mock_transport.return_value.set_credentials.assert_called_once_with( 'user', 'pass')