def test_generate_commands_section_human_readable(): yml_data = { 'script': { 'commands': [{ 'deprecated': True, 'name': 'deprecated-cmd' }, { 'deprecated': False, 'name': 'non-deprecated-cmd' }] } } example_dict = { 'non-deprecated-cmd': [ '!non-deprecated-cmd', '## this is human readable\nThis is a line\nAnother line', '{}' ] } section, errors = generate_commands_section(yml_data, example_dict, command_permissions_dict={}) hr_section: str = section[section.index('#### Human Readable Output') + 1] # get lines except first one which is a \n lines = hr_section.splitlines()[1:] for line in lines: assert line.startswith('>') assert lines[0] == '>## this is human readable' assert lines[1] == '>This is a line'
def test_generate_commands_with_permissions_section(): yml_data = { 'script': { 'commands': [{ 'deprecated': True, 'name': 'deprecated-cmd' }, { 'deprecated': False, 'name': 'non-deprecated-cmd' }] } } section, errors = generate_commands_section( yml_data, example_dict={}, command_permissions_dict={'non-deprecated-cmd': 'SUPERUSER'}) expected_section = [ '## Commands', 'You can execute these commands from the Demisto CLI, as part of an automation, or in a playbook.', 'After you successfully execute a command, a DBot message appears in the War Room with the command details.', '### non-deprecated-cmd', '***', ' ', '#### Required Permissions', 'SUPERUSER', '#### Base Command', '', '`non-deprecated-cmd`', '#### Input', '', 'There are no input arguments for this command.', '', '#### Context Output', '', 'There is no context output for this command.', '', '#### Command Example', '``` ```', '', '#### Human Readable Output', '\n', '' ] assert '\n'.join(section) == '\n'.join(expected_section)
def test_generate_commands_with_permissions_section_command_doesnt_exist(): """ Given - Integration commands from yml file with command permission flag on. - The commands from yml file do not exist in the given command permissions dict. When - Running the generate_table_section command. Then - Validate that in the #### Required Permissions section empty string is returned - Validate that an error is returned in error list which indicated that for this command no permission were found. """ yml_data = { 'script': { 'commands': [ {'deprecated': True, 'name': 'deprecated-cmd'}, {'deprecated': False, 'name': 'non-deprecated-cmd'}]}} section, errors = generate_commands_section(yml_data, example_dict={}, command_permissions_dict={ '!non-deprecated-cmd': 'SUPERUSER'}) expected_section = [ '## Commands', 'You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook.', 'After you successfully execute a command, a DBot message appears in the War Room with the command details.', '### non-deprecated-cmd', '***', ' ', '#### Required Permissions', '', '#### Base Command', '', '`non-deprecated-cmd`', '#### Input', '', 'There are no input arguments for this command.', '', '#### Context Output', '', 'There is no context output for this command.', '', '#### Command Example', '``` ```', '', '#### Human Readable Output', '\n', ''] assert 'Error! Command Permissions were not found for command non-deprecated-cmd' in errors assert '\n'.join(section) == '\n'.join(expected_section)