Esempio n. 1
0
    def test_group_layouts_needing_conversion_by_layout_id(self, tmpdir):
        """
        Given:
        -

        When:
        - Grouping layouts needing conversion by their layout ID.

        Then:
        - Ensure expected dict object is returned.
        """
        fake_pack_name = 'FakeTestPack'
        repo = Repo(tmpdir)
        repo_path = Path(repo.path)
        fake_pack = MockPack(repo_path / 'Packs', fake_pack_name, repo)
        fake_pack.create_layout('close-ExtraHop_Detection', util_load_json(self.LAYOUT_CLOSE_PATH))
        fake_pack.create_layout('details-ExtraHop_Detection', util_load_json(self.LAYOUT_DETAILS_PATH))
        fake_pack.create_layout('edit-ExtraHop_Detection', util_load_json(self.LAYOUT_EDIT_PATH))
        fake_pack.create_layout('quickView-ExtraHop_Detection',
                                util_load_json(self.LAYOUT_QUICK_VIEW_PATH))
        fake_pack.create_layout('mobile-ExtraHop_Detection', util_load_json(self.LAYOUT_MOBILE_PATH))
        fake_pack_path = fake_pack.path
        layout_converter = LayoutSixConverter(Pack(fake_pack_path))
        result = layout_converter.group_layouts_needing_conversion_by_layout_id()
        assert len(result) == 1 and 'ExtraHop Detection' in result
        layout_kinds = {layout['kind'] for layout in result['ExtraHop Detection']}
        assert all(layout.layout_id() == 'ExtraHop Detection' for layout in result['ExtraHop Detection'])
        assert layout_kinds == {'close', 'details', 'edit', 'mobile', 'quickView'}
Esempio n. 2
0
    def test_convert_dir(self, tmpdir):
        """
        Given:
        - Pack.

        When:
        - Converting every layout of version 6.0.0 and above to version 5.9.9 and below.

        Then:
        - Ensure expected layouts are created with expected values.
        """
        fake_pack_name = 'FakeTestPack'
        repo = Repo(tmpdir)
        repo_path = Path(repo.path)
        fake_pack = MockPack(repo_path / 'Packs', fake_pack_name, repo)
        fake_pack.create_layout('close-ExtraHop_Detection', util_load_json(self.LAYOUT_CLOSE_PATH))
        fake_pack.create_layout('details-ExtraHop_Detection', util_load_json(self.LAYOUT_DETAILS_PATH))
        fake_pack.create_layout('edit-ExtraHop_Detection', util_load_json(self.LAYOUT_EDIT_PATH))
        fake_pack.create_layout('quickView-ExtraHop_Detection',
                                util_load_json(self.LAYOUT_QUICK_VIEW_PATH))
        fake_pack.create_layout('mobile-ExtraHop_Detection', util_load_json(self.LAYOUT_MOBILE_PATH))
        fake_pack_path = fake_pack.path
        layout_converter = LayoutSixConverter(Pack(fake_pack_path))
        layout_converter.convert_dir()
        expected_new_layout_path = f'{str(layout_converter.pack.path)}/Layouts/layoutscontainer-ExtraHop_Detection.json'
        assert os.path.exists(expected_new_layout_path)
        with open(expected_new_layout_path, 'r') as f:
            layout_data = json.loads(f.read())
        test_data_json = util_load_json(os.path.join(__file__,
                                                     f'{git_path()}/demisto_sdk/commands/convert/converters/layout/'
                                                     'tests/test_data'
                                                     '/layoutscontainer-ExtraHop_Detection.json'))
        assert layout_data == test_data_json
        os.remove(expected_new_layout_path)
Esempio n. 3
0
    def test_get_layout_indicator_fields(self, tmpdir):
        """
        Given:
        - Schema path of the layouts-container.

        When:
        - Wanting to retrieve all indicator dynamic fields in the schema.

        Then:
        - Ensure indicator dynamic fields are returned.
        """
        layout_converter = LayoutSixConverter(Pack(tmpdir))
        dynamic_fields = set(layout_converter.get_layout_indicator_fields())
        assert dynamic_fields == {'indicatorsDetails', 'indicatorsQuickView'}
    def test_entity_separators_to_underscore(self, tmpdir, name: str,
                                             expected: str):
        """
        Given:
        - string, possibly containing one of the chars in 'ENTITY_NAME_SEPARATORS'.

        When:
        - Wanting to transform every char in 'ENTITY_NAME_SEPARATORS' to '_'.

        Then:
        - Ensure expected string is returned.
        """
        layout_converter = LayoutSixConverter(Pack(tmpdir))
        assert layout_converter.entity_separators_to_underscore(
            name) == expected
Esempio n. 5
0
    def test_calculate_new_layout_relative_path(self, tmpdir, layout_id: str, expected_suffix: str):
        """
        Given:
        - 'layout_id': Layout ID of the new layout created.

        When:
        - Calculating the path to the newly created layout.

        Then:
        - Ensure the expected path is returned.

        """
        layout_converter = LayoutSixConverter(Pack(tmpdir))
        expected = f'{layout_converter.pack.path}/Layouts/{expected_suffix}'
        assert layout_converter.calculate_new_layout_relative_path(layout_id) == expected
Esempio n. 6
0
    def test_calculate_new_layout_group(self, tmpdir, old_layout_path: str, expected: str):
        """
        Given:
        - 'old_layouts': List of old layout objects.

        When:
        - Calculating the group field value for the layout above 6.0.0 version to be created.

        Then:
        - Ensure the expected group value is returned.
        """
        fake_pack_name = 'FakeTestPack'
        repo = Repo(tmpdir)
        repo_path = Path(repo.path)
        fake_pack = MockPack(repo_path / 'Packs', fake_pack_name, repo)
        fake_pack.create_layout('test', util_load_json(old_layout_path))
        fake_pack_path = fake_pack.path
        layout_converter = LayoutSixConverter(Pack(fake_pack_path))
        assert layout_converter.calculate_new_layout_group(
            [layout for layout in layout_converter.pack.layouts]) == expected
 def convert(self) -> int:
     if self.server_version >= self.VERSION_6_0_0:
         layout_converter: LayoutBaseConverter = LayoutSixConverter(
             self.pack)
     else:
         layout_converter = LayoutBelowSixConverter(self.pack)
     convert_result = layout_converter.convert_dir()
     if not convert_result:
         click.secho(
             f'Converted Layouts successfully in pack: {str(self.pack.path)}',
             fg='green')
     return convert_result