def test_include_single_tag(self, fixture_registry_url, fixture_client,
                                fixture_repository, fixture_delete_tags,
                                fixture_delete_tags_with_no_old, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        include = r"1382$"
        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              include=include,
                              single_tag='^master-')

        # 'commit tags' to be removed
        # 1382 as no other release tag + included
        commit_tag_only_tags_deleted = [
            'master-2ze98e000wx39d60a7390925d0czr3qs03j90aaa-1382',
        ]

        # check commit_tags_only tags deleted
        assert sorted(deleted) == sorted(commit_tag_only_tags_deleted)

        # check repo should have over tags than commit_tags_only left now
        should_left_tags = [
            t for t in fixture_delete_tags
            if t not in commit_tag_only_tags_deleted
        ]
        assert sorted(repo.tags()) == sorted(should_left_tags)
Esempio n. 2
0
    def test_from_count(self, fixture_registry_url, fixture_client,
                        fixture_repository, fixture_delete_tags, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        # tags by date desc (and their name should match fixtures)
        expected_tags_by_desc_date = [
            tag_data['tag'] for tag_data in repo.get_tags_by_date()
        ]
        assert sorted(expected_tags_by_desc_date) == \
            sorted(fixture_delete_tags)

        # remove from staging/master-*-1388, see fixture_delete_tags docstring
        from_count = 3
        should_left = [
            'latest',
            # prod layer
            'master-b2a7d05ca36cdd3e8eb092f857580b3ed0f7159a-1386',
            'prod',
        ]

        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              from_count=from_count)

        # check delete from 3rd
        should_deleted = [tag for tag in repo_tags if tag not in should_left]
        assert sorted(deleted) == sorted(should_deleted)

        # check repo should have head of no deleted ones
        assert sorted(repo.tags()) == sorted(should_left)
    def test_from_date_single_tag(
        self,
        fixture_registry_url,
        fixture_client,
        fixture_repository,
        fixture_delete_tags,
        capsys
    ):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        # tags by date desc (and their name should match fixtures)
        tags_by_date_desc = repo.get_tags_by_date()
        expected_tags_by_desc_date = [
            tag_data['tag'] for tag_data in tags_by_date_desc
        ]
        assert sorted(expected_tags_by_desc_date) == \
            sorted(fixture_delete_tags)

        # delete from index desc order
        # delete from 'alpha'/master-*-1383 in desc order
        # see docstring of fixture_delete_tags
        from_date = '2019-01-30 22:20:20'

        handler = DeleteCommandHandler()
        deleted = handler.run(
            fixture_registry_url,
            fixture_repository,
            False,
            from_date=from_date,
            single_tag='^master-'
        )

        # 'commit tags' to be removed and left
        # (no other release tags like 'staging' on them)
        commit_tag_only_tags_deleted = [
            'master-2ze98e000wx39d60a7390925d0czr3qs03j90aaa-1382',
        ]

        # check commit_tags_only tags deleted
        assert sorted(deleted) == sorted(commit_tag_only_tags_deleted)

        # check repo should have over tags than commit_tags_only left now
        should_left_tags = [
            t for t in fixture_delete_tags
            if t not in commit_tag_only_tags_deleted
        ]
        assert sorted(repo.tags()) == sorted(should_left_tags)
Esempio n. 4
0
    def test_all_single_tag(
        self,
        fixture_registry_url,
        fixture_client,
        fixture_repository,
        fixture_delete_tags,
        capsys
    ):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        # tags by date desc (and their name should match fixtures)
        tags_by_desc_date = repo.get_tags_by_date()
        expected_tag_names_by_desc_date = [
            tag_data['tag'] for tag_data in tags_by_desc_date
        ]
        assert sorted(expected_tag_names_by_desc_date) == \
            sorted(fixture_delete_tags)

        handler = DeleteCommandHandler()
        deleted = handler.run(
            fixture_registry_url,
            fixture_repository,
            False,
            all=True,
            single_tag='^master-'
        )

        # 'commit tags' to be removed
        # (no other release tags like 'staging' on them)
        commit_tag_only_tags = [
            'master-2ze98e000wx39d60a7390925d0czr3qs03j90aaa-1382',
            'master-2bd32d000ez93c50h8486935f0fda5ee09z98bbb-1384',
        ]

        # check commit_tags_only tags deleted
        assert sorted(deleted) == sorted(commit_tag_only_tags)

        # check repo should have over tags than commit_tags_only left now
        should_left_tags = [
            t for t in fixture_delete_tags if t not in commit_tag_only_tags
        ]
        assert sorted(repo.tags()) == sorted(should_left_tags)
Esempio n. 5
0
    def test_all(self, fixture_registry_url, fixture_client,
                 fixture_repository, fixture_delete_tags, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              all=True)

        # check output: all tags deleted output
        assert sorted(deleted) == sorted(fixture_delete_tags)

        # check should have no tag anymore left for repo
        assert repo.tags() == []
