class TestIsFeedParamsExist: def setup(self): config = { 'configuration': deepcopy(FEED_REQUIRED_PARAMS), 'script': {'feed': True} } self.validator = IntegrationValidator(mock_structure("", config)) def test_valid(self): assert self.validator.all_feed_params_exist(), 'all_feed_params_exist() returns False instead True' def test_sanity(self): # missing param in configuration self.validator.current_file['configuration'] = [t for t in self.validator.current_file['configuration'] if not t.get('display')] assert self.validator.all_feed_params_exist() is False, 'all_feed_params_exist() returns True instead False' def test_missing_field(self): # missing param configuration = self.validator.current_file['configuration'] for i in range(len(configuration)): if not configuration[i].get('display'): del configuration[i]['name'] self.validator.current_file['configuration'] = configuration assert self.validator.all_feed_params_exist() is False, 'all_feed_params_exist() returns True instead False' def test_malformed_field(self): # incorrect param self.validator.current_file['configuration'] = [] for t in self.validator.current_file['configuration']: if not t.get('display'): t['type'] = 123 self.validator.current_file['configuration'].append(t) assert self.validator.all_feed_params_exist() is False, 'all_feed_params_exist() returns True instead False' NO_HIDDEN = {"configuration": [{"id": "new", "name": "new", "display": "test"}, {"d": "123", "n": "s", "r": True}]} HIDDEN_FALSE = {"configuration": [{"id": "n", "hidden": False}, {"display": "123", "name": "serer"}]} HIDDEN_TRUE = {"configuration": [{"id": "n", "n": "n"}, {"display": "123", "required": "false", "hidden": True}]} HIDDEN_TRUE_AND_FALSE = {"configuration": [{"id": "n", "hidden": False}, {"ty": "0", "r": "true", "hidden": True}]} HIDDEN_ALLOWED_TRUE = {"configuration": [{"name": "longRunning", "required": "false", "hidden": True}]} IS_VALID_HIDDEN_PARAMS = [ (NO_HIDDEN, True), (HIDDEN_FALSE, True), (HIDDEN_TRUE, False), (HIDDEN_TRUE_AND_FALSE, False), (HIDDEN_ALLOWED_TRUE, True) ] @pytest.mark.parametrize("current, answer", IS_VALID_HIDDEN_PARAMS) def test_is_valid_hidden_params(self, current, answer): structure = mock_structure(current_file=current) validator = IntegrationValidator(structure) assert validator.is_valid_hidden_params() is answer @pytest.mark.parametrize("script_type, fromversion, res", [ ('powershell', None, False), ('powershell', '4.5.0', False), ('powershell', '5.5.0', True), ('powershell', '5.5.1', True), ('powershell', '6.0.0', True), ('python', '', True), ('python', '4.5.0', True), ]) def test_valid_pwsh(self, script_type, fromversion, res): current = { "script": {"type": script_type}, "fromversion": fromversion, } structure = mock_structure("", current) validator = IntegrationValidator(structure) assert validator.is_valid_pwsh() == res
class TestIsFeedParamsExist: def setup(self): config = { 'configuration': deepcopy(FEED_REQUIRED_PARAMS), 'script': { 'feed': True } } self.validator = IntegrationValidator(mock_structure("", config)) def test_valid(self): assert self.validator.all_feed_params_exist( ), 'all_feed_params_exist() returns False instead True' def test_sanity(self): # missing param in configuration self.validator.current_file['configuration'] = [ t for t in self.validator.current_file['configuration'] if not t.get('display') ] assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' def test_missing_field(self): # missing param configuration = self.validator.current_file['configuration'] for i in range(len(configuration)): if not configuration[i].get('display'): del configuration[i]['name'] self.validator.current_file['configuration'] = configuration assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' def test_malformed_field(self): # incorrect param self.validator.current_file['configuration'] = [] for t in self.validator.current_file['configuration']: if not t.get('display'): t['type'] = 123 self.validator.current_file['configuration'].append(t) assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' NO_HIDDEN = { "configuration": [{ "id": "new", "name": "new", "display": "test" }, { "d": "123", "n": "s", "r": True }] } HIDDEN_FALSE = { "configuration": [{ "id": "n", "hidden": False }, { "display": "123", "name": "serer" }] } HIDDEN_TRUE = { "configuration": [{ "id": "n", "n": "n" }, { "display": "123", "required": "false", "hidden": True }] } HIDDEN_TRUE_AND_FALSE = { "configuration": [{ "id": "n", "hidden": False }, { "ty": "0", "r": "true", "hidden": True }] } IS_ALL_PARAMS_NOT_HIDDEN_INPUTS = [ (NO_HIDDEN, True), (HIDDEN_FALSE, True), (HIDDEN_TRUE, False), (HIDDEN_TRUE_AND_FALSE, False), ] @pytest.mark.parametrize("current, answer", IS_ALL_PARAMS_NOT_HIDDEN_INPUTS) def test_is_all_params_not_hidden(self, current, answer): structure = mock_structure(current_file=current) validator = IntegrationValidator(structure) assert validator.is_all_params_not_hidden() is answer
class TestIsFeedParamsExist: def setup(self): config = { 'configuration': deepcopy(FEED_REQUIRED_PARAMS), 'script': { 'feed': True } } self.validator = IntegrationValidator(mock_structure("", config)) def test_valid(self): assert self.validator.all_feed_params_exist( ), 'all_feed_params_exist() returns False instead True' def test_sanity(self): # missing param in configuration self.validator.current_file['configuration'] = [ t for t in self.validator.current_file['configuration'] if not t.get('display') ] assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' def test_missing_field(self): # missing param configuration = self.validator.current_file['configuration'] for i in range(len(configuration)): if not configuration[i].get('display'): del configuration[i]['name'] self.validator.current_file['configuration'] = configuration assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' def test_malformed_field(self): # incorrect param self.validator.current_file['configuration'] = [] for t in self.validator.current_file['configuration']: if not t.get('display'): t['type'] = 123 self.validator.current_file['configuration'].append(t) assert self.validator.all_feed_params_exist( ) is False, 'all_feed_params_exist() returns True instead False' def test_hidden_feed_reputation_field(self): # the feed reputation param is hidden configuration = self.validator.current_file['configuration'] for item in configuration: if item.get('name') == 'feedReputation': item['hidden'] = True assert self.validator.all_feed_params_exist() is True, \ 'all_feed_params_exist() returns False instead True for feedReputation param' NO_HIDDEN = { "configuration": [{ "id": "new", "name": "new", "display": "test" }, { "d": "123", "n": "s", "r": True }] } HIDDEN_FALSE = { "configuration": [{ "id": "n", "hidden": False }, { "display": "123", "name": "serer" }] } HIDDEN_TRUE = { "configuration": [{ "id": "n", "n": "n" }, { "display": "123", "required": "false", "hidden": True }] } HIDDEN_TRUE_AND_FALSE = { "configuration": [{ "id": "n", "hidden": False }, { "ty": "0", "r": "true", "hidden": True }] } HIDDEN_ALLOWED_TRUE = { "configuration": [{ "name": "longRunning", "required": "false", "hidden": True }] } HIDDEN_ALLOWED_FEED_REPUTATION = { "configuration": [{ "name": "feedReputation", "required": "false", "hidden": True }] } IS_VALID_HIDDEN_PARAMS = [ (NO_HIDDEN, True), (HIDDEN_FALSE, True), (HIDDEN_TRUE, False), (HIDDEN_TRUE_AND_FALSE, False), (HIDDEN_ALLOWED_TRUE, True), (HIDDEN_ALLOWED_FEED_REPUTATION, True), ] @pytest.mark.parametrize("current, answer", IS_VALID_HIDDEN_PARAMS) def test_is_valid_hidden_params(self, current, answer): structure = mock_structure(current_file=current) validator = IntegrationValidator(structure) assert validator.is_valid_hidden_params() is answer @pytest.mark.parametrize("script_type, fromversion, res", [ ('powershell', None, False), ('powershell', '4.5.0', False), ('powershell', '5.5.0', True), ('powershell', '5.5.1', True), ('powershell', '6.0.0', True), ('python', '', True), ('python', '4.5.0', True), ]) def test_valid_pwsh(self, script_type, fromversion, res): current = { "script": { "type": script_type }, "fromversion": fromversion, } structure = mock_structure("", current) validator = IntegrationValidator(structure) assert validator.is_valid_pwsh() == res def test_empty_commands(self): """ Given: an integration with no commands When: running validate on integration with no command. Then: Validate it's valid. """ current = {"script": {"commands": None}} structure = mock_structure("", current) validator = IntegrationValidator(structure) validator.current_file = current assert validator.is_valid_default_argument_in_reputation_command( ) is True @pytest.mark.parametrize('param', [{ 'commands': ['something'] }, { 'isFetch': True }, { 'longRunning': True }, { 'feed': True }]) def test_is_there_a_runnable(self, param): """ Given: one of any runnable integration When: running validate on integration with at least one of commands, fetch, feed or long-running Then: Validate it's valid. """ current = {"script": param} structure = mock_structure("", current) validator = IntegrationValidator(structure) validator.current_file = current assert validator.is_there_a_runnable() is True def test_is_there_a_runnable_negative(self): """ Given: an integration with no runnable param When: running validate on integration with no one of commands, fetch, feed or long-running Then: Validate it's invalid. """ current = {"script": {}} structure = mock_structure("", current) validator = IntegrationValidator(structure) validator.current_file = current assert validator.is_there_a_runnable() is False