Skip to content

Commit

Permalink
Move ImageValidator and DescriptionValidator validations to Integrati…
Browse files Browse the repository at this point in the history
…onValidator (#330)

* move imagevalidator and descriptionvalidator to integrationvalidator

* add tests

* add commas and fix docstring

* revert is_all_params_not_hidden removal and adjust is_valid_beta test
  • Loading branch information
Itay4 committed Apr 6, 2020
1 parent 5cac11a commit 310ec20
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 38 deletions.
48 changes: 43 additions & 5 deletions demisto_sdk/commands/common/hook_validations/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
PYTHON_SUBTYPES, Errors)
from demisto_sdk.commands.common.hook_validations.base_validator import \
BaseValidator
from demisto_sdk.commands.common.hook_validations.description import \
DescriptionValidator
from demisto_sdk.commands.common.hook_validations.docker import \
DockerImageValidator
from demisto_sdk.commands.common.hook_validations.image import ImageValidator
from demisto_sdk.commands.common.hook_validations.utils import is_v2_file
from demisto_sdk.commands.common.tools import (get_dockerimage45, print_error,
print_warning,
Expand Down Expand Up @@ -50,9 +53,15 @@ def is_backward_compatible(self):
]
return not any(answers)

def is_valid_file(self, validate_rn=True):
# type: (bool) -> bool
"""Check whether the Integration is valid or not"""
def is_valid_file(self, validate_rn: bool = True) -> bool:
"""Check whether the Integration is valid or not
Args:
validate_rn (bool): Whether to validate release notes (changelog) or not.
Returns:
bool: True if integration is valid, False otherwise.
"""
answers = [
super().is_valid_file(validate_rn),
self.is_valid_subtype(),
Expand All @@ -66,15 +75,18 @@ def is_valid_file(self, validate_rn=True):
self.is_valid_fetch(),
self.is_valid_display_name(),
self.is_all_params_not_hidden(),
self.is_valid_image(),
self.is_valid_description(beta_integration=False),
]
return all(answers)

def is_valid_beta_integration(self):
# type: () -> bool
def is_valid_beta_integration(self) -> bool:
"""Check whether the beta Integration is valid or not, update the _is_valid field to determine that"""
answers = [
self.is_valid_default_arguments(),
self.is_valid_beta(),
self.is_valid_image(),
self.is_valid_description(beta_integration=True),
]
return all(answers)

Expand Down Expand Up @@ -585,3 +597,29 @@ def is_all_params_not_hidden(self) -> bool:
ans = False
print_error(Errors.found_hidden_param(int_parameter.get('name')))
return ans

def is_valid_image(self) -> bool:
"""Verifies integration image/logo is valid.
Returns:
bool. True if integration image/logo is valid, False otherwise.
"""
image_validator = ImageValidator(self.file_path)
if not image_validator.is_valid():
return False
return True

def is_valid_description(self, beta_integration: bool = False) -> bool:
"""Verifies integration description is valid.
Returns:
bool: True if description is valid, False otherwise.
"""
description_validator = DescriptionValidator(self.file_path)
if beta_integration:
if not description_validator.is_valid_beta_description():
return False
else:
if not description_validator.is_valid():
return False
return True
24 changes: 23 additions & 1 deletion demisto_sdk/commands/common/tests/integration_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from copy import deepcopy
from typing import Optional

import pytest
from demisto_sdk.commands.common.constants import (FEED_REQUIRED_PARAMS,
FETCH_REQUIRED_PARAMS)
from demisto_sdk.commands.common.git_tools import git_path
from demisto_sdk.commands.common.hook_validations.integration import \
IntegrationValidator
from demisto_sdk.commands.common.hook_validations.structure import \
Expand Down Expand Up @@ -302,7 +304,7 @@ def test_is_valid_beta_integration(self, current, old, answer):
validator = IntegrationValidator(structure)
validator.current_file = current
validator.old_file = old
assert validator.is_valid_beta_integration() is answer
assert validator.is_valid_beta() is answer

