def test_sanity(self):
        """
        Given
            two changes in foreign content types

        When
            two pack versions that modified different items.

        Then
            type sections appears one after the other
        """
        release_notes_paths = [
            os.path.join(TEST_DATA_PATH, 'FakePack1', 'ReleaseNotes',
                         '1_1_0.md'),
            os.path.join(TEST_DATA_PATH, 'FakePack1', 'ReleaseNotes',
                         '2_1_0.md'),
        ]

        pack_versions_dict = {}
        for path in release_notes_paths:
            with open(path) as file_:
                pack_versions_dict[os.path.basename(
                    os.path.splitext(path)[0])] = file_.read()

        rn_block = merge_version_blocks('FakePack', pack_versions_dict, {})

        assert 'FakePack1_Playbook1' in rn_block
        assert 'FakePack1_Playbook2' in rn_block
        assert 'FakePack1_Integration1' in rn_block
        assert 'FakePack1_Integration2' in rn_block
        assert 'v2_1_0' in rn_block
        assert 'v1_1_0' not in rn_block
Exemplo n.º 2
0
    def test_spaced_content_entity_and_old_format(self):
        """
        Given
        - Two release notes files with content entity instance wrapped with ** and entity type contains spaces.
        When
        - Merging the two release notes files into one file.
        Then
        - Ensure that the content entity instance is wrapped with **.
        - Ensure that the content entity type contains whitespace.
        - Ensure that the content of both RN files appears in the result file.
        """
        release_notes_paths = [
            os.path.join(TEST_DATA_PATH, 'FakePack6', 'ReleaseNotes',
                         '1_0_1.md'),
            os.path.join(TEST_DATA_PATH, 'FakePack6', 'ReleaseNotes',
                         '1_0_2.md'),
        ]

        pack_versions_dict = {}
        for path in release_notes_paths:
            with open(path) as file_:
                pack_versions_dict[get_pack_version_from_path(
                    path)] = file_.read()

        rn_block, latest_version = merge_version_blocks(pack_versions_dict)

        assert 'Incident Fields' in rn_block
        assert '**XDR Alerts**' in rn_block
        assert 'First' in rn_block
        assert 'Second' in rn_block
        assert latest_version == '1.0.2'
    def test_similiar_entities(self):
        """
        Given
            two changes in similar content entities

        When
            two pack versions that modified the same items.

        Then
            one integration section appears
            one entity title for each one with two comments
        """
        release_notes_paths = [
            os.path.join(TEST_DATA_PATH, 'FakePack1', 'ReleaseNotes', '1_1_0.md'),
            os.path.join(TEST_DATA_PATH, 'FakePack1', 'ReleaseNotes', '2_0_0.md'),
        ]

        pack_versions_dict = {}
        for path in release_notes_paths:
            with open(path) as file_:
                pack_versions_dict[os.path.basename(os.path.splitext(path)[0])] = file_.read()

        rn_block = merge_version_blocks('FakePack', pack_versions_dict)

        assert rn_block.count('Integrations') == 1
        assert rn_block.count('FakePack1_Integration1') == 1
        assert rn_block.count('FakePack1_Integration2') == 1
        assert 'v2_0_0' in rn_block
        assert 'v1_1_0' not in rn_block
        assert 'fake1 minor' in rn_block
        assert 'fake2 minor' in rn_block
        assert 'fake1 major' in rn_block
        assert 'fake2 major' in rn_block
Exemplo n.º 4
0
    def test_merge_rns_with_gerneral_announcment(self, Pack_name, versions_ls,
                                                 expected_version):
        """
            Given:
                - Case 1: two consecutive versions of RN, both containing scripts with changes announcments,
                One of them contain entity with description and one of them contain entity with an empty description.
                One RN also contain integration changes announcments and the other contain entity with description.
                - Case 2: two consecutive versions of RN, one contain a script with changes announcments and two entities
                listed in this announcments and one of them contain a script with an entity with description.
            When:
                - Using merge_version_blocks function.
            Then:
                Ensure that the merge was done correctly.
                - Case 1: Should create a merged RN with anouncments as the top descrition of each category, two categories with
                one entity with descrition each. The other entity with the empty description should be omitted.
                - Case 2: Should create a merged RN with the anouncment at the top of the category
                including the two related entities, and under entity with descrition under the anouncment.
        """
        release_notes_paths = [
            os.path.join(TEST_DATA_PATH, Pack_name, 'ReleaseNotes', ver)
            for ver in versions_ls
        ]
        expected_results_paths = os.path.join(TEST_DATA_PATH, Pack_name,
                                              'expected_results.md')

        pack_versions_dict = {}
        for path in release_notes_paths:
            with open(path) as file:
                pack_versions_dict[get_pack_version_from_path(
                    path)] = file.read()

            with open(expected_results_paths) as file:
                expected_results = file.read()

        rn_block, latest_version = merge_version_blocks(pack_versions_dict)
        assert latest_version == expected_version
        assert rn_block == expected_results