Beispiel #1
0
    def test_display(self, fixture_registry_url, capsys):
        client = Client(fixture_registry_url, verbose=True)
        client.display("hello", "world")
        out_lines = tools.get_output_lines(capsys)
        assert out_lines == ["hello world"]

        client = Client(fixture_registry_url, verbose=False)
        client.display("hello")
        out_lines = tools.get_output_lines(capsys)
        assert out_lines == []
Beispiel #2
0
    def test_tags(
        self,
        fixture_registry_url,
        fixture_repository,
        fixture_tags,
        capsys
    ):
        # compute expected console result from expected fixture_tags
        client = Client(fixture_registry_url, verbose=False)
        repository = Repository(client, fixture_repository)
        expected_tags_lines = tabulate([
            [t, CommandHandler().date2str(repository.image(t).get_date())]
            for t in fixture_tags
        ], headers=['Tag', 'Date']).split("\n")

        with mock.patch(
            'sys.argv',
            ['dregcli', 'tags', fixture_registry_url, fixture_repository]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            assert out_lines[0] == 'tags'
            # tag lines result: last tags count ouput lines
            output_tags = out_lines[len(expected_tags_lines) * -1:]
            assert all([ot in expected_tags_lines for ot in output_tags])
Beispiel #3
0
    def test_reps_user(self, fixture_registry_url, fixture_repository, capsys):
        expected_out = [
            'reps',
            "login as user 'login'",
        ]

        with mock.patch(
            'sys.argv',
            ['dregcli', '-u', 'login:pwd', 'reps', fixture_registry_url]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            # we should have "registry: as user 'login'" at 2nd line
            assert out_lines[:2] == expected_out
Beispiel #4
0
    def test_reps(self, fixture_registry_url, fixture_repository, capsys):
        expected_out = [
            'reps',
            'GET {url}/v2/_catalog'.format(url=fixture_registry_url),
            fixture_repository,
        ]

        with mock.patch(
            'sys.argv',
            ['dregcli', 'reps', fixture_registry_url]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            assert out_lines == expected_out
Beispiel #5
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
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_get_output_lines_no_output(self, capsys):
     assert tools.get_output_lines(capsys) == []
Beispiel #8
0
 def test_get_output_lines(self, capsys):
     expected_output = "hello world"
     print(expected_output)
     assert tools.get_output_lines(capsys) == [expected_output]
Beispiel #9
0
    def test_image_delete(
        self,
        fixture_registry_url,
        fixture_repository,
        fixture_tags,
        fixture_client,
        capsys
    ):
        tag = 'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385'

        expected_out = [
            'image',
            'GET {url}/v2/{repo}/manifests/{tag}'.format(
                url=fixture_registry_url,
                repo=fixture_repository,
                tag=tag
            ),

        ]
        expected_delete_prefix = \
            'DELETE {url}/v2/{repo}/manifests/'.format(
                url=fixture_registry_url,
                repo=fixture_repository
            )

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
                '-d',
                '-y'
            ]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            # 5 lines: command, get image request, delete request,
            #          then digest and 'deleted' message
            delete_digest = out_lines[2][len(expected_delete_prefix):]
            digest = out_lines[3]
            assert len(out_lines) == 5 and \
                out_lines[:2] == expected_out and \
                out_lines[2].startswith(expected_delete_prefix) and \
                tools.check_sha256(delete_digest) and \
                tools.check_sha256(digest) and \
                out_lines[4] == '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'
                ]
            ):
                expected_out_404 = expected_out.copy()
                expected_out_404.append(tools.get_error_status_message(404))

                console_main()
                assert tools.get_output_lines(capsys) == expected_out_404

            fixture_tags.remove(
                'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385')
            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
Beispiel #10
0
    def test_image(
        self,
        fixture_registry_url,
        fixture_repository,
        fixture_tags,
        capsys
    ):
        tag = 'latest'

        expected_out = [
            'image',
            'GET {url}/v2/{repo}/manifests/{tag}'.format(
                url=fixture_registry_url,
                repo=fixture_repository,
                tag=tag
            ),
        ]

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
            ]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            # 3 lines, command, request and digest
            assert len(out_lines) == 3 and \
                out_lines[:2] == expected_out and \
                tools.check_sha256(out_lines[2])

        # with manifest
        expected_out = [
            'image',
            'GET {url}/v2/{repo}/manifests/{tag}'.format(
                url=fixture_registry_url,
                repo=fixture_repository,
                tag=tag
            ),
        ]

        with mock.patch(
            'sys.argv',
            [
                'dregcli',
                'image',
                fixture_registry_url,
                fixture_repository,
                tag,
                '-m'
            ]
        ):
            console_main()
            out_lines = tools.get_output_lines(capsys)
            # as we ask for manifest, we have more than 3 out_lines
            assert len(out_lines) > 3 and \
                out_lines[:2] == expected_out and \
                tools.check_sha256(out_lines[2])