Ejemplo n.º 1
0
 def test_recursive_extend_schema(self):
     """
         Given
             - A dict that represents a schema with sub-playbooks
         When
             - Run recursive_extend_schema on that schema
         Then
             - Ensure The reference is gone from the modified schema
             - Ensure the 'include' syntax has been replaced by the sub playbook itself
         """
     schema = {
         'mapping': {
             'inputs': {
                 'sequence': [{'include': 'input_schema'}],
                 'type': 'seq'}
         },
         'some-other-key': 'some-other-value'
     }
     sub_schema = {
         'mapping': {
             'required': {'type': 'bool'},
             'value': {'type': 'any'}
         },
         'type': 'map'}
     schema.update({'schema;input_schema': sub_schema})
     modified_schema = BaseUpdate.recursive_extend_schema(schema, schema)
     # Asserting the reference to the sub-playbook no longer exist in the modified schema
     assert 'schema;input_schema' not in modified_schema
     # Asserting the sub-playbook has replaced the reference
     assert modified_schema['mapping']['inputs']['sequence'][0] == sub_schema
     # Asserting some non related keys are not being deleted
     assert 'some-other-key' in modified_schema
Ejemplo n.º 2
0
 def test_update_fromVersion_default_version_lower_then_general(
         self, mocker):
     """
     Given
         - A new special content item with default fromVersion that is lower than the general.
     When
         - Calling set_fromVersion method.
     Then
         - Ensure that fromVersion key in the file data was set to the general fromVersion.
     """
     mocker.patch.object(BaseUpdate, '__init__', return_value=None)
     base_update = BaseUpdate()
     self.init_BaseUpdate(base_update)
     base_update.set_fromVersion('5.5.0')
     assert base_update.data.get(
         base_update.from_version_key) == GENERAL_DEFAULT_FROMVERSION
Ejemplo n.º 3
0
    def test_update_fromVersion_from_oldFile(self, mocker):
        """
        Given
            - An existing content item that already contains a fromversion key of 6.0.0.
        When
            - Calling set_fromVersion method.
        Then
            - Ensure that the fromVersion key in the file remains 6.0.0.
        """

        mocker.patch.object(BaseUpdate, '__init__', return_value=None)
        base_update = BaseUpdate()
        self.init_BaseUpdate(base_update, oldfile_version=VERSION_6_0_0)
        base_update.set_fromVersion()
        assert base_update.data.get(
            base_update.from_version_key) == VERSION_6_0_0
Ejemplo n.º 4
0
 def test_update_fromVersion_from_default_contentItem_askuser_False(
         self, mocker):
     """
     Given
         - A new content item.
     When
         - Calling set_fromVersion method.
     Then
         - Ensure that fromVersion key in the file data hasn't been generated.
     """
     mocker.patch.object(BaseUpdate, '__init__', return_value=None)
     base_update = BaseUpdate()
     self.init_BaseUpdate(base_update, assume_yes=False)
     mocker.patch.object(BaseUpdate, 'get_answer', return_value='F')
     base_update.set_fromVersion()
     assert base_update.from_version_key not in base_update.data
Ejemplo n.º 5
0
    def test_update_fromVersion_from_flag(self, mocker):
        """
        Given
            - A content item without a fromversion key in its current state.
            - The fromversion key to set is specified in the format arguments.
        When
            - Calling set_fromVersion method.
        Then
            - Ensure that fromVersion key in the file data was set to the specific test version.
        """

        mocker.patch.object(BaseUpdate, '__init__', return_value=None)
        base_update = BaseUpdate()
        self.init_BaseUpdate(base_update, VERSION_6_0_0)
        base_update.set_fromVersion()
        assert base_update.data.get(
            base_update.from_version_key) == VERSION_6_0_0
