def test_isarray_false(self, integration, capsys): """ Given: - An integration with IP command and ip argument when isArray is False When: - Running validate on IP command Then: - Check a warning printed to the user. - Validate isArray hasn't changed. """ yml_contents = integration.yml.read_dict() yml_contents['script']['commands'] = [ { 'name': 'ip', 'arguments': [{ 'isArray': False, 'name': 'ip' }] } ] integration.yml.write_dict(yml_contents) base_yml = IntegrationYMLFormat(integration.yml.path) base_yml.set_reputation_commands_basic_argument_as_needed() captured = capsys.readouterr() assert 'Array field in ip command is set to False.' in captured.out assert integration.yml.read_dict()['script']['commands'][0]['arguments'][0]['isArray'] is False
def test_set_fetch_params_in_config_with_default_value(): """ Given - Integration yml with isfetch field labeled as true and all necessary params exist including defaultvalue fields. When - Running the format command. Then - Ensure the defaultvalue fields remain after the execution. - Ensure that the config param with the defaultvalue key is not getting duplicated without the defaultvalue key. """ base_yml = IntegrationYMLFormat(SOURCE_FORMAT_INTEGRATION_VALID, path="schema_path", verbose=True) base_yml.set_fetch_params_in_config() configuration_params = base_yml.data.get('configuration', []) assert 'defaultvalue' in configuration_params[5] assert { 'display': 'Incident type', 'name': 'incidentType', 'required': False, 'type': 13 } not in configuration_params assert { 'display': 'Incident type', 'name': 'incidentType', 'required': False, 'type': 13, 'defaultvalue': '' } in configuration_params
def test_bang_commands_default_arguments(source_path, bang_command, verifications): base_yml = IntegrationYMLFormat(source_path) base_yml.set_reputation_commands_basic_argument_as_needed() for command in base_yml.yml_data['script']['commands']: if bang_command == command['name']: command_arguments = command['arguments'] for argument in command_arguments: if argument.get('name', '') == bang_command: for verification in verifications: assert argument[verification[0]] == verification[1]
def test_proxy_ssl_descriptions(source_path, argument_name, argument_description, appearances): base_yml = IntegrationYMLFormat(source_path) base_yml.update_proxy_insecure_param_to_default() argument_count = 0 for argument in base_yml.yml_data['configuration']: if argument_name == argument['name']: assert argument_description == argument['display'] argument_count += 1 assert argument_count == appearances
def test_proxy_ssl_descriptions(source_path, argument_name, argument_description, file_type, appearances): schema_path = os.path.normpath( os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format(file_type))) base_yml = IntegrationYMLFormat(source_path, path=schema_path) base_yml.update_proxy_insecure_param_to_default() argument_count = 0 for argument in base_yml.data['configuration']: if argument_name == argument['name']: assert argument_description == argument['display'] argument_count += 1 assert argument_count == appearances
def test_bang_commands_default_arguments(source_path, file_type, bang_command, verifications): schema_path = os.path.normpath( os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format(file_type))) base_yml = IntegrationYMLFormat(source_path, path=schema_path) base_yml.set_reputation_commands_basic_argument_as_needed() for command in base_yml.data['script']['commands']: if bang_command == command['name']: command_arguments = command['arguments'] for argument in command_arguments: if argument.get('name', '') == bang_command: for verification in verifications: assert argument[verification[0]] == verification[1]
def test_set_feed_params_in_config_with_default_value(): """ Given - Integration yml with feed field labeled as true and all necessary params exist including defaultvalue fields. When - Running the format command. Then - Ensures the defaultvalue fields remain after the execution. """ base_yml = IntegrationYMLFormat(FEED_INTEGRATION_VALID, path="schema_path") base_yml.set_feed_params_in_config() configuration_params = base_yml.data.get('configuration', []) assert 'defaultvalue' in configuration_params[0]
def test_update_docker_format(self, tmpdir, mocker): """Test that script and integration formatter update docker image tag """ test_tag = '1.0.0-test-tag' mocker.patch.object(DockerImageValidator, 'get_docker_image_latest_tag_request', return_value=test_tag) schema_dir = f'{GIT_ROOT}/demisto_sdk/commands/common/schemas' test_files_dir = f'{GIT_ROOT}/demisto_sdk/tests/test_files/update-docker' dest = str(tmpdir.join('docker-res.yml')) # test example script file with version before 5.0.0 src_file = f'{test_files_dir}/SlackAsk.yml' with open(src_file) as f: data = yaml.safe_load(f) org_docker = data['dockerimage'] assert data['fromversion'] < '5.0.0' assert not data.get( 'dockerimage45') # make sure for the test that dockerimage45 is not set (so we can verify that we set it in format) format_obj = ScriptYMLFormat(src_file, output=dest, path=f'{schema_dir}/script.yml', no_validate=True, update_docker=True) assert format_obj.run_format() == 0 with open(dest) as f: data = yaml.safe_load(f) assert data['dockerimage'].endswith(f':{test_tag}') assert data['dockerimage45'] == org_docker # test integration file src_file = f'{test_files_dir}/Slack.yml' format_obj = IntegrationYMLFormat(src_file, output=dest, path=f'{schema_dir}/integration.yml', no_validate=True, update_docker=True) assert format_obj.run_format() == 0 with open(dest) as f: data = yaml.safe_load(f) assert data['script']['dockerimage'].endswith(f':{test_tag}') assert not data['script'].get('dockerimage45')
def test_update_tests_on_integration_with_test_playbook(self): """ Given - An integration file. When - Run format on the integration Then - Ensure run_format return value is 0 - Ensure `tests` field gets the Test Playbook ID """ test_files_path = os.path.join(git_path(), 'demisto_sdk', 'tests') vmware_integration_yml_path = os.path.join(test_files_path, 'test_files', 'content_repo_example', 'Packs', 'VMware', 'Integrations', 'integration-VMware.yml') formatter = IntegrationYMLFormat(input=vmware_integration_yml_path, output='') res = formatter.update_tests() assert res is None assert formatter.data.get('tests') == ['VMWare Test']
def test_format_on_feed_integration_adds_feed_parameters(self): """ Given - Feed integration yml without feed parameters configured. When - Running the format command. Then - Ensures the feed parameters are added. """ base_yml = IntegrationYMLFormat(FEED_INTEGRATION_EMPTY_VALID, path="schema_path", verbose=True) base_yml.set_feed_params_in_config() configuration_params = base_yml.data.get('configuration', []) for param_details in FEED_REQUIRED_PARAMS: param = {'name': param_details.get('name')} param.update(param_details.get('must_equal', dict())) param.update(param_details.get('must_contain', dict())) assert param in configuration_params
def test_pwsh_format(tmpdir, yml_file, yml_type): schema_path = os.path.normpath( os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format(yml_type))) dest = str(tmpdir.join('pwsh_format_res.yml')) src_file = f'{GIT_ROOT}/demisto_sdk/tests/test_files/{yml_file}' if yml_type == 'script': format_obj = ScriptYMLFormat(src_file, output=dest, path=schema_path) else: format_obj = IntegrationYMLFormat(src_file, output=dest, path=schema_path) assert format_obj.run_format() == 0 with open(dest) as f: data = yaml.safe_load(f) assert data['fromversion'] == '5.5.0' assert data['commonfields']['version'] == -1