def test_handle_add_pkg_multi_pkg(self, activate_session_mock, stdout):
        tag = 'tag'
        dsttag = {'name': tag, 'id': 1}
        packages = ['package1', 'package2', 'package3']
        owner = 'owner'
        owner_info = mock.ANY
        extra_arches = 'arch1,arch2 arch3, arch4'
        args = ['--owner=' + owner, '--extra-arches=' + extra_arches, tag
                ] + packages
        kwargs = {
            'force': None,
            'block': False,
            'extra_arches': 'arch1 arch2 arch3 arch4'
        }
        options = mock.MagicMock()

        # Mock out the xmlrpc server
        session = mock.MagicMock()

        session.getUser.return_value = owner_info
        session.getTag.return_value = dsttag
        session.listPackages.return_value = [{
            'package_name': 'package2',
            'package_id': 2
        }]
        # Run it and check immediate output
        # args: --owner, --extra-arches='arch1,arch2 arch3, arch4',
        #       tag, package1, package2, package3
        # expected: success
        rv = handle_add_pkg(options, session, args)
        actual = stdout.getvalue()
        expected = 'Package package2 already exists in tag tag\nAdding 2 packages to tag tag\n'
        self.assertMultiLineEqual(actual, expected)
        # Finally, assert that things were called as we expected.
        activate_session_mock.assert_called_once_with(session, options)
        self.assertEqual(session.mock_calls, [
            call.getUser(owner),
            call.getTag(tag),
            call.listPackages(tagID=dsttag['id']),
            call.packageListAdd(tag, packages[0], owner, **kwargs),
            call.packageListAdd(tag, packages[2], owner, **kwargs),
            call.multiCall(strict=True)
        ])
        self.assertNotEqual(rv, 1)
