def test_handle_block_pkg_multi_pkg(self, activate_session_mock, stdout): tag = 'tag' dsttag = {'name': tag, 'id': 1} packages = ['package1', 'package2', 'package3'] args = [tag] + packages options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.getTag.return_value = dsttag session.listPackages.return_value = [ {'package_name': 'package1', 'package_id': 1}, {'package_name': 'package2', 'package_id': 2}, {'package_name': 'package3', 'package_id': 3}, {'package_name': 'other_package', 'package_id': 4} ] # Run it and check immediate output # args: tag, package1, package2, package3 # expected: success rv = handle_block_pkg(options, session, args) actual = stdout.getvalue() expected = '' 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.getTag(tag), call.listPackages(tagID=dsttag['id'], inherited=True), call.packageListBlock(tag, packages[0], force=False), call.packageListBlock(tag, packages[1], force=False), call.packageListBlock(tag, packages[2], force=False), call.multiCall(strict=True)]) self.assertNotEqual(rv, 1)
def test_handle_block_pkg_multi_pkg(self, activate_session_mock, stdout): tag = 'tag' dsttag = {'name': tag, 'id': 1} packages = ['package1', 'package2', 'package3'] args = [tag] + packages options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.getTag.return_value = dsttag session.listPackages.return_value = [ {'package_name': 'package1', 'package_id': 1}, {'package_name': 'package2', 'package_id': 2}, {'package_name': 'package3', 'package_id': 3}, {'package_name': 'other_package', 'package_id': 4} ] # Run it and check immediate output # args: tag, package1, package2, package3 # expected: success rv = cli.handle_block_pkg(options, session, args) actual = stdout.getvalue() expected = '' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session) self.assertEqual( session.mock_calls, [ call.getTag(tag), call.listPackages( tagID=dsttag['id'], inherited=True), call.packageListBlock( tag, packages[0]), call.packageListBlock( tag, packages[1]), call.packageListBlock( tag, packages[2]), call.multiCall( strict=True)]) self.assertNotEqual(rv, 1)
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 """)
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 """)