diff --git a/functional_tests/test_help.py b/functional_tests/test_help.py new file mode 100644 index 0000000000000000000000000000000000000000..af3874499df618bb89a14f909d77f4edff9b779a --- /dev/null +++ b/functional_tests/test_help.py @@ -0,0 +1,45 @@ +# -*- 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 . +# + + +import subprocess + + +def test_cli_works(): + # John is a system integrator that in his line of work often needs + # to issue certificates for testing. Just recently, he has heard + # of a new tool called gimmecert that can be used for issuing + # certificates in test environments that would make his life + # easier. + + # John goes ahead and installs the tool on his local machine. + + # Before moving on, John decides to quickly test if the package + # has been installed correctly. Assuming that the command is the + # same as package name, he runs it. + process = subprocess.Popen(["gimmecert"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + stdout, stderr = stdout.decode(), stderr.decode() + + # John has a look at output, and notices that no error has been + # reported. He also verifies the return code is non-zero, just to + # be on the safe side. + assert stderr == '' + assert process.returncode == 0 diff --git a/gimmecert/cli.py b/gimmecert/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..bdd737297c6cbc4119e3c7e3addfbcb11b3752c0 --- /dev/null +++ b/gimmecert/cli.py @@ -0,0 +1,45 @@ +# -*- 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 . +# + + +import argparse + + +def get_parser(): + """ + Sets-up and returns a CLI argument parser. + + :returns: argparse.ArgumentParser -- argument parser for CLI. + """ + + parser = argparse.ArgumentParser() + + return parser + + +def main(): + """ + This function is a CLI entry point for the tool. It is a thin + wrapper around the argument parser, and underlying command + implementation. + """ + + parser = get_parser() + parser.parse_args() diff --git a/setup.py b/setup.py index 8225ba9e450d3cafccf86dd46f0ac5c70c75b2f9..e4ba8bf86b5afa0dcbb7223b7696f6067daa4c62 100755 --- a/setup.py +++ b/setup.py @@ -73,6 +73,9 @@ setup( setup_requires=setup_requirements, tests_require=test_requirements, extras_require=extras_requirements, + entry_points = { + 'console_scripts': ['gimmecert=gimmecert.cli:main'], + }, classifiers=[ 'Development Status :: 1 - Planning', 'Environment :: Console', diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000000000000000000000000000000000000..217da74dd472459376a93afa866ac21e5d398bfa --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,50 @@ +# -*- 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 . +# + + +import argparse + +import gimmecert.cli + +from unittest import mock + + +def test_get_parser_returns_parser(): + parser = gimmecert.cli.get_parser() + + assert isinstance(parser, argparse.ArgumentParser) + + +@mock.patch('gimmecert.cli.get_parser') +def test_main_invokes_get_parser(mock_get_parser): + + gimmecert.cli.main() + + mock_get_parser.assert_called_once_with() + + +@mock.patch('gimmecert.cli.get_parser') +def test_main_invokes_argument_parsing(mock_get_parser): + mock_parser = mock.Mock() + mock_get_parser.return_value = mock_parser + + gimmecert.cli.main() + + mock_parser.parse_args.assert_called_once_with()