def test_add_command_to_implementing_integrations_mapping(repo): """ Given - an id_set file includes integrations and playbooks When - modify_id_set_command_to_integration_of_playbook is called Then - Validates that each command_to_integration in playbook is a dictionary between command name and list of all integration that implement this command. """ pack = repo.create_pack("Pack1") integration_list = [integration1, integration2] playbook_list = [playbook1, playbook2] id_set_creator = IDSetCreator(pack.path, print_logs=False) id_set_creator.id_set["integrations"] = integration_list id_set_creator.id_set["playbooks"] = playbook_list id_set_creator.add_command_to_implementing_integrations_mapping() playbook_set = id_set_creator.id_set["playbooks"] assert playbook_set[0]["Playbook1"]['command_to_integration'][ 'test-command'] == ['Integration1', 'Integration2'] assert playbook_set[0]["Playbook1"]['command_to_integration'][ 'test-command_1'] == ['Integration1'] assert playbook_set[1]["Playbook2"]['command_to_integration'][ 'test-command'] == ['Integration1', 'Integration2'] assert playbook_set[1]["Playbook2"]['command_to_integration'][ 'test-command_2'] == ['Integration2']
def test_generic_command_that_uses_a_specific_brand(repo): """ Given - A playbook with a generic command (send-notification, etc.) that uses a specific brand When - Updating the commands_to_integrations fields in playbooks Then - Do not update 'command_to_integration' fields with any other brands """ integrations = [ { 'Slack': OrderedDict([ ('name', 'Slack'), ('commands', ['send-notification']), ]) }, { 'Syslog': OrderedDict([ ('name', 'Syslog'), ('commands', ['send-notification']), ]) }, ] playbooks = [{ 'Playbook': OrderedDict([ ('name', 'Playbook'), ('command_to_integration', { 'send-notification': 'Slack', }), ]), }] id_set_creator = IDSetCreator(print_logs=False) id_set_creator.id_set["integrations"] = integrations id_set_creator.id_set["playbooks"] = playbooks id_set_creator.add_command_to_implementing_integrations_mapping() playbook = id_set_creator.id_set['playbooks'][0]['Playbook'] assert playbook['command_to_integration'][ 'send-notification'] == 'Slack'
def test_do_not_modify_specific_brand(repo): """ Given - playbook with a command using a specific brand - playbook with a command using a specific brand When - updating the commands_to_integrations fields in playbooks Then - only update commands that don't have a specific brand """ integrations = [ { 'MainInteg': OrderedDict([ ('name', 'MainInteg'), ('commands', ['generic-command']), ]) }, { 'SecondaryInteg': OrderedDict([ ('name', 'SecondaryInteg'), ('commands', ['generic-command', 'specific-command']), ]) }, ] playbooks = [ { 'Playbook1': OrderedDict([ ('name', 'Playbook1'), ('command_to_integration', { 'specific-command': "", 'generic-command': "", }), ]), }, { 'Playbook2': OrderedDict([ ('name', 'Playbook2'), ('command_to_integration', { 'generic-command': 'MainInteg', 'no-integration': '', }), ]), }, ] id_set_creator = IDSetCreator(print_logs=False) id_set_creator.id_set["integrations"] = integrations id_set_creator.id_set["playbooks"] = playbooks id_set_creator.add_command_to_implementing_integrations_mapping() playbook1 = id_set_creator.id_set['playbooks'][0]['Playbook1'] playbook2 = id_set_creator.id_set['playbooks'][1]['Playbook2'] assert playbook1['command_to_integration']['specific-command'] == [ 'SecondaryInteg' ] assert playbook1['command_to_integration']['generic-command'] == [ 'MainInteg', 'SecondaryInteg' ] assert playbook2['command_to_integration'][ 'generic-command'] == 'MainInteg' assert playbook2['command_to_integration']['no-integration'] == ''