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_incident_type('ExtraHop_Detection', util_load_json(self.INCIDENT_TYPE_ONE)) fake_pack.create_layoutcontainer('ExtraHop Detection', util_load_json(self.LAYOUT_CONTAINER)) fake_pack_path = fake_pack.path layout_converter = LayoutBelowSixConverter(Pack(fake_pack_path)) layout_converter.convert_dir() test_data_json = util_load_json( os.path.join( __file__, f'{git_path()}/demisto_sdk/commands/convert/converters/layout/' 'tests/test_data' '/layout_up_to_5_9_9_expected_convert_dir_test_file_output.json' )) for layout_field_name, layout_data in test_data_json.items(): expected_new_layout_path = f'{str(layout_converter.pack.path)}/Layouts/layout-{layout_field_name}-' \ 'ExtraHop_Detection.json' assert os.path.exists(expected_new_layout_path) assert util_load_json(expected_new_layout_path) == layout_data os.remove(expected_new_layout_path)
def test_get_layouts_by_layout_container_type(self, tmpdir): """ Given: - Layout container FileType. When: - Wanting to retrieve all layout-containers from the current pack. Then: - Ensure only layout-containers in the pack are 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_layoutcontainer('ExtraHop Detection', util_load_json(self.LAYOUT_CONTAINER)) fake_pack_path = fake_pack.path layouts = BaseConverter.get_entities_by_entity_type( Pack(fake_pack_path).layouts, FileType.LAYOUTS_CONTAINER) assert all(layout.type() == FileType.LAYOUTS_CONTAINER for layout in layouts) assert [layout.layout_id() for layout in layouts] == ['ExtraHop Detection']