コード例 #1
0
ファイル: test_cli.py プロジェクト: pbabinca/dockpulp
    def test_do_clone(self, mocked_pulp, args, lib, img, manifest, noprefix):
        bopts = testbOpts()
        p = testPulp()
        mocked_pulp.side_effect = [p]
        if img:
            images = {'1': '1'}
        else:
            images = {}
        if manifest:
            manifests = {'2': '2'}
        else:
            manifests = {}

        oldinfo = [{'redirect': None, 'description': None, 'title': None,
                    'protected': "False", "images": images, "manifests": manifests}]
        args = args.split(" ")
        bargs = args[:]
        if lib:
            bargs.append('-l')
        if noprefix:
            bargs.append('--noprefix')
        if lib and len(args) != 2:
            with pytest.raises(SystemExit):
                cli.do_clone(bopts, bargs)
        elif not lib and len(args) != 3:
            with pytest.raises(SystemExit):
                cli.do_clone(bopts, bargs)
        else:
            if lib:
                if noprefix:
                    repoid = '%s' % args[1]
                else:
                    repoid = 'redhat-%s' % args[1]
                productid = None
            else:
                if noprefix:
                    repoid = '%s-%s' % (args[1], args[2])
                else:
                    repoid = 'redhat-%s-%s' % (args[1], args[2])
                productid = args[1]
            if noprefix:
                prefix_with = ''
            else:
                prefix_with = 'redhat-'
            tags = {'tag': '1:1'}
            flexmock(testPulp)
            if not noprefix:
                (testPulp
                    .should_receive('getPrefix')
                    .once()
                    .and_return('redhat-'))
            (testPulp
                .should_receive('listRepos')
                .once()
                .with_args(args[0], content=True, paginate=True)
                .and_return(oldinfo))
            (testPulp
                .should_receive('createRepo')
                .once()
                .with_args(repoid, None, desc=None, title=None, protected=False,
                           productline=productid, distribution=None, prefix_with=prefix_with)
                .and_return(None))
            if img:
                (testPulp
                    .should_receive('copy')
                    .once()
                    .with_args(repoid, '1')
                    .and_return(None))
                (testPulp
                    .should_receive('updateRepo')
                    .once()
                    .with_args(repoid, tags)
                    .and_return(None))
            if manifest:
                (testPulp
                    .should_receive('copy')
                    .once()
                    .with_args(repoid, '2')
                    .and_return(None))
            assert cli.do_clone(bopts, bargs) is None
コード例 #2
0
ファイル: test_cli.py プロジェクト: rohanpm/dockpulp
    def test_do_clone(self, args, lib, img, manifest, noprefix):
        bopts = testbOpts()
        p = testPulp()
        if img:
            images = {'1': '1'}
        else:
            images = {}
        if manifest:
            manifests = {'2': '2'}
        else:
            manifests = {}

        oldinfo = [{
            'redirect': None,
            'description': None,
            'title': None,
            'protected': "False",
            "images": images,
            "manifests": manifests
        }]
        (flexmock(Pulp).new_instances(p).once().with_args(
            Pulp, env=bopts.server, config_file=bopts.config_file))
        args = args.split(" ")
        bargs = args[:]
        if lib:
            bargs.append('-l')
        if noprefix:
            bargs.append('--noprefix')
        if lib and len(args) != 2:
            with pytest.raises(SystemExit):
                cli.do_clone(bopts, bargs)
        elif not lib and len(args) != 3:
            with pytest.raises(SystemExit):
                cli.do_clone(bopts, bargs)
        else:
            if lib:
                if noprefix:
                    repoid = '%s' % args[1]
                else:
                    repoid = 'redhat-%s' % args[1]
                productid = None
            else:
                if noprefix:
                    repoid = '%s-%s' % (args[1], args[2])
                else:
                    repoid = 'redhat-%s-%s' % (args[1], args[2])
                productid = args[1]
            if noprefix:
                prefix_with = ''
            else:
                prefix_with = 'redhat-'
            tags = {'tag': '1:1'}
            flexmock(testPulp)
            if not noprefix:
                (testPulp.should_receive('getPrefix').once().and_return(
                    'redhat-'))
            (testPulp.should_receive('listRepos').once().with_args(
                args[0], content=True).and_return(oldinfo))
            (testPulp.should_receive('createRepo').once().with_args(
                repoid,
                None,
                desc=None,
                title=None,
                protected=False,
                productline=productid,
                sig=None,
                distribution=None,
                prefix_with=prefix_with).and_return(None))
            if img:
                (testPulp.should_receive('copy').once().with_args(
                    repoid, '1').and_return(None))
                (testPulp.should_receive('updateRepo').once().with_args(
                    repoid, tags).and_return(None))
            if manifest:
                (testPulp.should_receive('copy').once().with_args(
                    repoid, '2').and_return(None))
            assert cli.do_clone(bopts, bargs) is None