diff --git a/shipyard_client/cli/cli_format_common.py b/shipyard_client/cli/cli_format_common.py index ce88b10f..f79cd19f 100644 --- a/shipyard_client/cli/cli_format_common.py +++ b/shipyard_client/cli/cli_format_common.py @@ -124,7 +124,8 @@ def gen_action_table(action_list): actions = format_utils.table_factory( field_names=['Name', 'Action', 'Lifecycle']) if action_list: - for action in action_list: + # sort by id, which is ULID - chronological. + for action in sorted(action_list, key=lambda k: k['id']): actions.add_row([ action.get('name'), 'action/{}'.format(action.get('id')), action.get('action_lifecycle') diff --git a/shipyard_client/cli/create/commands.py b/shipyard_client/cli/create/commands.py index d468458e..ee1531b4 100644 --- a/shipyard_client/cli/create/commands.py +++ b/shipyard_client/cli/create/commands.py @@ -139,8 +139,9 @@ def create_configdocs(ctx, collection, filename, directory, append, [os.path.join(dir, each) for each in os.listdir(dir) if each.endswith('.yaml')]) - if filename is None: - ctx.fail('The directory does not contain any YAML files.' + if not filename: + # None or empty list should raise this error + ctx.fail('The directory does not contain any YAML files. ' 'Please enter one or more YAML files or a ' 'directory that contains one or more YAML files.') diff --git a/shipyard_client/tests/unit/cli/create/no_yaml_dir/placeholder.txt b/shipyard_client/tests/unit/cli/create/no_yaml_dir/placeholder.txt new file mode 100644 index 00000000..6134979a --- /dev/null +++ b/shipyard_client/tests/unit/cli/create/no_yaml_dir/placeholder.txt @@ -0,0 +1 @@ +This is not a .yaml file. diff --git a/shipyard_client/tests/unit/cli/create/test_create_commands.py b/shipyard_client/tests/unit/cli/create/test_create_commands.py index 774bd97c..c6fd8636 100644 --- a/shipyard_client/tests/unit/cli/create/test_create_commands.py +++ b/shipyard_client/tests/unit/cli/create/test_create_commands.py @@ -84,6 +84,22 @@ def test_create_configdocs_directory(): mock_method.assert_called_once_with(ANY, collection, 'append', ANY, ANY) +def test_create_configdocs_directory_empty(): + """test create configdocs with empty directory""" + + collection = 'design' + dir1 = 'shipyard_client/tests/unit/cli/create/no_yaml_dir/' + runner = CliRunner() + + with patch.object(CreateConfigdocs, 'invoke_and_return_resp') as _method: + result = runner.invoke(shipyard, [ + auth_vars, 'create', 'configdocs', collection, + '--directory=' + dir1 + ]) + _method.assert_not_called() + assert b'directory does not contain any YAML files' in result.output_bytes + + def test_create_configdocs_multi_directory(): """test create configdocs with multiple directories"""