Esempio n. 6
0
    def test_from_date(self, fixture_registry_url, fixture_client,
                       fixture_repository, fixture_delete_tags, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        # tags by date desc (and their name should match fixtures)
        tags_by_desc_date = repo.get_tags_by_date()
        expected_tag_names_by_desc_date = [
            tag_data['tag'] for tag_data in tags_by_desc_date
        ]
        assert sorted(expected_tag_names_by_desc_date) == \
            sorted(fixture_delete_tags)

        # index to test from
        from_index = 3
        from_date = tags_by_desc_date[from_index]['date']
        from_data_str = from_date.strftime('%Y-%m-%d %H:%M:%S.%f')

        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              from_date=from_data_str)

        # get expected remove from index (from date)
        expected_from_index = -1
        index = 0
        for tag_data in tags_by_desc_date:
            if tag_data['date'] == from_date:
                expected_from_index = index
                break
            index += 1
        assert expected_from_index >= 0  # base condition of below contracts

        # check delete from 3rd
        assert deleted == expected_tag_names_by_desc_date[expected_from_index:]

        # check should have left of no deleted ones
        assert sorted(repo.tags()) == \
            sorted(expected_tag_names_by_desc_date[:expected_from_index])
Esempio n. 7
0
    def test_dry_run(self, fixture_registry_url, fixture_client,
                     fixture_repository, fixture_delete_tags, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              all=True,
                              dry_run=True)

        # check output: all tags deleted output
        assert sorted(deleted) == sorted(fixture_delete_tags)

        # check should have all tags left here versus no tag anymore
        # due to dry run mode
        assert sorted(repo_tags) == sorted(fixture_delete_tags)
    def test_all_cotags(self, fixture_registry_url, fixture_client,
                        fixture_repository, fixture_delete_tags,
                        fixture_delete_tags_cotags_mapping, capsys):
        """delete: cotags report in json"""
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        handler = DeleteCommandHandler()
        deleted = handler.run(
            fixture_registry_url,
            fixture_repository,
            True,  # json output
            all=True)

        output_json = tools.get_output_json(capsys)
        assert 'result' in output_json
        # check mapping: we should match each tag cotags
        for json_result_entry in output_json['result']:
            assert sorted(json_result_entry['cotags']) == sorted(
                fixture_delete_tags_cotags_mapping[json_result_entry['tag']])
Esempio n. 9
0
    def test_exclude(self, fixture_registry_url, fixture_client,
                     fixture_repository, fixture_delete_tags, capsys):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        isolated_tag = 'latest'
        exclude = r"^{tag}".format(tag=isolated_tag)
        handler = DeleteCommandHandler()
        deleted = handler.run(fixture_registry_url,
                              fixture_repository,
                              False,
                              exclude=exclude)

        # check output: others than isolated_tag deleted
        expected_tags_left = fixture_delete_tags.copy()
        expected_tags_left.remove(isolated_tag)
        assert sorted(deleted) == sorted(expected_tags_left)

        # check should have isolated_tag left (by exclusion)
        assert repo.tags() == [isolated_tag]
    def test_exclude_single_tag(
        self,
        fixture_registry_url,
        fixture_client,
        fixture_repository,
        fixture_delete_tags,
        capsys
    ):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        exclude = '1382$'
        handler = DeleteCommandHandler()
        deleted = handler.run(
            fixture_registry_url,
            fixture_repository,
            False,
            exclude=exclude,
            single_tag='^master-'
        )

        # 1384 to be removed: only 1382 and 1384 have no release tag
        # and 1382 is excluded
        commit_tag_only_tags_deleted = [
            'master-2bd32d000ez93c50h8486935f0fda5ee09z98bbb-1384',
        ]

        # check commit_tags_only tags deleted
        assert sorted(deleted) == sorted(commit_tag_only_tags_deleted)

        # check repo should have over tags than commit_tags_only left now
        should_left_tags = [
            t for t in fixture_delete_tags
            if t not in commit_tag_only_tags_deleted
        ]
        assert sorted(repo.tags()) == sorted(should_left_tags)
Esempio n. 11
0
    def test_include(
        self,
        fixture_registry_url,
        fixture_client,
        fixture_repository,
        fixture_delete_tags,
        fixture_delete_tags_old_only,
        fixture_delete_tags_with_no_old,
        capsys
    ):
        # check data set adhoc state
        repo = fixture_client.repositories()[0]
        repo_tags = repo.tags()
        assert sorted(repo_tags) == sorted(fixture_delete_tags)

        include = r"^old"

        handler = DeleteCommandHandler()
        deleted = handler.run(
            fixture_registry_url,
            fixture_repository,
            False,
            include=include,
        )

        # 'commit tags' to be removed
        # (no other release tags like 'staging' on them)
        commit_tag_only_tags_deleted = [

        ]

        # check commit_tags_only tags deleted
        assert sorted(deleted) == sorted(fixture_delete_tags_old_only)

        # check repo should have over tags than commit_tags_only left now
        assert sorted(repo.tags()) == sorted(fixture_delete_tags_with_no_old)
Esempio n. 12
0
 def test_repositories(self, fixture_client, fixture_repository):
     repositories = fixture_client.repositories()
     assert isinstance(repositories, list) and \
         len(repositories) == 1 and \
         repositories[0].name == fixture_repository