From 6e1a4cc65bf0dead0a0ef3e8b1a89fd11d8f0cf2 Mon Sep 17 00:00:00 2001 From: kschopmeyer Date: Tue, 25 Aug 2020 15:31:59 -0500 Subject: [PATCH] Fixes issue # 732 Refactor the code for connection show to simplify the code and remove some corner cases that were wrong. Adds tests for all branches in connection show. --- docs/changes.rst | 3 + docs/pywbemcli/cmdshelp.rst | 8 +- pywbemtools/pywbemcli/_cmd_connection.py | 121 +++++++++++---------- pywbemtools/pywbemcli/_context_obj.py | 2 +- tests/unit/pytest_extensions.py | 8 +- tests/unit/test_connection_cmds.py | 128 +++++++++++++++-------- tests/unit/test_general_options.py | 5 +- 7 files changed, 163 insertions(+), 112 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 3f76e52a8..7127f48dd 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -123,6 +123,9 @@ Released: not yet * Refactor statistics display to present information consistent with the display in pywbem. (see issue # 724) +* Refactor connections show command and clean up its documentation. (see + issue #732) + **Known issues:** * See `list of open issues`_. diff --git a/docs/pywbemcli/cmdshelp.rst b/docs/pywbemcli/cmdshelp.rst index 79acee11d..2e107dd22 100644 --- a/docs/pywbemcli/cmdshelp.rst +++ b/docs/pywbemcli/cmdshelp.rst @@ -826,12 +826,14 @@ Help text for ``pywbemcli connection show`` (see :ref:`connection show command`) Show the name and attributes of a WBEM connection definition or the current connection, as follows: - * If the NAME argument is specified, the connection definition with that name from the connections file is shown. + * If the NAME argument is specified, the connection information with that name from the connections file is + displayed or the current connection if it is the same name. * If the NAME argument is '?', the command presents a list of connection definitions from the connections file and - prompts the user for selecting one, which is then shown. + prompts the user for selecting one, which is then displayed if a connection file exists. - * If the NAME argument is omitted, the current connection is shown. + * If the NAME argument is omitted, the current connection information is displayed if there is a current + connection. Example showing a named connection definition: diff --git a/pywbemtools/pywbemcli/_cmd_connection.py b/pywbemtools/pywbemcli/_cmd_connection.py index 070e072a5..eda8bed21 100644 --- a/pywbemtools/pywbemcli/_cmd_connection.py +++ b/pywbemtools/pywbemcli/_cmd_connection.py @@ -112,14 +112,16 @@ def connection_show(context, name, **options): Show the name and attributes of a WBEM connection definition or the current connection, as follows: - * If the NAME argument is specified, the connection definition with that - name from the connections file is shown. + * If the NAME argument is specified, the connection information with that + name from the connections file is displayed or the current connection + if it is the same name. * If the NAME argument is '?', the command presents a list of connection definitions from the connections file and prompts the user for - selecting one, which is then shown. + selecting one, which is then displayed if a connection file exists. - * If the NAME argument is omitted, the current connection is shown. + * If the NAME argument is omitted, the current connection information + is displayed if there is a current connection. Example showing a named connection definition: @@ -399,34 +401,47 @@ def get_current_connection_name(context): return context.pywbem_server.name if context.pywbem_server else None -def raise_no_repository_file(connections): +def pick_connection(name, context, connections_repo): """ - Raise exception with message that connections file does not exist. - """ - raise click.ClickException( - 'Connections file "{0}" does not exist'. - format(connections.connections_file)) + If name is None use the interactive mode to select the connection from the + list of connections in the connections file. If the name is provided, it is + tested against the names in the connections file. If it is not provided, + + Parameters: + name (:term:`string): + Name that will be validated against repository or Noe if the name + is to be picked from a selection presented + + context (:class:`'~pywbemtools.pywbemcli._context_obj.ContextObj`): + The current ContextObj instance. + + connections_repo (:class:`'~pywbemtools._context_obj.ContextObj`): + + Returns: + name selected from connections or None if no name selected. + + Raises + + click.ClickException: No connection file exists or if there is a name, + parameter, that name does not exist in the connections file -def select_connection(name, context, connections): - """ - Use the interactive mode to select the connection from the list of - connections in the connections file. If the name is provided, it is tested - against the names in the connections file. If it is not provided, """ context.spinner_stop() - if not connections.file_exists(): - raise_no_repository_file(connections) + if not connections_repo.file_exists(): + raise click.ClickException( + 'Connections file "{0}" does not exist'. + format(connections_repo.connections_file)) if name: - if name in connections: + if name in connections_repo: return name raise click.ClickException( 'Connection definition "{0}" not found in connections file "{1}"'. - format(name, connections.connections_file)) + format(name, connections_repo.connections_file)) - conn_names = sorted(list(six.iterkeys(connections))) + conn_names = sorted(list(six.iterkeys(connections_repo))) return pick_one_from_list(context, conn_names, "Select a connection or Ctrl-C to abort.") @@ -538,46 +553,38 @@ def cmd_connection_show(context, name, options): connections_repo = context.connections_repo - curr_name = get_current_connection_name(context) - # If no name arg, fallback to selection unless there is no connections file + current_name = get_current_connection_name(context) + + # If no name arg, use the current connection if it exists if not name: - name = curr_name or '?' - if not curr_name and not connections_repo.file_exists(): - raise click.ClickException( - 'No current connection and no connections file {}.' - .format(connections_repo.connections_file)) + if not current_name: + raise click.ClickException('No current connection exists.') + name = current_name - # ? means to ask for connections file. However fallback to current - # if there is no connections file and fail if no current. + # ? means ask for connections file. However fallback to current connection + # if there is no connections file and fail if no current connection. if name == '?': - # No connections exit in connections file. - if not connections_repo.file_exists(): - if context.pywbem_server: - show_connection_information( - context, - context.pywbem_server, - show_state=True, - show_password=options['show_password']) - return - - name = select_connection(None, context, connections_repo) - - # Have a name. If there are connections and this name is in connections - # and that name is not current, use it. If current name is same as - # name, use the current version. + name = pick_connection(None, context, connections_repo) + + # Name is now defined + if name == current_name: + show_connection_information(context, + context.pywbem_server, + show_state=True, + show_password=options['show_password']) + return + + # Show a server definition from the connections file if connections_repo.file_exists(): - # If name in connections use it if name not in connections_repo: raise click.ClickException( 'Connection definition "{0}" not found in connections file ' '"{1}"'.format(name, connections_repo.connections_file)) connection = connections_repo[name] - else: # not connections file - if curr_name != name: - raise click.ClickException( - 'Name: "{}" not current and no connections file {}'.format( - name, connections_repo.connections_file)) - connection = context.pywbem_server + else: # no connections file + raise click.ClickException( + 'Name: "{}" not current and no connections file {}'.format( + name, connections_repo.connections_file)) show_connection_information(context, connection, @@ -656,7 +663,7 @@ def cmd_connection_select(context, name, options): """ connections_repo = context.connections_repo - name = select_connection(name, context, connections_repo) + name = pick_connection(name, context, connections_repo) new_ctx = ContextObj(connections_repo[name], context.output_format, @@ -692,18 +699,20 @@ def cmd_connection_delete(context, name): # Select the connection with prompt if name is None. # This also stops the spinner - name = select_connection(name, context, connections_repo) + name = pick_connection(name, context, connections_repo) - cname = get_current_connection_name(context) + current_name = get_current_connection_name(context) connections_repo.delete(name) - default = 'default ' if cname and cname == name else '' + default = 'default ' if current_name and current_name == name else '' click.echo('Deleted {} connection "{}".'.format(default, name)) def cmd_connection_save(context, name): """ - Saves the connection named name or the current connection of no name + Saves the current connection definition with the name provided. A current + connection must exist. + The save function allows overwriting existing names """ current_connection = context.pywbem_server diff --git a/pywbemtools/pywbemcli/_context_obj.py b/pywbemtools/pywbemcli/_context_obj.py index a59867c3d..b1d772af1 100644 --- a/pywbemtools/pywbemcli/_context_obj.py +++ b/pywbemtools/pywbemcli/_context_obj.py @@ -281,7 +281,7 @@ def execute_cmd(self, cmd): self.spinner_start() if self.pdb: import pdb # pylint: disable=import-outside-toplevel - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member try: cmd() finally: diff --git a/tests/unit/pytest_extensions.py b/tests/unit/pytest_extensions.py index 4115e771a..fc2db55fd 100644 --- a/tests/unit/pytest_extensions.py +++ b/tests/unit/pytest_extensions.py @@ -136,7 +136,7 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition): if exp_exc_types: with pytest.raises(exp_exc_types): if condition == 'pdb': - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member test_func(testcase, **kwargs) # expecting an exception @@ -146,7 +146,7 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition): # exception). else: if condition == 'pdb': - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member test_func(testcase, **kwargs) # not expecting an exception @@ -156,14 +156,14 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition): if exp_exc_types: with pytest.raises(exp_exc_types): if condition == 'pdb': - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member test_func(testcase, **kwargs) # expecting an exception ret = None # Debugging hint else: if condition == 'pdb': - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member test_func(testcase, **kwargs) # not expecting an exception diff --git a/tests/unit/test_connection_cmds.py b/tests/unit/test_connection_cmds.py index 6f8dd0e34..04c86e921 100644 --- a/tests/unit/test_connection_cmds.py +++ b/tests/unit/test_connection_cmds.py @@ -277,7 +277,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # Begin of sequence - repository is empty. - ['Verify connection command save creates file.', + ['Verify connection command save creates file. SEQ 0,1', {'general': ['--server', 'http://blah'], 'args': ['save', 'test1']}, {'stdout': "", @@ -285,7 +285,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'exists'}}, None, OK], - ['Verify connection command show of just created test1', + ['Verify connection command show of just created test1. SEQ 0,2', {'general': [], 'args': ['show', 'test1']}, {'stdout': """Connection status: @@ -309,7 +309,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command show of just created test1 as table', + ['Verify connection command show of just created test1 as table. SEQ 0,3', {'general': ['--output-format', 'plain'], 'args': ['show', 'test1']}, {'stdout': """Connection status: @@ -332,7 +332,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command save with complex general options short', + ['Verify connection command save with complex general options short. ' + 'SEQ 0,4', {'general': ['--server', 'http://blahblah', '-u', 'fred', '-p', 'argh', '-t', '18', '--no-verify', '-l', 'api=file,all'], 'args': ['save', 'test2']}, @@ -341,7 +342,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command show named connnection test1', + ['Verify connection command show named connnection test1.SEQ 0,5', {'general': [], 'args': ['show', 'test1']}, {'stdout': """Connection status: @@ -364,7 +365,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command show test2 with --show-password', + ['Verify connection command show test2 with --show-password. SEQ 0.6', {'general': [], 'args': ['show', 'test2', '--show-password']}, {'stdout': """Connection status: @@ -387,7 +388,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command show test2, masked password', + ['Verify connection command show test2, masked password. SEQ 0,7', {'general': [], 'args': ['show', 'test2']}, {'stdout': """Connection status: @@ -410,7 +411,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command show test2, masked password', + ['Verify connection command show test2, masked password. SEQ 0,7', {'general': [], 'args': ['show', 'BADSERVERNAME']}, {'stderr': ['Connection definition', @@ -420,7 +421,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command list with 2 servers defined', + ['Verify connection command list with 2 servers defined. SEQ 0,8', {'general': ['--output-format', 'plain'], 'args': ['list']}, {'stdout': ['WBEM server connections(brief): (#: default, *: current)', @@ -430,28 +431,28 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command select test2', + ['Verify connection command select test2.. SEQ 0,9', {'general': [], 'args': ['select', 'test2', '--default']}, {'stdout': ['test2', 'default'], 'test': 'innows'}, None, OK], - ['Verify connection command show test2 includes "current"', + ['Verify connection command show test2 includes "current". SEQ 0,10', {'general': [], 'args': ['show', 'test2']}, {'stdout': ['test2', 'http://blahblah', 'current'], 'test': 'innows'}, None, OK], - ['Verify connection command select test2 shows it is current', + ['Verify connection command select test2 shows it is current. SEQ 0,11', {'general': [], 'args': ['select', 'test2']}, {'stdout': ['test2', 'current'], 'test': 'innows'}, None, OK], - ['Verify connection command select test3 fails', + ['Verify connection command select test3 fails. . SEQ 0,12', {'general': [], 'args': ['select', 'test9']}, {'stderr': ['Connection definition', @@ -462,7 +463,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name None, OK], ['Verify connection command list with 2 servers defined, not sel after ' - 'next pywbemcli call', + 'next pywbemcli call. . SEQ 0,13', {'general': ['--output-format', 'plain'], 'args': ['list']}, {'stdout': ['WBEM server connections(brief): (#: default, *: current)', @@ -472,8 +473,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command list with 2 servers defined, not sel after ' - 'next pywbemcli call', + ['Verify connection command list with 2 servers defined, not selected ' + 'after next pywbemcli call. SEQ 0,14', {'general': ['--output-format', 'plain'], 'args': ['list']}, {'stdout': ['WBEM server connections(brief): (#: default, *: current)', @@ -484,7 +485,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name None, OK], ['Verify connection command list with 2 servers defined, not sel after ' - 'next pywbemcli call --full', + 'next pywbemcli call --full. SEQ 0,15', {'general': ['--output-format', 'plain'], 'args': ['list', '--full']}, {'stdout': ['WBEM server connections(full): (#: default, *: current)', @@ -496,7 +497,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name None, OK], ['Verify connection command list with 2 servers defined, not sel after ' - 'next pywbemcli call -f', + 'next pywbemcli call -f. SEQ 0,16', {'general': ['--output-format', 'plain'], 'args': ['list', '-f']}, {'stdout': ['WBEM server connections(full): (#: default, *: current)', @@ -507,7 +508,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command delete test1', + ['Verify connection command delete test1. SEQ 0,17', {'general': [], 'args': ['delete', 'test1']}, {'stdout': ['Deleted', 'test1'], @@ -515,6 +516,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], + # End of sequence - repository is empty. + ['Verify connection command test', {'general': [], 'args': ['test']}, @@ -563,7 +566,6 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, ONE_CLASS_MOCK_FILE, OK], - # TODO: Future; Add test for --pull-options where the mocker has # pull disabled. Note that this must be a completely new test, not # just the existing because there is no external way to turh off @@ -587,7 +589,16 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - # End of sequence - repository is empty. + ['Verify connection command save no current connection.', + {'general': [], + 'args': ['show']}, + {'stderr': [ + "No current connection exists"], + 'test': 'innows', + 'rc': 1, + 'file': {'before': 'none', 'after': 'none'}}, + None, OK], + # # Sequence that creates, shows and deletes a single server definition @@ -595,7 +606,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # Begin of sequence - repository is empty. - ['Verify connection command add with all arguments.', + ['Verify connection command add with all arguments. SEQ 1,1', {'general': ['--server', 'http://blahblah', '--default-namespace', 'root/blahblah', '--user', 'john', @@ -610,7 +621,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'exists'}}, None, OK], - ['Verify connection command show addallargs initial version', + ['Verify connection command show addallargs initial version. SEQ 1,2', {'general': [], 'args': ['show', 'addallargs']}, {'stdout': [ @@ -625,7 +636,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command with that overwrites existing name works.', + ['Verify connection command with that overwrites existing name works. ' + 'SEQ 1,3', {'general': ['--server', 'http://blah', '--default-namespace', 'root/blah', '--user', 'john', @@ -641,7 +653,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command show of name addallargs, overwrite changed', + ['Verify connection command show of name addallargs, overwrite changed. ' + 'SEQ 1,4', {'general': [], 'args': ['show', 'addallargs', '--show-password']}, {'stdout': [ @@ -656,7 +669,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command delete addallargs', + ['Verify connection command delete addallargs. SEQ 1,5', {'general': [], 'args': ['delete', 'addallargs']}, {'stdout': "Deleted", @@ -666,7 +679,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # uses regex because windows generates set and linux export in statements # No file verification required. Does not use file - ['Verify connection command export current connection', + ['Verify connection command export current connection. SEQ 1,6', {'args': ['export'], 'general': ['-s', 'http://blah', '-u', 'fred', '-p', 'arghh', '--no-verify', @@ -685,7 +698,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command export no current conection', + ['Verify connection command export no current conection. SEQ 1,7', {'general': [], 'args': ['export']}, {'stderr': ['No server currently defined as current'], @@ -703,7 +716,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # Begin of sequence - connections file does not exist. - ['Verify connection command show with name, non-existing conn file', + ['Verify connection command show with name, non-existing conn file. ' + 'SEQ 2,1', {'general': [], 'args': ['show', 'blah']}, {'stderr': ['Name', 'blah', 'not current and no connections file', @@ -713,16 +727,17 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command show with no name, non-existing conn file', + ['Verify connection command show with no name, non-existing conn file.' + 'SEQ 2.2', {'general': [], 'args': ['show']}, - {'stderr': ['No current connection and no connections file'], + {'stderr': ['No current connection exists'], 'rc': 1, 'test': 'innows', 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command select, non-existing conn file', + ['Verify connection command select, non-existing conn file. SEQ 2.3', {'general': [], 'args': ['select']}, {'stderr': ["Connections file", "does not exist"], @@ -731,7 +746,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command select blah, non-existing conn file', + ['Verify connection command select blah, non-existing conn file. SEQ 2.4', {'general': [], 'args': ['select', 'blah']}, {'stderr': ["Connections file", "does not exist"], @@ -740,7 +755,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command delete, non-existing conn file', + ['Verify connection command delete, non-existing conn file. SEQ 2.5', ['delete'], {'stderr': ["Connections file", "does not exist"], 'rc': 1, @@ -748,7 +763,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'none'}}, None, OK], - ['Verify connection command delete, non-existing conn file', + ['Verify connection command delete, non-existing conn file. SEQ 2.6', {'general': [], 'args': ['delete', 'blah']}, {'stderr': ["Connections file", "does not exist"], @@ -765,7 +780,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # Begin of sequence - repository is empty. - ['Verify mock connection exists.', + ['Verify mock connection exists. SEQ 3,1', {'general': ['--mock-server', MOCK_FILE_PATH], 'args': ['save', 'mocktest']}, {'stdout': "", @@ -773,7 +788,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'exists'}}, None, OK], - ['Verify connection command shows mock file ', + ['Verify connection command shows mock file. SEQ 3,2', {'general': [], 'args': ['show', 'mocktest']}, {'stdout': [ @@ -789,7 +804,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'test': 'innows'}, None, OK], - ['Verify connection command test against existing mock def', + ['Verify connection command test against existing mock def. SEQ 3,3', {'args': ['test'], 'general': ['--name', 'mocktest']}, {'stdout': "Connection OK: FakedUrl", @@ -799,7 +814,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # The following 3 tests use a file defined to pywbemcli through an # environment variable to mock the select prompt. - ['Verify connection command select mocktest with prompt', + ['Verify connection command select mocktest with prompt. SEQ 3,4', {'general': [], 'args': ['select'], 'env': {MOCK_DEFINITION_ENVVAR: GET_TEST_PATH_STR(MOCK_PROMPT_0_FILE)}}, @@ -808,7 +823,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command show with prompt', + ['Verify connection command show with prompt. SEQ 3,5', {'general': [], 'args': ['show', '?'], 'env': {MOCK_DEFINITION_ENVVAR: GET_TEST_PATH_STR(MOCK_PROMPT_0_FILE)}}, @@ -817,7 +832,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'exists'}}, None, OK], - ['Verify connection command delete last one that deletes w/o prompt', + ['Verify connection command delete last one that deletes w/o prompt. ' + 'SEQ 3,6', {'general': [], 'args': ['delete'], 'env': {MOCK_DEFINITION_ENVVAR: GET_TEST_PATH_STR(MOCK_PROMPT_0_FILE)}}, @@ -826,7 +842,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'exists', 'after': 'none'}}, None, OK], - ['Verify Add mock server to empty connections file.', + ['Verify Add mock server to empty connections file. SEQ 3,7', {'general': ['--mock-server', MOCK_FILE_PATH], 'args': ['save', 'mocktest']}, {'stdout': "", @@ -834,7 +850,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name 'file': {'before': 'none', 'after': 'exists'}}, None, OK], - ['Verify connection command delete, empty repository', + ['Verify connection command delete, empty repository. SEQ 3,8', {'general': [], 'args': ['delete', 'mocktest']}, {'stdout': ['Deleted connection "mocktest"'], @@ -933,11 +949,31 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name # End of sequence - repository is empty. # - # Sequence that tests select variations + # Sequence that tests select/show variations # # Begin of sequence - repository is empty. + ['Verify connection show with no server definitions file fails', + {'general': [], + 'args': ['show']}, + {'stderr': "No current connection exists.", + 'rc': 1, + 'test': 'innows', + 'file': {'before': 'none', 'after': 'none'}}, + None, OK], + + ['Verify connection show ? with no server definitions file fails', + {'general': ['--server', 'http://blah'], + 'args': ['show', "?"]}, + {'stderr': ["Connections file ", ".pywbemcli_connections.yaml", + "does not exist"], + 'rc': 1, + 'test': 'innows', + 'file': {'before': 'none', 'after': 'none'}}, + None, RUN], + + ['Verify connection show with just current server defined by --server', {'args': ['show'], 'general': ['--server', 'http://blah']}, @@ -1221,7 +1257,7 @@ def test_file_existence(file_test): if condition == 'pdb': import pdb # pylint: disable=import-outside-toplevel - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member if 'file' in exp_response: if 'before' in exp_response['file']: @@ -1436,7 +1472,7 @@ def test_file_existence(file_test): if condition == 'pdb': import pdb # pylint: disable=import-outside-toplevel - pdb.set_trace() + pdb.set_trace() # pylint: disable=no-member if 'file' in exp_response: if 'before' in exp_response['file']: diff --git a/tests/unit/test_general_options.py b/tests/unit/test_general_options.py index d16782690..4b9bde65a 100644 --- a/tests/unit/test_general_options.py +++ b/tests/unit/test_general_options.py @@ -737,7 +737,7 @@ class Command group for CIM classes. 'env': {MOCK_DEFINITION_ENVVAR: GET_TEST_PATH_STR(MOCK_PW_PROMPT_FILE)}}, {'stdout': ['CIM_Foo'], 'test': 'innows'}, - None, RUN], + None, OK], ['Delete our test server. Sequence 0,4. Last', {'general': ['--name', 'mocktestVerifyPWPrompt'], @@ -953,7 +953,8 @@ class Command group for CIM classes. 'connection show'], 'cmdgrp': None, }, - {'stderr': ['Conflicting server definitions:', + {'stdout': ["name not-saved (current)"], + 'stderr': ['Conflicting server definitions:', 'http://blah', 'mock-server: tests/unit/simple_mock_model.mof'], 'rc': 0,