From 08116661332d17ee8744026c6e17355384bd3670 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Sun, 25 Nov 2018 12:44:06 -0800 Subject: [PATCH] nucypher cli status automated test --- tests/cli/commands/test_status.py | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/cli/commands/test_status.py diff --git a/tests/cli/commands/test_status.py b/tests/cli/commands/test_status.py new file mode 100644 index 000000000..ea2610b95 --- /dev/null +++ b/tests/cli/commands/test_status.py @@ -0,0 +1,75 @@ +""" +This file is part of nucypher. + +nucypher is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +nucypher is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with nucypher. If not, see . +""" + +import os + +import pytest + +from nucypher.cli.main import nucypher_cli +from nucypher.config.characters import UrsulaConfiguration +from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD, MOCK_CUSTOM_INSTALLATION_PATH, \ + MOCK_IP_ADDRESS, MOCK_URSULA_STARTING_PORT + + +@pytest.fixture(scope='module') +def nominal_configuration_fields(): + config = UrsulaConfiguration(dev_mode=True) + config_fields = config.static_payload + del config_fields['is_me'] + yield tuple(config_fields.keys()) + del config + + +def test_initialize_configuration_files_and_directories(custom_filepath, click_runner): + init_args = ('ursula', 'init', '--config-root', custom_filepath, '--rest-port', MOCK_URSULA_STARTING_PORT) + + # Use a custom local filepath for configuration + user_input = '{password}\n{password}\n{ip}\n'.format(password=INSECURE_DEVELOPMENT_PASSWORD, ip=MOCK_IP_ADDRESS) + result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) + assert result.exit_code == 0 + + # CLI Output + assert MOCK_CUSTOM_INSTALLATION_PATH in result.output, "Configuration not in system temporary directory" + assert "nucypher ursula run" in result.output, 'Help message is missing suggested command' + + # Files and Directories + assert os.path.isdir(custom_filepath), 'Configuration file does not exist' + assert os.path.isdir(os.path.join(custom_filepath, 'keyring')), 'Keyring does not exist' + assert os.path.isdir(os.path.join(custom_filepath, 'known_nodes')), 'known_nodes directory does not exist' + + custom_config_filepath = os.path.join(custom_filepath, UrsulaConfiguration.CONFIG_FILENAME) + assert os.path.isfile(custom_config_filepath), 'Configuration file does not exist' + + # Auth + assert 'Enter keyring password:' in result.output, 'WARNING: User was not prompted for password' + assert 'Repeat for confirmation:' in result.output, 'User was not prompted to confirm password' + + +def test_empty_federated_status(click_runner, custom_filepath): + + custom_config_filepath = os.path.join(custom_filepath, UrsulaConfiguration.CONFIG_FILENAME) + assert os.path.isfile(custom_config_filepath), 'Configuration file does not exist' + + status_args = ('status', '--config-file', custom_config_filepath) + result = click_runner.invoke(nucypher_cli, status_args, catch_exceptions=False) + + assert result.exit_code == 0 + + assert 'Federated Only' in result.output + heading = 'Known Nodes (connected 0 / seen 0) Last Seen self | known | seednode |' + assert heading in result.output + assert 'password' not in result.output