Changeset - 95e112372df9
[Not reviewed]
0 3 1
Branko Majic (branko) - 6 years ago 2018-02-28 15:13:40
branko@majic.rs
GC-3: Added dummy command for CA initialisation:

- Fixed test for the help command (help output now includes multiple
comands).
- Added dummy/skeleton implementation for init command parser.
4 files changed with 80 insertions and 1 deletions:
0 comments (0 inline, 0 general)
functional_tests/test_help.py
Show inline comments
 
@@ -69,7 +69,7 @@ def test_extended_help_shown():
 
    assert "Examples:" in stdout_h_flag
 
    assert "optional arguments" in stdout_h_flag
 
    # Subcommands listed.
 
    assert "{help}" in stdout_h_flag
 
    assert "help" in stdout_h_flag
 
    # @TODO: Can't really test this without producing errors, but
 
    # possibly not needed.
 
    # assert "positional arguments" in stdout_h_flag
functional_tests/test_init.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
#
 
# Copyright (C) 2018 Branko Majic
 
#
 
# This file is part of Gimmecert.
 
#
 
# Gimmecert 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.
 
#
 
# Gimmecert 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
 
# Gimmecert.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 

	
 
from .base import run_command
 

	
 

	
 
def test_init_command_available_with_help():
 
    # John has decided it is time to try out the tool. He starts off
 
    # by running the short usage help.
 
    stdout, stderr, returncode = run_command("gimmecert", "-h")
 

	
 
    # Looking at output, John notices the init command.
 
    assert returncode == 0
 
    assert stderr == ""
 
    assert 'init' in stdout
 

	
 
    # John decides to look at a more detailed description of this
 
    # command before proceeding.
 
    stdout, stderr, returncode = run_command("gimmecert", "init", "-h")
 

	
 
    # John notices that this command has some useful usage
 
    # instructions, which allows him to study the available arguments.
 
    assert returncode == 0
 
    assert stderr == ""
 
    assert stdout.startswith("usage: gimmecert init")
gimmecert/cli.py
Show inline comments
 
@@ -32,6 +32,18 @@ Examples:
 
"""
 

	
 

	
 
@subcommand_parser
 
def setup_init_subcommand_parser(parser, subparsers):
 
    subparser = subparsers.add_parser('init', description='Initialise CA hierarchy.')
 

	
 
    def init(args):
 
        pass
 

	
 
    subparser.set_defaults(func=init)
 

	
 
    return subparser
 

	
 

	
 
@subcommand_parser
 
def setup_help_subcommand_parser(parser, subparsers):
 
    subparser = subparsers.add_parser('help', description='shows help')
tests/test_cli.py
Show inline comments
 
@@ -134,3 +134,27 @@ def test_help_subcommand_sets_function_callback():
 
    subparser = gimmecert.cli.setup_help_subcommand_parser(parser, subparsers)
 

	
 
    assert callable(subparser.get_default('func'))
 

	
 

	
 
def test_setup_init_subcommand_parser_registered():
 
    registered_functions = gimmecert.decorators.get_subcommand_parser_setup_functions()
 

	
 
    assert gimmecert.cli.setup_init_subcommand_parser in registered_functions
 

	
 

	
 
def test_setup_init_subcommand_returns_parser():
 
    parser = argparse.ArgumentParser()
 
    subparsers = parser.add_subparsers()
 

	
 
    subparser = gimmecert.cli.setup_init_subcommand_parser(parser, subparsers)
 

	
 
    assert isinstance(subparser, argparse.ArgumentParser)
 

	
 

	
 
def test_setup_init_subcommand_sets_function_callback():
 
    parser = argparse.ArgumentParser()
 
    subparsers = parser.add_subparsers()
 

	
 
    subparser = gimmecert.cli.setup_init_subcommand_parser(parser, subparsers)
 

	
 
    assert callable(subparser.get_default('func'))
0 comments (0 inline, 0 general)