Exemple #1
0
def test_validate_readme_exists_not_checking_on_test_playbook(repo, mocker):
    """
    Given:
    - A test playbook

    When:
    - Validating if a readme file exists

    Then:
    - Ensure that True is being returned since we don't validate a readme for test playbooks.
    """
    pack = repo.create_pack('TEST_PALYBOOK')
    test_playbook = pack.create_test_playbook('test_playbook1')
    structue_validator = StructureValidator(test_playbook.yml.path)
    content_entity_validator = ContentEntityValidator(structue_validator)
    assert content_entity_validator.validate_readme_exists()
Exemple #2
0
def test_yml_has_test_key(file_path, schema, expected):
    # type: (str, str, bool) -> None
    """
        Given
        - A yml file test playbook list and the yml file type

        When
        - Checking if file has test playbook exists

        Then
        -  Ensure the method 'yml_has_test_key' return answer accordingly
    """
    structure_validator = StructureValidator(file_path,
                                             predefined_scheme=schema)
    validator = ContentEntityValidator(structure_validator)
    tests = structure_validator.current_file.get('tests')
    assert validator.yml_has_test_key(tests, schema) == expected
Exemple #3
0
def test_validate_readme_exists_not_checking_on_api_modules(repo):
    """
    Given:
    - An APIModules script

    When:
    - Validating if a readme file exists

    Then:
    - Ensure that True is being returned since we don't validate a readme for APIModules files.
    """
    pack = repo.create_pack(API_MODULES_PACK)
    api_modules = pack.create_script('TestApiModule', readme=None)
    os.remove(api_modules.readme.path)
    structue_validator = StructureValidator(api_modules.yml.path)
    content_entity_validator = ContentEntityValidator(structue_validator)
    assert content_entity_validator.validate_readme_exists()
Exemple #4
0
def test_entity_valid_name_valid(repo, mocker):
    """
    Given:
    - Entity name that does not contain excluded words.

    When:
    - Checking whether entity name contains excluded word.

    Then:
    - Ensure true is returned.
    """
    pack = repo.create_pack('TestPack')
    integration = pack.create_integration(name='BitcoinAbuse')
    integration.create_default_integration(name='BitcoinAbuse')
    integration.yml.update({'display': 'BitcoinAbuse'})
    integration_structure_validator = StructureValidator(integration.yml.path)
    integration_content_entity_validator = ContentEntityValidator(
        integration_structure_validator)
    assert integration_content_entity_validator.name_does_not_contain_excluded_word(
    )
Exemple #5
0
def test_entity_valid_name_invalid(repo, mocker):
    """
    Given:
    - Entity name with excluded word.

    When:
    - Checking whether entity name contains excluded word.

    Then:
    - Ensure false is returned.
    """
    pack = repo.create_pack('TestPack')
    script = pack.create_script(name='QRadar')
    script.create_default_script(name='QRadar')
    excluded_word = EXCLUDED_DISPLAY_NAME_WORDS[0]
    script.yml.update({'name': f'QRadar ({excluded_word})'})
    script_structure_validator = StructureValidator(script.yml.path)
    script_content_entity_validator = ContentEntityValidator(
        script_structure_validator)
    mocker.patch.object(script_content_entity_validator, 'handle_error')
    assert not script_content_entity_validator.name_does_not_contain_excluded_word(
    )