Changeset - 87692ece8441
[Not reviewed]
0 3 1
Branko Majic (branko) - 6 years ago 2018-03-31 23:55:31
branko@majic.rs
GC-20: Added initial dummy implementation of status command:

- Added functional test checking if the command is available and has
help.
- Updated unit tests for new CLI command.
- The command does not do anything at the moment.
4 files changed with 75 insertions and 2 deletions:
0 comments (0 inline, 0 general)
functional_tests/test_status.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_status_command_available_with_help():
 
    # John has used Gimmecert for issuing server and client
 
    # certificates in one of his projects. Since the project has been
 
    # quite hectic, he has started to loose track of all the different
 
    # server and client certificates he has issued. He realises that
 
    # he needs to check what has been issued. Although this should be
 
    # possible by simply listing the directory content, John hopes
 
    # that there might be a convenience command for this instead that
 
    # provides some extra info as well. He starts off by running the
 
    # command without any paramrters to get a listing of available
 
    # commands.
 
    stdout, stderr, exit_code = run_command("gimmecert")
 

	
 
    # Looking at output, John notices the status command.
 
    assert exit_code == 0
 
    assert stderr == ""
 
    assert "status" in stdout
 

	
 
    # He goes ahead and has a look at command invocation to check what
 
    # kind of parameters he might need to provide.
 
    stdout, stderr, exit_code = run_command("gimmecert", "status", "-h")
 

	
 
    # John can see that the command does not take any additional
 
    # arguments.
 
    assert exit_code == 0
 
    assert stderr == ""
 
    assert stdout.split('\n')[0] == "usage: gimmecert status [-h]"
gimmecert/cli.py
Show inline comments
 
@@ -24,7 +24,7 @@ import os
 
import sys
 

	
 
from .decorators import subcommand_parser, get_subcommand_parser_setup_functions
 
from .commands import client, help_, init, renew, server, usage, ExitCode
 
from .commands import client, help_, init, renew, server, status, usage, ExitCode
 

	
 

	
 
ERROR_GENERIC = 10
 
@@ -148,6 +148,21 @@ def setup_renew_subcommand_parser(parser, subparsers):
 
    return subparser
 

	
 

	
 
@subcommand_parser
 
def setup_status_subcommand_parser(parser, subparsers):
 

	
 
    subparser = subparsers.add_parser(name="status", description="Shows status information about issued certificates.")
 

	
 
    def status_wrapper(args):
 
        status()
 

	
 
        return ExitCode.SUCCESS
 

	
 
    subparser.set_defaults(func=status_wrapper)
 

	
 
    return subparser
 

	
 

	
 
def get_parser():
 
    """
 
    Sets-up and returns a CLI argument parser.
gimmecert/commands.py
Show inline comments
 
@@ -321,3 +321,7 @@ def renew(stdout, stderr, project_directory, entity_type, entity_name, generate_
 
          file=stdout)
 

	
 
    return ExitCode.SUCCESS
 

	
 

	
 
def status():
 
    pass
tests/test_cli.py
Show inline comments
 
@@ -185,6 +185,7 @@ def test_setup_subcommand_parser_sets_function_callback(setup_subcommand_parser)
 
        gimmecert.cli.setup_server_subcommand_parser,
 
        gimmecert.cli.setup_client_subcommand_parser,
 
        gimmecert.cli.setup_renew_subcommand_parser,
 
        gimmecert.cli.setup_status_subcommand_parser
 
    ]
 
)
 
def test_setup_subcommand_parser_registered(setup_subcommand_parser):
 
@@ -250,6 +251,8 @@ VALID_CLI_INVOCATIONS = [
 
    ("gimmecert.cli.renew", ["gimmecert", "renew", "-p", "server", "myserver"]),
 
    ("gimmecert.cli.renew", ["gimmecert", "renew", "-p", "client", "myclient"]),
 

	
 
    # status, no options
 
    ("gimmecert.cli.status", ["gimmecert", "status"]),
 
]
 

	
 

	
 
@@ -280,7 +283,7 @@ def test_parser_commands_and_options_are_available(tmpdir, command_function, cli
 
        gimmecert.cli.main()  # Should not raise
 

	
 

	
 
@pytest.mark.parametrize("command", ["help", "init", "server", "client", "renew"])
 
@pytest.mark.parametrize("command", ["help", "init", "server", "client", "renew", "status"])
 
@pytest.mark.parametrize("help_option", ["--help", "-h"])
 
def test_command_exists_and_accepts_help_flag(tmpdir, command, help_option):
 
    """
0 comments (0 inline, 0 general)