Beispiel #1
0
    def test_tags_json(
            self,
            fixture_registry_url,
            fixture_repository,
            fixture_tags,
            capsys
    ):
        # compute expected json result from expected fixture_tags
        client = Client(fixture_registry_url, verbose=False)
        repository = Repository(client, fixture_repository)
        expected_json_result = {
            'result': [
                {
                    'tag': t,
                    'date': CommandHandler().date2str(
                        repository.image(t).get_date()
                    ),
                } for t in fixture_tags
            ],
        }

        with mock.patch(
            'sys.argv',
            ['dregcli', 'tags', fixture_registry_url, fixture_repository, '-j']
        ):
            console_main()
            out_json = tools.get_output_json(capsys)
            assert out_json and 'result' in expected_json_result \
                and all(t in expected_json_result['result']
                        for t in out_json['result'])
Beispiel #2
0
    def test_image_json(
        self,
        fixture_registry_url,
        fixture_repository,
        fixture_tags,
        capsys
    ):
        tag = 'latest'

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
                '-j',
            ]
        ):
            console_main()
            out_json = tools.get_output_json(capsys)
            assert out_json and isinstance(out_json, dict) and \
                list(out_json.keys()) == ['result'] and \
                list(out_json['result'].keys()) == ['digest'] and \
                tools.check_sha256(out_json['result']['digest'])

        # with manifest
        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
                '-j',
                '-m',
            ]
        ):
            console_main()
            out_json = tools.get_output_json(capsys)
            assert out_json and isinstance(out_json, dict) and \
                list(out_json.keys()) == ['result'] and \
                sorted(list(out_json['result'].keys())) \
                == ['digest', 'manifest'] and \
                tools.check_sha256(out_json['result']['digest'])
Beispiel #3
0
    def test_reps_json(self, fixture_registry_url, fixture_repository, capsys):
        expected_json = {'result': [fixture_repository]}

        with mock.patch(
            'sys.argv',
            ['dregcli', 'reps', fixture_registry_url, '-j']
        ):
            console_main()
            assert tools.get_output_json(capsys) == expected_json
Beispiel #4
0
    def test_delete_no_option(self, fixture_registry_url, fixture_repository,
                              capsys):
        expected_msg = 'no option selected (criteria). delete aborted'
        handler = DeleteCommandHandler()

        expected_output_json = {'error': expected_msg}
        handler.run(fixture_registry_url,
                    fixture_repository,
                    True,
                    dry_run=True)
        assert tools.get_output_json(capsys) == expected_output_json

        expected_output_lines = [self._command, expected_msg]
        handler.run(fixture_registry_url,
                    fixture_repository,
                    False,
                    dry_run=True)
        out_lines = tools.get_output_lines(capsys)
        assert out_lines == expected_output_lines
    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']])
Beispiel #6
0
    def test_delete_exclusive_options(self, fixture_registry_url,
                                      fixture_repository, capsys):
        expected_msg = '--all, --from_count, --from_date, --include, ' \
                       '--exclude are exclusives. --delete aborted'
        handler = DeleteCommandHandler()

        expected_output_json = {'error': expected_msg}
        handler.run(fixture_registry_url,
                    fixture_repository,
                    True,
                    all=True,
                    from_count=10)  # 2 exclusives filter options
        assert tools.get_output_json(capsys) == expected_output_json

        expected_output_lines = [self._command, expected_msg]
        handler.run(fixture_registry_url,
                    fixture_repository,
                    False,
                    all=True,
                    from_count=10)  # 2 exclusives filter options
        out_lines = tools.get_output_lines(capsys)
        assert out_lines == expected_output_lines
Beispiel #7
0
    def test_images_json(
            self,
            fixture_registry_url,
            fixture_repository,
            fixture_tags,
            capsys
    ):
        # compute expected json result from expected fixture_tags
        client = Client(fixture_registry_url, verbose=False)
        repository = Repository(client, fixture_repository)

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'images',
                fixture_registry_url, fixture_repository,
                '-j'
            ]
        ):
            console_main()
            out_json = tools.get_output_json(capsys)

            # 1388 commit and latest should be in same layer
            # 1385 1386 and 1387 should each on separate layer

            for result_item in out_json['result']:
                tags = result_item['tags']
                tags_count = len(tags)

                assert tags_count in (1, 2)
                for t in tags:
                    pipeline_ref = t.split('-')[-1]
                    if tags_count == 1:
                        assert pipeline_ref in ('1385', '1386', '1387')
                    else:
                        assert pipeline_ref in ('latest', '1388')
Beispiel #8
0
 def test_get_output_json_no_output(self, capsys):
     assert tools.get_output_json(capsys) is None
Beispiel #9
0
 def test_get_output_json(self, capsys):
     expected_json = {"message": "hello world"}
     print(json.dumps(expected_json))
     assert tools.get_output_json(capsys) == expected_json
Beispiel #10
0
    def test_image_delete_json(
        self,
        fixture_registry_url,
        fixture_repository,
        fixture_tags,
        fixture_client,
        capsys
    ):
        tag = 'master-b2a7d05ca36cdd3e8eb092f857580b3ed0f7159a-1386'

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
                '-d',
                '-y',
                '-j',
            ]
        ):
            console_main()
            out_json = tools.get_output_json(capsys)
            assert out_json and isinstance(out_json, dict) and \
                list(out_json.keys()) == ['result'] and \
                sorted(list(out_json['result'].keys())) == [
                    'digest', 'message'] and \
                tools.check_sha256(out_json['result']['digest']) and \
                out_json['result']['message'] == 'deleted'

            # after delete, same image action should 404 (no more manifest)
            with mock.patch(
                'sys.argv',
                [
                    'dregcli',
                    'image',
                    fixture_registry_url,
                    fixture_repository,
                    tag,
                    '-d',
                    '-y',
                    '-j',
                ]
            ):
                msg404 = tools.get_error_status_message(404)
                expected_json = {'error': msg404}

                console_main()
                assert tools.get_output_json(capsys) == expected_json

            # extrapolated tags left
            # deleted in test_image_delete()
            fixture_tags.remove(
                'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385')
            # deleted here
            fixture_tags.remove(
                'master-b2a7d05ca36cdd3e8eb092f857580b3ed0f7159a-1386')
            repo = self.get_repo(fixture_client)
            assert sorted(repo.tags()) == sorted(fixture_tags)

            # after delete, repo should still be here in catalog
            assert repo.name == fixture_repository