Ejemplo n.º 2
0
    def test_handle_clone_tag_existing_dsttag(self, stdout):
        args = ['src-tag', 'dst-tag', '--all', '-v']
        self.session.multiCall.return_value = []
        self.session.listPackages.side_effect = [[{'package_id': 1,
                                                   'package_name': 'pkg1',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag',
                                                   'extra_arches': None},
                                                  {'package_id': 2,
                                                   'package_name': 'pkg2',
                                                   'blocked': True,
                                                   'owner_name': 'userB',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch3 arch4'},
                                                  {'package_id': 3,
                                                   'package_name': 'apkg',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch4'}],
                                                 [{'package_id': 1,
                                                   'package_name': 'pkg1',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag',
                                                   'extra_arches': None},
                                                  {'package_id': 3,
                                                   'package_name': 'apkg',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch4'},
                                                  {'package_id': 4,
                                                   'package_name': 'bpkg',
                                                   'blocked': False,
                                                   'owner_name': 'userC',
                                                   'tag_name': 'src-tag',
                                                   'extra_arches': 'arch4'},
                                                  {'package_id': 5,
                                                   'package_name': 'cpkg',
                                                   'blocked': True,
                                                   'owner_name': 'userC',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch4'},
                                                  {'package_id': 6,
                                                   'package_name': 'dpkg',
                                                   'blocked': True,
                                                   'owner_name': 'userC',
                                                   'tag_name': 'src-tag',
                                                   'extra_arches': 'arch4'}
                                                  ]]
        self.session.listTagged.side_effect = [[{'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.1-2',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.0-2',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-0.1-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.0-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg2',
                                                 'nvr': 'pkg2-1.0-1',
                                                 'state': 2,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag-p'}
                                                ],
                                               [{'package_name': 'pkg1',
                                                 'nvr': 'pkg1-2.1-2',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'dst-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.0-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'dst-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-0.1-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'dst-tag'},
                                                {'package_name': 'pkg2',
                                                 'nvr': 'pkg2-1.0-1',
                                                 'state': 2,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'dst-tag'},
                                                {'package_name': 'pkg3',
                                                 'nvr': 'pkg3-1.0-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'dst-tag'}
                                                ]]
        self.session.getTagGroups.side_effect = [[{'name': 'group1',
                                                   'tag_id': 1,
                                                   'packagelist': [
                                                       {'package': 'pkg1',
                                                        'blocked': False},
                                                       {'package': 'pkg2',
                                                        'blocked': False},
                                                       {'package': 'pkg3',
                                                        'blocked': False},
                                                       {'package': 'pkg4',
                                                        'blocked': False}
                                                   ]},
                                                  {'name': 'group2',
                                                   'tag_id': 1,
                                                   'packagelist': [
                                                       {'package': 'apkg',
                                                        'blocked': False},
                                                       {'package': 'bpkg',
                                                        'blocked': False}]
                                                   }],
                                                 [{'name': 'group1',
                                                   'tag_id': 2,
                                                   'packagelist': [
                                                       {'package': 'pkg1',
                                                        'blocked': False},
                                                       {'package': 'pkg5',
                                                        'blocked': False}
                                                   ]},
                                                  {'name': 'group2',
                                                   'tag_id': 3,
                                                   'packagelist': [
                                                       {'package': 'apkg',
                                                        'blocked': False},
                                                       {'package': 'cpkg',
                                                        'blocked': False}]},
                                                  {'name': 'group3',
                                                   'tag_id': 2,
                                                   'packagelist': [
                                                       {'package': 'cpkg',
                                                        'blocked': False},
                                                       {'package': 'dpkg',
                                                        'blocked': False}]},
                                                  {'name': 'group4',
                                                   'tag_id': 3,
                                                   'packagelist': [
                                                       {'package': 'epkg',
                                                        'blocked': False},
                                                       {'package': 'fpkg',
                                                        'blocked': False}]}
                                                  ]]
        self.session.getTag.side_effect = [{'id': 1,
                                            'name': 'src-tag',
                                            'arches': 'arch1 arch2',
                                            'perm_id': 1,
                                            'maven_support': False,
                                            'maven_include_all': True,
                                            'locked': False},
                                           {'id': 2,
                                            'name': 'dst-tag',
                                            'arches': 'arch1 arch2',
                                            'perm_id': 1,
                                            'maven_support': False,
                                            'maven_include_all': True,
                                            'locked': False}]
        handle_clone_tag(self.options, self.session, args)
        self.activate_session.assert_called_once()
        self.session.assert_has_calls([call.hasPerm('admin'),
                                       call.getTag('src-tag'),
                                       call.getTag('dst-tag'),
                                       call.listPackages(event=None,
                                                         inherited=True,
                                                         tagID=1),
                                       call.listPackages(inherited=True,
                                                         tagID=2),
                                       call.listTagged(1, event=None,
                                                       inherit=None,
                                                       latest=None),
                                       call.listTagged(2, inherit=False,
                                                       latest=False),
                                       call.getTagGroups('src-tag',
                                                         event=None),
                                       call.getTagGroups('dst-tag'),
                                       call.packageListAdd('dst-tag', 'pkg2',
                                                           block=True,
                                                           extra_arches='arch3 arch4',
                                                           owner='userB'),
                                       call.multiCall(batch=1000),
                                       call.untagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-2.1-2',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'dst-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.untagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-0.1-1',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'dst-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.untagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg3-1.0-1',
                                           'package_name': 'pkg3', 'state': 1,
                                           'tag_name': 'dst-tag',
                                           'name': 'pkg3'}, force=None),
                                       call.multiCall(batch=1000),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-0.1-1',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-1.0-2',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-1.1-2',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.multiCall(batch=1000),
                                       call.multiCall(batch=1000),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group1',
                                                                'pkg2',
                                                                force=None),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group1',
                                                                'pkg3',
                                                                force=None),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group1',
                                                                'pkg4',
                                                                force=None),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group2',
                                                                'bpkg',
                                                                force=None),
                                       call.multiCall(batch=1000),
                                       call.multiCall(batch=1000),
                                       call.packageListBlock('dst-tag',
                                                             'bpkg'),
                                       call.packageListBlock('dst-tag',
                                                             'cpkg'),
                                       call.packageListBlock('dst-tag',
                                                             'dpkg'),
                                       call.multiCall(batch=1000),
                                       call.groupListRemove('dst-tag',
                                                            'group3',
                                                            force=None),
                                       call.groupListBlock('dst-tag',
                                                           'group4'),
                                       call.multiCall(batch=1000),
                                       call.groupPackageListRemove('dst-tag',
                                                                   'group1',
                                                                   'pkg5',
                                                                   force=None),
                                       call.groupPackageListBlock('dst-tag',
                                                                  'group2',
                                                                  'cpkg'),
                                       call.multiCall(batch=1000)])
        self.assert_console_message(stdout, """
List of changes:

    Action  Package                      Blocked    Owner      From Tag  
    ------- ---------------------------- ---------- ---------- ----------
    [add]   pkg2                         True       userB      src-tag-p 
    [blk]   bpkg                         False      userC      src-tag   
    [blk]   cpkg                         True       userC      src-tag-p 
    [blk]   dpkg                         True       userC      src-tag   

    Action  From/To Package              Build(s)                                 State      Owner      From Tag  
    ------- ---------------------------- ---------------------------------------- ---------- ---------- ----------
    [del]   pkg1                         pkg1-2.1-2                               COMPLETE   b_owner    dst-tag   
    [del]   pkg1                         pkg1-0.1-1                               COMPLETE   b_owner    dst-tag   
    [del]   pkg3                         pkg3-1.0-1                               COMPLETE   b_owner    dst-tag   
    [add]   pkg1                         pkg1-0.1-1                               COMPLETE   b_owner    src-tag   
    [add]   pkg1                         pkg1-1.0-2                               COMPLETE   b_owner    src-tag   
    [add]   pkg1                         pkg1-1.1-2                               COMPLETE   b_owner    src-tag   

    Action  Package                      Group                       
    ------- ---------------------------- ----------------------------
    [new]   pkg2                         group1                      
    [new]   pkg3                         group1                      
    [new]   pkg4                         group1                      
    [new]   bpkg                         group2                      
    [del]   cpkg                         group3                      
    [del]   dpkg                         group3                      
    [blk]   epkg                         group4                      
    [blk]   fpkg                         group4                      
    [del]   pkg5                         group1                      
    [blk]   cpkg                         group2                      
""")
Ejemplo n.º 3
0
    def test_handle_clone_tag_new_dsttag(self, stdout):
        args = ['src-tag', 'dst-tag', '--all', '-v']
        self.session.listPackages.return_value = [{'package_id': 1,
                                                   'package_name': 'pkg1',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag',
                                                   'extra_arches': None},
                                                  {'package_id': 2,
                                                   'package_name': 'pkg2',
                                                   'blocked': True,
                                                   'owner_name': 'userB',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch3 arch4'},
                                                  {'package_id': 3,
                                                   'package_name': 'apkg',
                                                   'blocked': False,
                                                   'owner_name': 'userA',
                                                   'tag_name': 'src-tag-p',
                                                   'extra_arches': 'arch4'}]
        self.session.listTagged.return_value = [{'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.1-2',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.0-2',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg1',
                                                 'nvr': 'pkg1-1.0-1',
                                                 'state': 1,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag'},
                                                {'package_name': 'pkg2',
                                                 'nvr': 'pkg2-1.0-1',
                                                 'state': 2,
                                                 'owner_name': 'b_owner',
                                                 'tag_name': 'src-tag-p'}
                                                ]
        self.session.getTagGroups.return_value = [{'name': 'group1',
                                                   'packagelist': [
                                                       {'package': 'pkg1',
                                                        'blocked': False},
                                                       {'package': 'pkg2',
                                                        'blocked': False}]},
                                                  {'name': 'group2',
                                                   'packagelist': [
                                                       {'package': 'apkg',
                                                        'blocked': False},
                                                       {'package': 'bpkg',
                                                        'blocked': False}]
                                                   }]
        self.session.getTag.side_effect = [{'id': 1,
                                            'name': 'src-tag',
                                            'arches': 'arch1 arch2',
                                            'perm_id': 1,
                                            'maven_support': False,
                                            'maven_include_all': True,
                                            'locked': False},
                                           None,
                                           {'id': 2,
                                            'name': 'dst-tag',
                                            'arches': 'arch1 arch2',
                                            'perm_id': 1,
                                            'maven_support': False,
                                            'maven_include_all': True,
                                            'locked': False}]
        handle_clone_tag(self.options, self.session, args)
        self.activate_session.assert_called_once()
        self.session.assert_has_calls([call.hasPerm('admin'),
                                       call.getTag('src-tag'),
                                       call.getTag('dst-tag'),
                                       call.createTag('dst-tag',
                                                      arches='arch1 arch2',
                                                      locked=False,
                                                      maven_include_all=True,
                                                      maven_support=False,
                                                      parent=None, perm=1),
                                       call.getTag('dst-tag', strict=True),
                                       call.listPackages(event=None,
                                                         inherited=True,
                                                         tagID=1),
                                       call.packageListAdd('dst-tag', 'apkg',
                                                           block=False,
                                                           extra_arches='arch4',
                                                           owner='userA'),
                                       call.packageListAdd('dst-tag', 'pkg1',
                                                           block=False,
                                                           extra_arches=None,
                                                           owner='userA'),
                                       call.packageListAdd('dst-tag', 'pkg2',
                                                           block=True,
                                                           extra_arches='arch3 arch4',
                                                           owner='userB'),
                                       call.multiCall(batch=1000),
                                       call.listTagged(1, event=None,
                                                       inherit=None,
                                                       latest=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg2-1.0-1',
                                           'package_name': 'pkg2', 'state': 2,
                                           'tag_name': 'src-tag-p',
                                           'name': 'pkg2'}, force=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-1.0-1',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-1.0-2',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.tagBuildBypass('dst-tag', {
                                           'owner_name': 'b_owner',
                                           'nvr': 'pkg1-1.1-2',
                                           'package_name': 'pkg1', 'state': 1,
                                           'tag_name': 'src-tag',
                                           'name': 'pkg1'}, force=None),
                                       call.multiCall(batch=1000),
                                       call.getTagGroups('src-tag',
                                                         event=None),
                                       call.groupListAdd('dst-tag', 'group1'),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group1',
                                                                'pkg1',
                                                                block=False),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group1',
                                                                'pkg2',
                                                                block=False),
                                       call.groupListAdd('dst-tag', 'group2'),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group2',
                                                                'apkg',
                                                                block=False),
                                       call.groupPackageListAdd('dst-tag',
                                                                'group2',
                                                                'bpkg',
                                                                block=False),
                                       call.multiCall(batch=1000)])
        self.assert_console_message(stdout, """
List of changes:

    Action  Package                      Blocked    Owner      From Tag  
    ------- ---------------------------- ---------- ---------- ----------
    [new]   apkg                         False      userA      src-tag-p 
    [new]   pkg1                         False      userA      src-tag   
    [new]   pkg2                         True       userB      src-tag-p 

    Action  From/To Package              Build(s)                                 State      Owner      From Tag  
    ------- ---------------------------- ---------------------------------------- ---------- ---------- ----------
    [new]   pkg2                         pkg2-1.0-1                               DELETED    b_owner    src-tag-p 
    [new]   pkg1                         pkg1-1.0-1                               COMPLETE   b_owner    src-tag   
    [new]   pkg1                         pkg1-1.0-2                               COMPLETE   b_owner    src-tag   
    [new]   pkg1                         pkg1-1.1-2                               COMPLETE   b_owner    src-tag   

    Action  Package                      Group                       
    ------- ---------------------------- ----------------------------
    [new]   pkg1                         group1                      
    [new]   pkg2                         group1                      
    [new]   apkg                         group2                      
    [new]   bpkg                         group2                      
""")
Ejemplo n.º 4
0
    def test_handle_clone_tag_existing_dsttag(self, stdout):
        args = ['src-tag', 'dst-tag', '--all', '-v']
        self.session.multiCall.return_value = []
        self.session.listPackages.side_effect = [[{
            'package_id': 1,
            'package_name': 'pkg1',
            'blocked': False,
            'owner_name': 'userA',
            'tag_name': 'src-tag',
            'extra_arches': None
        }, {
            'package_id': 2,
            'package_name': 'pkg2',
            'blocked': True,
            'owner_name': 'userB',
            'tag_name': 'src-tag-p',
            'extra_arches': 'arch3 arch4'
        }, {
            'package_id': 3,
            'package_name': 'apkg',
            'blocked': False,
            'owner_name': 'userA',
            'tag_name': 'src-tag-p',
            'extra_arches': 'arch4'
        }],
                                                 [{
                                                     'package_id': 1,
                                                     'package_name': 'pkg1',
                                                     'blocked': False,
                                                     'owner_name': 'userA',
                                                     'tag_name': 'src-tag',
                                                     'extra_arches': None
                                                 }, {
                                                     'package_id': 3,
                                                     'package_name': 'apkg',
                                                     'blocked': False,
                                                     'owner_name': 'userA',
                                                     'tag_name': 'src-tag-p',
                                                     'extra_arches': 'arch4'
                                                 }, {
                                                     'package_id': 4,
                                                     'package_name': 'bpkg',
                                                     'blocked': False,
                                                     'owner_name': 'userC',
                                                     'tag_name': 'src-tag',
                                                     'extra_arches': 'arch4'
                                                 }, {
                                                     'package_id': 5,
                                                     'package_name': 'cpkg',
                                                     'blocked': True,
                                                     'owner_name': 'userC',
                                                     'tag_name': 'src-tag-p',
                                                     'extra_arches': 'arch4'
                                                 }, {
                                                     'package_id': 6,
                                                     'package_name': 'dpkg',
                                                     'blocked': True,
                                                     'owner_name': 'userC',
                                                     'tag_name': 'src-tag',
                                                     'extra_arches': 'arch4'
                                                 }]]
        self.session.listTagged.side_effect = [[{
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.1-2',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.0-2',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg1',
            'nvr': 'pkg1-0.1-1',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.0-1',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg2',
            'nvr': 'pkg2-1.0-1',
            'state': 2,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag-p'
        }],
                                               [{
                                                   'package_name': 'pkg1',
                                                   'nvr': 'pkg1-2.1-2',
                                                   'state': 1,
                                                   'owner_name': 'b_owner',
                                                   'tag_name': 'dst-tag'
                                               }, {
                                                   'package_name': 'pkg1',
                                                   'nvr': 'pkg1-1.0-1',
                                                   'state': 1,
                                                   'owner_name': 'b_owner',
                                                   'tag_name': 'dst-tag'
                                               }, {
                                                   'package_name': 'pkg1',
                                                   'nvr': 'pkg1-0.1-1',
                                                   'state': 1,
                                                   'owner_name': 'b_owner',
                                                   'tag_name': 'dst-tag'
                                               }, {
                                                   'package_name': 'pkg2',
                                                   'nvr': 'pkg2-1.0-1',
                                                   'state': 2,
                                                   'owner_name': 'b_owner',
                                                   'tag_name': 'dst-tag'
                                               }, {
                                                   'package_name': 'pkg3',
                                                   'nvr': 'pkg3-1.0-1',
                                                   'state': 1,
                                                   'owner_name': 'b_owner',
                                                   'tag_name': 'dst-tag'
                                               }]]
        self.session.getTagGroups.side_effect = [[{
            'name':
            'group1',
            'tag_id':
            1,
            'packagelist': [{
                'package': 'pkg1',
                'blocked': False
            }, {
                'package': 'pkg2',
                'blocked': False
            }, {
                'package': 'pkg3',
                'blocked': False
            }, {
                'package': 'pkg4',
                'blocked': False
            }]
        }, {
            'name':
            'group2',
            'tag_id':
            1,
            'packagelist': [{
                'package': 'apkg',
                'blocked': False
            }, {
                'package': 'bpkg',
                'blocked': False
            }]
        }],
                                                 [{
                                                     'name':
                                                     'group1',
                                                     'tag_id':
                                                     2,
                                                     'packagelist': [{
                                                         'package':
                                                         'pkg1',
                                                         'blocked':
                                                         False
                                                     }, {
                                                         'package':
                                                         'pkg5',
                                                         'blocked':
                                                         False
                                                     }]
                                                 }, {
                                                     'name':
                                                     'group2',
                                                     'tag_id':
                                                     3,
                                                     'packagelist': [{
                                                         'package':
                                                         'apkg',
                                                         'blocked':
                                                         False
                                                     }, {
                                                         'package':
                                                         'cpkg',
                                                         'blocked':
                                                         False
                                                     }]
                                                 }, {
                                                     'name':
                                                     'group3',
                                                     'tag_id':
                                                     2,
                                                     'packagelist': [{
                                                         'package':
                                                         'cpkg',
                                                         'blocked':
                                                         False
                                                     }, {
                                                         'package':
                                                         'dpkg',
                                                         'blocked':
                                                         False
                                                     }]
                                                 }, {
                                                     'name':
                                                     'group4',
                                                     'tag_id':
                                                     3,
                                                     'packagelist': [{
                                                         'package':
                                                         'epkg',
                                                         'blocked':
                                                         False
                                                     }, {
                                                         'package':
                                                         'fpkg',
                                                         'blocked':
                                                         False
                                                     }]
                                                 }]]
        self.session.getTag.side_effect = [{
            'id': 1,
            'name': 'src-tag',
            'arches': 'arch1 arch2',
            'perm_id': 1,
            'maven_support': False,
            'maven_include_all': True,
            'locked': False
        }, {
            'id': 2,
            'name': 'dst-tag',
            'arches': 'arch1 arch2',
            'perm_id': 1,
            'maven_support': False,
            'maven_include_all': True,
            'locked': False
        }]
        handle_clone_tag(self.options, self.session, args)
        self.activate_session.assert_called_once()
        self.session.assert_has_calls([
            call.hasPerm('admin'),
            call.getTag('src-tag'),
            call.getTag('dst-tag'),
            call.listPackages(event=None, inherited=True, tagID=1),
            call.listPackages(inherited=True, tagID=2),
            call.listTagged(1, event=None, inherit=None, latest=None),
            call.listTagged(2, inherit=False, latest=False),
            call.getTagGroups('src-tag', event=None),
            call.getTagGroups('dst-tag'),
            call.packageListAdd('dst-tag',
                                'pkg2',
                                block=True,
                                extra_arches='arch3 arch4',
                                owner='userB'),
            call.multiCall(batch=1000),
            call.untagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-2.1-2',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'dst-tag',
                'name': 'pkg1'
            },
                                  force=None),
            call.untagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-0.1-1',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'dst-tag',
                'name': 'pkg1'
            },
                                  force=None),
            call.untagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg3-1.0-1',
                'package_name': 'pkg3',
                'state': 1,
                'tag_name': 'dst-tag',
                'name': 'pkg3'
            },
                                  force=None),
            call.multiCall(batch=1000),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-0.1-1',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-1.0-2',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-1.1-2',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.multiCall(batch=1000),
            call.multiCall(batch=1000),
            call.groupPackageListAdd('dst-tag', 'group1', 'pkg2', force=None),
            call.groupPackageListAdd('dst-tag', 'group1', 'pkg3', force=None),
            call.groupPackageListAdd('dst-tag', 'group1', 'pkg4', force=None),
            call.groupPackageListAdd('dst-tag', 'group2', 'bpkg', force=None),
            call.multiCall(batch=1000),
            call.multiCall(batch=1000),
            call.packageListBlock('dst-tag', 'bpkg'),
            call.packageListBlock('dst-tag', 'cpkg'),
            call.packageListBlock('dst-tag', 'dpkg'),
            call.multiCall(batch=1000),
            call.groupListRemove('dst-tag', 'group3', force=None),
            call.groupListBlock('dst-tag', 'group4'),
            call.multiCall(batch=1000),
            call.groupPackageListRemove('dst-tag',
                                        'group1',
                                        'pkg5',
                                        force=None),
            call.groupPackageListBlock('dst-tag', 'group2', 'cpkg'),
            call.multiCall(batch=1000)
        ])
        self.assert_console_message(
            stdout, """
List of changes:

    Action  Package                      Blocked    Owner      From Tag  
    ------- ---------------------------- ---------- ---------- ----------
    [add]   pkg2                         True       userB      src-tag-p 
    [blk]   bpkg                         False      userC      src-tag   
    [blk]   cpkg                         True       userC      src-tag-p 
    [blk]   dpkg                         True       userC      src-tag   

    Action  From/To Package              Build(s)                                 State      Owner      From Tag  
    ------- ---------------------------- ---------------------------------------- ---------- ---------- ----------
    [del]   pkg1                         pkg1-2.1-2                               COMPLETE   b_owner    dst-tag   
    [del]   pkg1                         pkg1-0.1-1                               COMPLETE   b_owner    dst-tag   
    [del]   pkg3                         pkg3-1.0-1                               COMPLETE   b_owner    dst-tag   
    [add]   pkg1                         pkg1-0.1-1                               COMPLETE   b_owner    src-tag   
    [add]   pkg1                         pkg1-1.0-2                               COMPLETE   b_owner    src-tag   
    [add]   pkg1                         pkg1-1.1-2                               COMPLETE   b_owner    src-tag   

    Action  Package                      Group                       
    ------- ---------------------------- ----------------------------
    [new]   pkg2                         group1                      
    [new]   pkg3                         group1                      
    [new]   pkg4                         group1                      
    [new]   bpkg                         group2                      
    [del]   cpkg                         group3                      
    [del]   dpkg                         group3                      
    [blk]   epkg                         group4                      
    [blk]   fpkg                         group4                      
    [del]   pkg5                         group1                      
    [blk]   cpkg                         group2                      
""")
Ejemplo n.º 5
0
    def test_handle_clone_tag_new_dsttag(self, stdout):
        args = ['src-tag', 'dst-tag', '--all', '-v']
        self.session.listPackages.return_value = [{
            'package_id': 1,
            'package_name': 'pkg1',
            'blocked': False,
            'owner_name': 'userA',
            'tag_name': 'src-tag',
            'extra_arches': None
        }, {
            'package_id': 2,
            'package_name': 'pkg2',
            'blocked': True,
            'owner_name': 'userB',
            'tag_name': 'src-tag-p',
            'extra_arches': 'arch3 arch4'
        }, {
            'package_id': 3,
            'package_name': 'apkg',
            'blocked': False,
            'owner_name': 'userA',
            'tag_name': 'src-tag-p',
            'extra_arches': 'arch4'
        }]
        self.session.listTagged.return_value = [{
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.1-2',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.0-2',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg1',
            'nvr': 'pkg1-1.0-1',
            'state': 1,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag'
        }, {
            'package_name': 'pkg2',
            'nvr': 'pkg2-1.0-1',
            'state': 2,
            'owner_name': 'b_owner',
            'tag_name': 'src-tag-p'
        }]
        self.session.getTagGroups.return_value = [{
            'name':
            'group1',
            'packagelist': [{
                'package': 'pkg1',
                'blocked': False
            }, {
                'package': 'pkg2',
                'blocked': False
            }]
        }, {
            'name':
            'group2',
            'packagelist': [{
                'package': 'apkg',
                'blocked': False
            }, {
                'package': 'bpkg',
                'blocked': False
            }]
        }]
        self.session.getTag.side_effect = [{
            'id': 1,
            'name': 'src-tag',
            'arches': 'arch1 arch2',
            'perm_id': 1,
            'maven_support': False,
            'maven_include_all': True,
            'locked': False
        }, None, {
            'id': 2,
            'name': 'dst-tag',
            'arches': 'arch1 arch2',
            'perm_id': 1,
            'maven_support': False,
            'maven_include_all': True,
            'locked': False
        }]
        handle_clone_tag(self.options, self.session, args)
        self.activate_session.assert_called_once()
        self.session.assert_has_calls([
            call.hasPerm('admin'),
            call.getTag('src-tag'),
            call.getTag('dst-tag'),
            call.createTag('dst-tag',
                           arches='arch1 arch2',
                           locked=False,
                           maven_include_all=True,
                           maven_support=False,
                           parent=None,
                           perm=1),
            call.getTag('dst-tag', strict=True),
            call.listPackages(event=None, inherited=True, tagID=1),
            call.packageListAdd('dst-tag',
                                'apkg',
                                block=False,
                                extra_arches='arch4',
                                owner='userA'),
            call.packageListAdd('dst-tag',
                                'pkg1',
                                block=False,
                                extra_arches=None,
                                owner='userA'),
            call.packageListAdd('dst-tag',
                                'pkg2',
                                block=True,
                                extra_arches='arch3 arch4',
                                owner='userB'),
            call.multiCall(batch=1000),
            call.listTagged(1, event=None, inherit=None, latest=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg2-1.0-1',
                'package_name': 'pkg2',
                'state': 2,
                'tag_name': 'src-tag-p',
                'name': 'pkg2'
            },
                                force=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-1.0-1',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-1.0-2',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.tagBuildBypass('dst-tag', {
                'owner_name': 'b_owner',
                'nvr': 'pkg1-1.1-2',
                'package_name': 'pkg1',
                'state': 1,
                'tag_name': 'src-tag',
                'name': 'pkg1'
            },
                                force=None),
            call.multiCall(batch=1000),
            call.getTagGroups('src-tag', event=None),
            call.groupListAdd('dst-tag', 'group1'),
            call.groupPackageListAdd('dst-tag', 'group1', 'pkg1', block=False),
            call.groupPackageListAdd('dst-tag', 'group1', 'pkg2', block=False),
            call.groupListAdd('dst-tag', 'group2'),
            call.groupPackageListAdd('dst-tag', 'group2', 'apkg', block=False),
            call.groupPackageListAdd('dst-tag', 'group2', 'bpkg', block=False),
            call.multiCall(batch=1000)
        ])
        self.assert_console_message(
            stdout, """
List of changes:

    Action  Package                      Blocked    Owner      From Tag  
    ------- ---------------------------- ---------- ---------- ----------
    [new]   apkg                         False      userA      src-tag-p 
    [new]   pkg1                         False      userA      src-tag   
    [new]   pkg2                         True       userB      src-tag-p 

    Action  From/To Package              Build(s)                                 State      Owner      From Tag  
    ------- ---------------------------- ---------------------------------------- ---------- ---------- ----------
    [new]   pkg2                         pkg2-1.0-1                               DELETED    b_owner    src-tag-p 
    [new]   pkg1                         pkg1-1.0-1                               COMPLETE   b_owner    src-tag   
    [new]   pkg1                         pkg1-1.0-2                               COMPLETE   b_owner    src-tag   
    [new]   pkg1                         pkg1-1.1-2                               COMPLETE   b_owner    src-tag   

    Action  Package                      Group                       
    ------- ---------------------------- ----------------------------
    [new]   pkg1                         group1                      
    [new]   pkg2                         group1                      
    [new]   apkg                         group2                      
    [new]   bpkg                         group2                      
""")