PROXY_VALID = [{"name": "proxy", "type": 8, "display": "Use system proxy settings", "required": False}]
PROXY_WRONG_TYPE = [{"name": "proxy", "type": 9, "display": "Use system proxy settings", "required": False}]
Expand Down Expand Up @@ -442,6 +444,26 @@ def test_is_valid_display_name(self, current, answer):
validator.current_file = current
assert validator.is_valid_display_name() is answer

def test_is_valid_image_positive(self, monkeypatch):
integration_path = os.path.normpath(
os.path.join(f'{git_path()}/demisto_sdk/tests', 'test_files', 'integration-Zoom.yml')
)
structure = mock_structure(file_path=integration_path)
monkeypatch.setattr(
'demisto_sdk.commands.common.hook_validations.image.INTEGRATION_REGXES',
[integration_path]
)
validator = IntegrationValidator(structure)
assert validator.is_valid_image() is True

def test_is_valid_description_positive(self):
integration_path = os.path.normpath(
os.path.join(f'{git_path()}/demisto_sdk/tests', 'test_files', 'integration-Zoom.yml')
)
structure = mock_structure(file_path=integration_path)
validator = IntegrationValidator(structure)
assert validator.is_valid_description() is True


class TestIsFetchParamsExist:
def setup(self):
Expand Down
32 changes: 0 additions & 32 deletions demisto_sdk/commands/validate/file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
ConfJsonValidator
from demisto_sdk.commands.common.hook_validations.dashboard import \
DashboardValidator
from demisto_sdk.commands.common.hook_validations.description import \
DescriptionValidator
from demisto_sdk.commands.common.hook_validations.id import IDSetValidator
from demisto_sdk.commands.common.hook_validations.image import ImageValidator
from demisto_sdk.commands.common.hook_validations.incident_field import \
Expand Down Expand Up @@ -303,14 +301,6 @@ def validate_modified_files(self, modified_files): # noqa: C901
self._is_valid = False

elif checked_type(file_path, YML_INTEGRATION_REGEXES):
image_validator = ImageValidator(file_path)
if not image_validator.is_valid():
self._is_valid = False

description_validator = DescriptionValidator(file_path)
if not description_validator.is_valid():
self._is_valid = False

integration_validator = IntegrationValidator(structure_validator)
if self.is_backward_check and not integration_validator.is_backward_compatible():
self._is_valid = False
Expand All @@ -319,14 +309,6 @@ def validate_modified_files(self, modified_files): # noqa: C901
self._is_valid = False

elif checked_type(file_path, YML_BETA_INTEGRATIONS_REGEXES):
image_validator = ImageValidator(file_path)
if not image_validator.is_valid():
self._is_valid = False

description_validator = DescriptionValidator(file_path)
if not description_validator.is_valid_beta_description():
self._is_valid = False

integration_validator = IntegrationValidator(structure_validator)
if not integration_validator.is_valid_beta_integration():
self._is_valid = False
Expand Down Expand Up @@ -440,16 +422,6 @@ def validate_added_files(self, added_files, file_type: str = None): # noqa: C90
self._is_valid = False

elif checked_type(file_path, YML_INTEGRATION_REGEXES) or file_type == 'integration':
image_validator = ImageValidator(file_path)
# if file_type(non git path) the image is not in a separate path
image_validator.file_path = file_path if file_type else image_validator.file_path
if not image_validator.is_valid():
self._is_valid = False

description_validator = DescriptionValidator(file_path)
if not description_validator.is_valid():
self._is_valid = False

integration_validator = IntegrationValidator(structure_validator)
if not integration_validator.is_valid_file(validate_rn=not file_type):
self._is_valid = False
Expand All @@ -466,10 +438,6 @@ def validate_added_files(self, added_files, file_type: str = None): # noqa: C90

elif re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
re.match(BETA_INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
description_validator = DescriptionValidator(file_path)
if not description_validator.is_valid_beta_description():
self._is_valid = False

integration_validator = IntegrationValidator(structure_validator)
if not integration_validator.is_valid_beta_integration():
self._is_valid = False
Expand Down

0 comments on commit 310ec20

Please sign in to comment.