def test_run_command(self): ch = CommandHandler(['flow']) # we need to monkey-patch stderr since it'll print out the generic help # to stderr if no command is given in argv when __init__() is called correct_stderr = sys.stderr sys.stderr = MockStdout() try: ch.run_command() mock_stderr = sys.stderr finally: sys.stderr = correct_stderr expected = "\nType 'flow help <subcommand>' for help on a specific subcommand.\n\nAvailable subcommands:\n app\n create\n push\n test\n" self.assertEqual(expected, mock_stderr.output) # Get help for a specific command ch = CommandHandler(['flow', 'help', 'create']) correct_stdout = sys.stdout sys.stdout = MockStdout() try: ch.run_command() mock_stdout = sys.stdout finally: sys.stdout = correct_stdout expected = "Usage: flow create [options] [projectname]\n\nCreates a Flow project directory for the given project name in the current directory.\n\nOptions:\n -h, --help show this help message and exit\n" self.assertEqual(expected, mock_stdout.output) # The --help and -h commands are handled corectly for command in ['-h', '--h', '-help', '--help', 'help']: ch = CommandHandler(['flow', command]) correct_stderr = sys.stderr sys.stderr = MockStdout() try: ch.run_command() mock_stderr = sys.stderr finally: sys.stderr = correct_stderr expected = "\nType 'flow help <subcommand>' for help on a specific subcommand.\n\nAvailable subcommands:\n app\n create\n push\n test\n" self.assertEqual(expected, mock_stderr.output) # Try to run the "create" command to make sure run_command passes # things along properly project_name = 'TEST' + str(uuid.uuid4()).replace('-', '_') try: ch = CommandHandler(['flow', 'create', project_name]) ch.run_command() # we should be able to see the newly created project directory in the # cwd and find the correct files in there self.assertTrue(os.path.exists(project_name)) self.assertTrue(os.path.isdir(project_name)) settings_path = os.path.join(project_name, 'settings.py') self.assertTrue(os.path.exists(settings_path)) self.assertTrue(os.path.isfile(settings_path)) finally: # tidy up path = os.path.abspath(project_name) shutil.rmtree(path)
def test_help(self): ch = CommandHandler(['flow']) expected = "\nType 'flow help <subcommand>' for help on a specific subcommand.\n\nAvailable subcommands:\n app\n create\n push\n test" actual = ch.help() self.assertEqual(expected, actual)
def test_fetch_command(self): ch = CommandHandler(['flow']) result = ch.fetch_command('create') self.assertTrue(isinstance(result, Command))