Esempio n. 1
0
def test_is_not_default_image():
    int_path = os.path.normpath(
        os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                     'integration-Zoom.yml'))
    image_validator = image.ImageValidator(int_path)
    assert image_validator.is_not_default_image() is False

    image_path = os.path.normpath(
        os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                     'default_image.png'))
    image_validator = image.ImageValidator(image_path)
    assert image_validator.is_not_default_image() is False

    image_path = os.path.normpath(
        os.path.join(__file__,
                     f'{git_path()}/demisto_sdk/commands/init/templates',
                     'HelloWorld', 'HelloWorld_image.png'))
    image_validator = image.ImageValidator(image_path)
    assert image_validator.is_not_default_image() is False

    int_path = os.path.normpath(
        os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                     'fake_integration.yml'))
    image_validator = image.ImageValidator(int_path)
    assert image_validator.is_not_default_image() is False
Esempio n. 2
0
def test_json_outputs_where_no_image_in_integration(repo):
    """
        Given
            - An integration without an existing image
            - A json file for writing the outputs

        When
            - Validating the image integration

        Then
            - Ensure that the outputs are correct.
    """
    # Create pack and integration
    pack = repo.create_pack('PackName')
    integration = pack.create_integration('IntName')
    integration.create_default_integration()

    # Remove the integration image
    image_path = os.path.join(integration.path, 'IntName_image.png')
    if os.path.exists(image_path):
        os.remove(image_path)

    # Run the image validator with a json file path
    json_file_path = os.path.join(integration.path, 'json_outputs.json')
    image_validator = image.ImageValidator(integration.yml.path,
                                           json_file_path=json_file_path)

    # Check the outputs in the json file
    with open(image_validator.json_file_path, "r") as r:
        json_outputs = json.loads(r.read())

        assert json_outputs[0]['filePath'] == image_path
        assert json_outputs[0]['fileType'] == 'png'
        assert json_outputs[0]['entityType'] == 'image'
Esempio n. 3
0
def test_is_valid_image_name_with_invalid_name(repo):
    """
        Given
            - An integration image with a invalid name

        When
            - Validating the integration image name

        Then
            - Ensure that image validator for integration failed.
    """

    pack = repo.create_pack('PackName')

    integration = pack.create_integration('IntName')
    integration.create_default_integration()

    if os.path.exists(integration.image.path):
        os.remove(integration.image.path)
        integration.image = None

    integration.image = File(
        integration._tmpdir_integration_path / f'{integration.name}_img.png',
        integration._repo.path)

    with ChangeCWD(repo.path):

        image_validator = image.ImageValidator(integration.image.path)

        assert not image_validator.is_valid_image_name()
Esempio n. 4
0
def test_is_not_default_image():
    int_path = os.path.normpath(os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                                             'integration-Zoom.yml'))
    image.INTEGRATION_REGXES.append(int_path)
    image_validator = image.ImageValidator(int_path)
    assert image_validator.is_not_default_image() is False
    image_path = os.path.normpath(os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                                               'default_image.png'))
    image.YML_INTEGRATION_REGEXES.append(image_path)
    image_validator = image.ImageValidator(image_path)
    assert image_validator.is_not_default_image() is False
    int_path = os.path.normpath(os.path.join(__file__, f'{git_path()}/demisto_sdk/tests', 'test_files',
                                             'fake_integration.yml'))
    image.INTEGRATION_REGXES.append(int_path)
    image_validator = image.ImageValidator(int_path)
    assert image_validator.is_not_default_image() is False
Esempio n. 5
0
def test_is_valid_image_name_with_valid_name(repo):
    """
        Given
            - An integration image with a valid name

        When
            - Validating the integration image name

        Then
            - Ensure that image validator for integration passes.
    """

    pack = repo.create_pack('PackName')

    integration = pack.create_integration('IntName')
    integration.create_default_integration()

    image_validator = image.ImageValidator(integration.yml.path)

    assert image_validator.is_valid_image_name()