diff --git a/icon_validator/__init__.py b/icon_validator/__init__.py index e69de29..1d3ad8f 100644 --- a/icon_validator/__init__.py +++ b/icon_validator/__init__.py @@ -0,0 +1 @@ +VERSION = "2.47.15" diff --git a/icon_validator/rules/plugin_validators/title_validator.py b/icon_validator/rules/plugin_validators/title_validator.py index c5e880a..1f7bb7d 100644 --- a/icon_validator/rules/plugin_validators/title_validator.py +++ b/icon_validator/rules/plugin_validators/title_validator.py @@ -4,89 +4,139 @@ class TitleValidator(KomandPluginValidator): + def __init__(self): + super().__init__() + + self.all_offenses: str = "" + + def validate_title(self, title: str, plugin_title: bool = False) -> None: + """ + + :param title: + :param plugin_title: + + """ - @staticmethod - def validate_title(title, plugin_title=False): title_validation_list_lowercase = '", "'.join(title_validation_list).lower() + if not isinstance(title, str): - raise ValidationException("Title must not be blank") + self.all_offenses += ( + f"Title must be a string, not a number or other value: {title}\n" + ) if title == "": - raise ValidationException("Title must not be blank") + self.all_offenses += f"Title must not be blank: {title}\n" if title.endswith("."): - raise ValidationException("Title ends with period when it should not.") + self.all_offenses += f"Title ends with period when it should not: {title}\n" if title[0].islower() and not plugin_title: # This plugin title is OK: minFraud # This plugin title is OK: ifconfig.co - raise ValidationException("Title should not start with a lower case letter.") + self.all_offenses += ( + f"Title should not start with a lower case letter: {title}\n" + ) if title[0].isspace(): - raise ValidationException("Title should not start with a whitespace character.") + self.all_offenses += ( + f"Title should not start with a whitespace character: {title}\n" + ) if len(title.split()) > 7: - raise ValidationException(f"Title is too long, 6 words or less: contains {str(len(title.split()))}") + self.all_offenses += f"Title is too long, 6 words or less: contains {str(len(title.split()))}: {title}\n" for word in title.split(): if not title.startswith(word): if word in title_validation_list: if not title.endswith(word): - raise ValidationException( - 'English articles and conjunctions should be lowercase when in the middle of the sentence:' - f' "{title_validation_list_lowercase}"' - ) + self.all_offenses += f"English articles and conjunctions should be lowercase when in the middle of the sentence:'{title_validation_list_lowercase}': {title}\n" elif "By" == word and not title.endswith("By"): # This is OK: Order By # This is NOT OK: Search By String - raise ValidationException("Title contains a capitalized 'By' when it should not.") + self.all_offenses += f"Title contains a capitalized 'By' when it should not: {title}\n" elif "Of" == word and not title.endswith("Of"): # This is OK: Member Of # This is NOT OK: Type Of String - raise ValidationException("Title contains a capitalized 'Of' when it should not.") - elif not word[0].isupper() and not word.capitalize() in title_validation_list: + self.all_offenses += f"Title contains a capitalized 'Of' when it should not: {title}\n" + elif ( + not word[0].isupper() + and not word.capitalize() in title_validation_list + ): if not word.lower() == "by" or word.lower() == "of": if word.isalpha(): - raise ValidationException(f"Title contains a lowercase '{word}' when it should not.") + self.all_offenses += f"Title contains a lowercase '{word}' when it should not: {title}\n" + + def validate_actions(self, spec: dict, spec_section: str): + """ - @staticmethod - def validate_actions(dict_, dict_key): - if dict_key in dict_: - TitleValidator.validate_dictionary(dict_, dict_key) - for key, value in dict_[dict_key].items(): + :param spec: + :param spec_section: + + """ + + if spec_section in spec: + self.validate_dictionary(spec, spec_section) + for key, value in spec[spec_section].items(): if "input" in value: - TitleValidator.validate_dictionary(value, "input") + self.all_offenses += self.validate_dictionary( + value, "input" + ) if "output" in value: - TitleValidator.validate_dictionary(value, "output") + self.all_offenses += self.validate_dictionary( + value, "output" + ) if "state" in value: - TitleValidator.validate_dictionary(value, "state") + self.all_offenses += self.validate_dictionary( + value, "state" + ) if "schedule" in value: - TitleValidator.validate_dictionary({"schedule": value}, "schedule") + self.all_offenses += self.validate_dictionary( + {"schedule": value}, "schedule" + ) + + def validate_dictionary(self, spec: dict, section: str) -> None: + """ + + :param spec: + :param section: + + """ - @staticmethod - def validate_dictionary(dict_, dict_key): - if dict_key in dict_: - if not dict_[dict_key]: + if section in spec: + if not spec[section]: return - for key, value in dict_[dict_key].items(): - if "name" in value: - raise ValidationException( - f"Deprecated 'name' key '{value}' found when 'title' should be used instead.") + for key, value in spec[section].items(): if "title" in value: - try: - TitleValidator.validate_title(value["title"], plugin_title=False) - except Exception as e: - raise ValidationException(f"{dict_key} key '{key}' error.", e) + self.all_offenses += self.validate_title( + value["title"], plugin_title=False + ) - @staticmethod - def validate_plugin_title(spec): - if "title" not in spec.spec_dictionary(): - raise ValidationException("Plugin title is missing.") + if "name" in value: + self.all_offenses += f"Deprecated 'name' key '{value}' found when 'title' should be used instead: {value}\n" + + def validate_plugin_title(self, spec) -> None: + """ + + :param spec: + """ + + if "title" not in spec.spec_dictionary(): + self.all_offenses += f"Plugin title is missing" try: - TitleValidator.validate_title(spec.spec_dictionary()["title"], plugin_title=True) - except Exception as e: - raise ValidationException("Plugin title not valid.", e) + self.validate_title( + spec.spec_dictionary()["title"], plugin_title=True + ) + except Exception as error: + self.all_offenses += f"Plugin title not valid: {error}" def validate(self, spec): - TitleValidator.validate_plugin_title(spec) - TitleValidator.validate_actions(spec.spec_dictionary(), "actions") - TitleValidator.validate_actions(spec.spec_dictionary(), "triggers") - TitleValidator.validate_actions(spec.spec_dictionary(), "connection") - TitleValidator.validate_actions(spec.spec_dictionary(), "tasks") + """ + + :param spec: + + """ + + self.validate_plugin_title(spec) + self.validate_actions(spec.spec_dictionary(), "actions") + self.validate_actions(spec.spec_dictionary(), "triggers") + self.validate_actions(spec.spec_dictionary(), "tasks") + self.validate_actions(spec.spec_dictionary(), "connection") + if self.all_offenses: + raise ValidationException(self.all_offenses) diff --git a/setup.py b/setup.py index cdd3353..b2144cc 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +from icon_validator import VERSION from setuptools import setup, find_packages with open("README.md", "r") as fh: @@ -7,7 +7,7 @@ setup( name="insightconnect_integrations_validators", - version="2.47.14", + version=VERSION, description="Validator tooling for InsightConnect integrations", long_description=long_description, long_description_content_type="text/markdown",