Ejemplo n.º 6
0
 def test_update_fromVersion_from_default_contentItem_askuser_True(
         self, mocker):
     """
     Given
         - A new content item.
     When
         - Calling set_fromVersion method.
     Then
         - Ensure that fromVersion key in the file data was set to the GENERAL_DEFAULT_FROMVERSION.
          item version if the user answers Y.
     """
     mocker.patch.object(BaseUpdate, '__init__', return_value=None)
     base_update = BaseUpdate()
     self.init_BaseUpdate(base_update, assume_yes=False)
     mocker.patch.object(BaseUpdate, 'get_answer', return_value='Y')
     base_update.set_fromVersion()
     assert base_update.data.get(
         base_update.from_version_key) == GENERAL_DEFAULT_FROMVERSION
Ejemplo n.º 7
0
 def test_recursive_extend_schema_prints_warning(self, mocker):
     """
         Given
             - A dict that represents a schema with sub-schema reference that has no actual sub-schema
         When
             - Run recursive_extend_schema on that schema
         Then
             - Ensure a warning about the missing sub-schema is printed
         """
     schema = {
         'mapping': {
             'inputs': {
                 'sequence': [{'include': 'input_schema'}],
                 'type': 'seq'}
         },
     }
     mocker.patch('click.echo')
     BaseUpdate.recursive_extend_schema(schema, schema)
     click.echo.assert_called_once_with('Could not find sub-schema for input_schema', LOG_COLORS.YELLOW)
Ejemplo n.º 8
0
    def test_update_fromVersion_from_data_with_oldfile(self, mocker):
        """
        Given
            - An existing content item that already contains a fromversion key of 6.1.0.
            - The user manually updated the fromversion key to 6.0.0 in the current version.
        When
            - Calling set_fromVersion method.
        Then
            - Ensure that fromVersion remains 6.0.0.
        """

        mocker.patch.object(BaseUpdate, '__init__', return_value=None)
        base_update = BaseUpdate()
        self.init_BaseUpdate(base_update,
                             oldfile_version='6.1.0',
                             current_fromVersion=VERSION_6_0_0)
        base_update.set_fromVersion()
        assert base_update.data.get(
            base_update.from_version_key) == VERSION_6_0_0
Ejemplo n.º 9
0
    def test_update_fromVersion_from_default_contentItem(
            self, mocker, content_type):
        """
        Given
            - A new special content item.
        When
            - Calling set_fromVersion method.
        Then
            - Ensure that fromVersion key in the file data was set to the specific default content item version.
        """
        mocker.patch.object(BaseUpdate, '__init__', return_value=None)
        mocker.patch(
            'demisto_sdk.commands.common.constants.GENERAL_DEFAULT_FROMVERSION',
            return_value='6.2.0')

        base_update = BaseUpdate()
        self.init_BaseUpdate(base_update)
        base_update.set_fromVersion(
            FILETYPE_TO_DEFAULT_FROMVERSION.get(content_type))
        assert base_update.data.get(
            base_update.from_version_key
        ) == FILETYPE_TO_DEFAULT_FROMVERSION.get(content_type)
Ejemplo n.º 10
0
 def init_BaseUpdate(self,
                     base_update: BaseUpdate,
                     version_to_set='',
                     oldfile_version='',
                     assume_yes=True,
                     current_fromVersion=''):
     base_update.verbose = False
     base_update.data = {}
     base_update.from_version_key = 'fromversion'
     if current_fromVersion:
         base_update.data[
             base_update.from_version_key] = current_fromVersion
     base_update.from_version = version_to_set
     base_update.old_file = {}
     base_update.assume_yes = assume_yes
     if oldfile_version:
         base_update.old_file[
             base_update.from_version_key] = oldfile_version
Ejemplo n.º 11
0
def test_initiate_file_validator(mocker, is_old_file, function_validate):
    """
    Given
        - New file
        - Existing file in the repo
    When
        - Running validate on the file
    Then
        - Running validate -i on new files
        - Running validate -g on modified files
    """
    mocker.patch.object(BaseUpdate, '__init__', return_value=None)
    base_update = BaseUpdate()
    base_update.no_validate = False
    base_update.output_file = 'output_file_path'
    base_update.validate_manager = ValidateManager
    mocker.patch.object(BaseUpdate, 'is_old_file', return_value=is_old_file)

    result = mocker.patch.object(ValidateManager, function_validate)

    base_update.initiate_file_validator()
    assert result.call_count == 1