# coding: utf-8
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.

import io
import unittest
from click.testing import CliRunner
from . import util
import oraclebmc_cli

help_template = u"""
++++++++++++++++++++++++++++++++++++++++++++++
$ bmcs {cmd}
{output}
""".lstrip()


class TestHelp(unittest.TestCase):

    def setUp(self):
        self.runner = CliRunner()
        self.output_file = 'tests/output/inline_help_dump.txt'

    def test_help_on_all_commands(self):
        # Get a list of commands, where each command is a list of strings corresponding to the
        # command structure. Example: ['bucket', 'list']
        commands = sorted(util.collect_commands(oraclebmc_cli.cli))

        with io.open(self.output_file, mode='w+') as f:
            f.write(
                u'This file is generated by running test_help.py, and shows the output of --help for every possible command.\n\n')

            for command in commands:
                # Test the command with both -? and --help.
                help_command = command + ['-?']
                result = self.invoke_example_operation(help_command)
                self.validate_response(result)

                help_command = command + ['--help']
                result = self.invoke_example_operation(help_command)
                self.validate_response(result)

                f.write(help_template.format(
                    cmd=" ".join(help_command),
                    output=result.output
                ))

    def invoke_example_operation(self, command_list):
        return self.runner.invoke(oraclebmc_cli.cli, command_list)

    def validate_response(self, result):
        self.assertEqual(0, result.exit_code)

        # Ensure that compartment-id shortcut is set.
        if "--compartment-id TEXT" in result.output:
            assert ("-c, --compartment-id" in result.output)


if __name__ == '__main__':
    unittest.main()

# coding: utf-8
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.

import io
import unittest
from click.testing import CliRunner
from . import util
import oraclebmc_cli

help_template = u"""
++++++++++++++++++++++++++++++++++++++++++++++
$ bmcs {cmd}
{output}
""".lstrip()


class TestHelp(unittest.TestCase):

    def setUp(self):
        self.runner = CliRunner()
        self.output_file = 'tests/output/inline_help_dump.txt'

    def test_help_on_all_commands(self):
        # Get a list of commands, where each command is a list of strings corresponding to the
        # command structure. Example: ['bucket', 'list']
        commands = sorted(util.collect_commands(oraclebmc_cli.cli))

        with io.open(self.output_file, mode='w+') as f:
            f.write(
                u'This file is generated by running test_help.py, and shows the output of --help for every possible command.\n\n')

            for command in commands:
                # Test the command with both -? and --help.
                help_command = command + ['-?']
                result = self.invoke_example_operation(help_command)
                self.validate_response(result)

                help_command = command + ['--help']
                result = self.invoke_example_operation(help_command)
                self.validate_response(result)

                f.write(help_template.format(
                    cmd=" ".join(help_command),
                    output=result.output
                ))

    def invoke_example_operation(self, command_list):
        return self.runner.invoke(oraclebmc_cli.cli, command_list)

    def validate_response(self, result):
        self.assertEqual(0, result.exit_code)

        # Ensure that compartment-id shortcut is set.
        if "--compartment-id TEXT" in result.output:
            assert ("-c, --compartment-id" in result.output)


if __name__ == '__main__':
    unittest.main()

# coding: utf-8 # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. ++++++++++++++++++++++++++++++++++++++++++++++ $ bmcs {cmd} {output} # Get a list of commands, where each command is a list of strings corresponding to the # command structure. Example: ['bucket', 'list'] # Test the command with both -? and --help. # Ensure that compartment-id shortcut is set.