Esempio n. 1
0
 def test_getRPMFile_no_rpmfile(self, ope, pr, pb, get_build, get_rpm):
     re = kojihub.RootExports().getRPMFile(1, 'filename')
     self.assertEquals(re, {})
     with self.assertRaises(koji.GenericError) as cm:
         kojihub.RootExports().getRPMFile(1, 'filename', strict=True)
     self.assertEquals(cm.exception.args[0],
                       "RPM package file of 1 doesn't exist")
Esempio n. 2
0
 def test_getRPMFile_external_rpm(self, get_rpm):
     re = kojihub.RootExports().getRPMFile(1, 'filename')
     self.assertEquals(re, {})
     with self.assertRaises(koji.GenericError) as cm:
         kojihub.RootExports().getRPMFile(1, 'filename', strict=True)
     self.assertEquals(
         cm.exception.args[0], 'Can not get RPM file,'
         ' because RPM: 1 is not internal')
 def test_getRPMDeps_external_rpm(self, get_rpm):
     re = kojihub.RootExports().getRPMDeps(1)
     self.assertEquals(re, [])
     with self.assertRaises(koji.GenericError) as cm:
         kojihub.RootExports().getRPMDeps(1, strict=True)
     self.assertEquals(
         cm.exception.args[0], 'Can not get dependencies,'
         ' because RPM: 1 is not internal')
    def test_getRPMDeps_no_rpminfo(self, get_rpm):
        def mock_get_rpm(rpmID, strict=False):
            if strict:
                raise koji.GenericError('msg')
            else:
                return None

        get_rpm.side_effect = mock_get_rpm
        re = kojihub.RootExports().getRPMDeps(1)
        self.assertEquals(re, [])
        with self.assertRaises(koji.GenericError) as cm:
            kojihub.RootExports().getRPMDeps(1, strict=True)
        self.assertEquals(cm.exception.args[0], 'msg')
    def test_has_perm(self, lookup_perm, context):
        rv = kojihub.RootExports().hasPerm('perm')
        self.assertEqual(rv, context.session.hasPerm.return_value)
        lookup_perm.assert_not_called()
        context.session.hasPerm.assert_called_once_with('perm')

        context.session.hasPerm.reset_mock()
        with self.assertRaises(koji.GenericError) as cm:
            kojihub.RootExports().hasPerm('perm', strict=True)
        lookup_perm.assert_called_once_with('perm')
        context.session.hasPerm.assert_not_called()
        self.assertEqual(cm.exception.args[0],
                         'No such permission perm defined')
 def setUp(self):
     self.get_build = mock.patch('kojihub.get_build').start()
     self.exports = kojihub.RootExports()
     self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                       side_effect=self.getInsert).start()
     self.inserts = []
     self.insert_execute = mock.MagicMock()
Esempio n. 7
0
 def setUp(self):
     self.verify_name_user = mock.patch('kojihub.verify_name_user').start()
     self.get_user = mock.patch('kojihub.get_user').start()
     self.get_user_by_krb_principal = mock.patch(
         'kojihub.get_user_by_krb_principal').start()
     self.exports = kojihub.RootExports()
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.context.session.assertPerm = mock.MagicMock()
     self.context.session.assertLogin = mock.MagicMock()
     self.user_name = 'test_user'
     self.user_info = {
         'id': 1,
         'krb_principals': [],
         'name': self.user_name,
         'status': 0,
         'usertype': 0
     }
     self.user_info_krb = {
         'id': 1,
         'krb_principals': ['*****@*****.**'],
         'name': self.user_name,
         'status': 0,
         'usertype': 0
     }
 def setUp(self):
     self.exports = kojihub.RootExports()
     self.get_channel = mock.patch('kojihub.get_channel').start()
     self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                       side_effect=self.getUpdate).start()
     self.updates = []
     self.channelname = 'test-channel'
 def setUp(self):
     self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
                                      side_effect=self.getQuery).start()
     self.queries = []
     self.get_tag = mock.patch('kojihub.get_tag').start()
     self.exports = kojihub.RootExports()
     self.context = mock.patch('kojihub.context').start()
     self.cursor = mock.MagicMock()
Esempio n. 10
0
 def setUp(self):
     self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
                                       side_effect=self.getQuery).start()
     self.queries = []
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.exports = kojihub.RootExports()
 def setUp(self):
     self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                       side_effect=self.getUpdate).start()
     self.updates = []
     self.context = mock.patch('kojihub.context').start()
     self.context.session.assertPerm = mock.MagicMock()
     self.exports = kojihub.RootExports()
     self.channel_name = 'test-channel'
Esempio n. 12
0
 def test_non_exist_file(self, os_path_exist):
     exports = kojihub.RootExports()
     basename = 'rpm-1-34'
     uploadpath = koji.pathinfo.work()
     filepath = '%s/%s/%s' % (uploadpath, self.filename, basename)
     os_path_exist.return_value = False
     with self.assertRaises(koji.GenericError) as cm:
         exports.importRPM(self.filename, basename)
     self.assertEqual("No such file: %s" % filepath, str(cm.exception))
Esempio n. 13
0
 def test_getPackageID_None(self):
     rv = kojihub.RootExports().getPackageID('invalidpkg')
     self.assertEqual(len(self.queries), 1)
     self.assertLastQueryEqual(tables=['package'],
                               columns=['id'],
                               clauses=['name=%(name)s'],
                               values={'name': 'invalidpkg',
                                       'strict': False,
                                       'self': mock.ANY})
     self.assertIsNone(rv)
 def setUp(self):
     self.verify_name_internal = mock.patch(
         'kojihub.verify_name_internal').start()
     self.exports = kojihub.RootExports()
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.context.session.assertPerm = mock.MagicMock()
     self.context.session.assertLogin = mock.MagicMock()
     self.user_name = 'test_user'
Esempio n. 15
0
 def setUp(self):
     self.hub = kojihub.RootExports()
     self.standard_processor_kwargs = dict(
         tables=mock.ANY,
         columns=mock.ANY,
         values=mock.ANY,
         joins=mock.ANY,
         clauses=mock.ANY,
         opts=mock.ANY,
         aliases=mock.ANY,
     )
Esempio n. 16
0
 def test_getPackageID(self):
     self.qp_execute_return_value = [{'id': 1}]
     rv = kojihub.RootExports().getPackageID('koji')
     self.assertEqual(len(self.queries), 1)
     self.assertLastQueryEqual(tables=['package'],
                               columns=['id'],
                               clauses=['name=%(name)s'],
                               values={'name': 'koji',
                                       'strict': False,
                                       'self': mock.ANY})
     self.assertEqual(rv, 1)
Esempio n. 17
0
 def test_getPackageID_strict(self):
     with self.assertRaises(koji.GenericError) as cm:
         kojihub.RootExports().getPackageID('invalidpkg', strict=True)
     self.assertLastQueryEqual(tables=['package'],
                               columns=['id'],
                               clauses=['name=%(name)s'],
                               values={'name': 'invalidpkg',
                                       'strict': True,
                                       'self': mock.ANY})
     self.assertEqual(cm.exception.args[0],
                      'Invalid package name: invalidpkg')
Esempio n. 18
0
    def setUp(self):

        self.context = mock.patch('kojihub.context').start()
        self.context.session.assertPerm = mock.MagicMock()
        self.exports = kojihub.RootExports()
        self.channel_name = 'test-channel'
        self.description = 'test-description'
        self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                          side_effect=self.getInsert).start()
        self.inserts = []
        self.insert_execute = mock.MagicMock()
Esempio n. 19
0
 def setUp(self):
     self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
                                      side_effect=self.getQuery).start()
     self.queries = []
     self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                       side_effect=self.getInsert).start()
     self.inserts = []
     self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                       side_effect=self.getUpdate).start()
     self.updates = []
     self._dml = mock.patch('kojihub._dml').start()
     self.exports = kojihub.RootExports()
Esempio n. 20
0
 def setUp(self):
     self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                       side_effect=self.getInsert).start()
     self.inserts = []
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.context.session.assertLogin = mock.MagicMock()
     self.context.session.assertPerm = mock.MagicMock()
     self.context.opts = {'HostPrincipalFormat': '-%s-'}
     self.exports = kojihub.RootExports()
     self.data_path = os.path.abspath("tests/test_hub/data/rpms")
    def test_getRPMDeps(self, pi, build, rpm):
        pi.build.return_value = os.path.join(os.path.dirname(__file__),
                                             '../test_lib/data/rpms')
        pi.rpm.return_value = 'test-deps-1-1.fc24.x86_64.rpm'
        getRPMDeps = kojihub.RootExports().getRPMDeps
        res = getRPMDeps('')
        # limit test for rpm < 4.12
        if any(koji.SUPPORTED_OPT_DEP_HDRS.values()):
            self.assertEqual(len(res), 22)
            types = set([x['type'] for x in res])
            self.assertEqual(
                set([
                    koji.DEP_REQUIRE,
                    koji.DEP_PROVIDE,
                    koji.DEP_OBSOLETE,
                    koji.DEP_CONFLICT,
                    koji.DEP_SUGGEST,
                    koji.DEP_ENHANCE,
                    koji.DEP_SUPPLEMENT,
                    koji.DEP_RECOMMEND,
                ]), types)

            # test correct mapping of names
            result = {}
            for r in res:
                result.setdefault(r['type'], set()).add(r['name'])
            self.assertTrue('require1' in result[koji.DEP_REQUIRE])
            self.assertTrue('provide1' in result[koji.DEP_PROVIDE])
            self.assertTrue('obsoletes1' in result[koji.DEP_OBSOLETE])
            self.assertTrue('conflicts1' in result[koji.DEP_CONFLICT])
            self.assertTrue('suggests1' in result[koji.DEP_SUGGEST])
            self.assertTrue('enhances1' in result[koji.DEP_ENHANCE])
            self.assertTrue('supplements1' in result[koji.DEP_SUPPLEMENT])
            self.assertTrue('recommends1' in result[koji.DEP_RECOMMEND])
        else:
            self.assertEqual(len(res), 14)
            types = set([x['type'] for x in res])
            self.assertEqual(
                set([
                    koji.DEP_REQUIRE,
                    koji.DEP_PROVIDE,
                    koji.DEP_OBSOLETE,
                    koji.DEP_CONFLICT,
                ]), types)

            # test correct mapping of names
            result = {}
            for r in res:
                result.setdefault(r['type'], set()).add(r['name'])
            self.assertTrue('require1' in result[koji.DEP_REQUIRE])
            self.assertTrue('provide1' in result[koji.DEP_PROVIDE])
            self.assertTrue('obsoletes1' in result[koji.DEP_OBSOLETE])
            self.assertTrue('conflicts1' in result[koji.DEP_CONFLICT])
Esempio n. 22
0
 def setUp(self):
     self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                       side_effect=self.getUpdate).start()
     self.updates = []
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.context.session.assertLogin = mock.MagicMock()
     self.context.session.assertPerm = mock.MagicMock()
     self.context.event_id = 42
     self.context.session.user_id = 23
     self.context.opts = {'HostPrincipalFormat': '-%s-'}
     self.exports = kojihub.RootExports()
 def setUp(self):
     self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                       side_effect=self.getInsert).start()
     self.inserts = []
     self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                       side_effect=self.getUpdate).start()
     self.updates = []
     self.context = mock.patch('kojihub.context').start()
     # It seems MagicMock will not automatically handle attributes that
     # start with "assert"
     self.context.session.assertLogin = mock.MagicMock()
     self.context.session.assertPerm = mock.MagicMock()
     self.exports = kojihub.RootExports()
Esempio n. 24
0
    def test_inherited_noconfig(self, get_tag, readFullInheritance):
        tag = 'tag_name'
        get_tag.side_effect = [
            {
                'id': 123,
                'name': tag,
                'extra': {},
                'arches': None,
            },
            {
                'id': 1234,
                'name': 'parent',
                'extra': {
                    'value': (False, 'inherited')
                },
                'arches': 'x86_64',
            },
        ]
        readFullInheritance.return_value = [{
            'child_id': 123,
            'currdepth': 1,
            'filter': [],
            'intransitive': False,
            'maxdepth': None,
            'name': tag,
            'nextdepth': None,
            'noconfig': True,
            'parent_id': 1234,
            'pkg_filter': '',
            'priority': 0
        }]

        taginfo = kojihub.RootExports().getBuildConfig(tag, event=1111)

        get_tag.assert_called_once_with(tag,
                                        event=1111,
                                        strict=True,
                                        blocked=True)
        readFullInheritance.assert_called_with(123, event=1111)

        self.assertEqual(
            taginfo, {
                'arches': None,
                'extra': {},
                'config_inheritance': {
                    'extra': {},
                    'arches': None
                },
                'id': 123,
                'name': 'tag_name'
            })
    def test_DistRepo(self, make_task, dist_repo_init):
        session = kojihub.context.session = mock.MagicMock()
        # It seems MagicMock will not automatically handle attributes that
        # start with "assert"
        session.assertPerm = mock.MagicMock()
        dist_repo_init.return_value = ('repo_id', 'event_id')
        make_task.return_value = 'task_id'

        exports = kojihub.RootExports()
        ret = exports.distRepo('tag', 'keys')
        session.assertPerm.assert_called_once_with('dist-repo')
        dist_repo_init.assert_called_once()
        make_task.assert_called_once()
        self.assertEquals(ret, make_task.return_value)
Esempio n. 26
0
def get_registry(opts, plugins):
    # Create and populate handler registry
    registry = HandlerRegistry()
    functions = kojihub.RootExports()
    hostFunctions = kojihub.HostExports()
    registry.register_instance(functions)
    registry.register_module(hostFunctions,"host")
    registry.register_function(koji.auth.login)
    registry.register_function(koji.auth.krbLogin)
    registry.register_function(koji.auth.sslLogin)
    registry.register_function(koji.auth.logout)
    registry.register_function(koji.auth.subsession)
    registry.register_function(koji.auth.logoutChild)
    registry.register_function(koji.auth.exclusiveSession)
    registry.register_function(koji.auth.sharedSession)
    for name in opts.get('Plugins', '').split():
        registry.register_plugin(plugins.get(name))
    return registry
Esempio n. 27
0
    def test_simple_tag(self, get_tag, readFullInheritance):
        tag = 'tag_name'
        get_tag.return_value = {'id': 123, 'name': tag, 'extra': {}}
        readFullInheritance.return_value = []

        taginfo = kojihub.RootExports().getBuildConfig(tag)

        get_tag.assert_called_with(tag, event=None, strict=True, blocked=True)
        readFullInheritance.assert_called_with(123, event=None)

        self.assertEqual(
            taginfo, {
                'id': 123,
                'name': tag,
                'extra': {},
                'config_inheritance': {
                    'extra': {},
                    'arches': None
                },
            })
 def setUp(self):
     self.get_build = mock.patch('kojihub.get_build').start()
     self.exports = kojihub.RootExports()
     self.session = mock.MagicMock()
     self.context = mock.patch('kojihub.context').start()
     self.context.session.assertPerm = mock.MagicMock()
     self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                       side_effect=self.getInsert).start()
     self.inserts = []
     self.insert_execute = mock.MagicMock()
     self.get_build_info = {
         'id': 100,
         'name': 'test_name',
         'version': 'test_version',
         'release': 'test_release',
         'epoch': 'test_epoch',
         'owner': 'test_owner',
         'build_id': 2,
     }
     self.build_info = 'test-build-11-12'
Esempio n. 29
0
    def test_DistRepo(self, make_task, dist_repo_init, assert_policy):
        session = kojihub.context.session = mock.MagicMock()
        session.user_id = 123
        # It seems MagicMock will not automatically handle attributes that
        # start with "assert"
        session.hasPerm = mock.MagicMock()
        session.hasPerm.return_value = False
        dist_repo_init.return_value = ('repo_id', 'event_id')
        make_task.return_value = 'task_id'
        exports = kojihub.RootExports()
        exports.getBuildConfig = mock.MagicMock()
        exports.getBuildConfig.return_value = {'extra': {}}

        ret = exports.distRepo('tag', 'keys')

        session.hasPerm.has_calls(mock.call('dist_repo'), mock.call('admin'))
        assert_policy.assert_called_once_with('dist_repo', {'tag': 'tag'})
        dist_repo_init.assert_called_once()
        make_task.assert_called_once()
        self.assertEquals(ret, make_task.return_value)
        exports.getBuildConfig.assert_called_once_with('tag')
Esempio n. 30
0
    def setUp(self):
        self.context = mock.patch('kojihub.context').start()
        self.context.opts = {
            'EmailDomain': 'test.domain.com',
            'NotifyOnSuccess': True,
        }

        self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
                                         side_effect=self.getQuery).start()
        self.queries = []
        self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
                                          side_effect=self.getInsert).start()
        self.inserts = []
        self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',
                                          side_effect=self.getUpdate).start()
        self.updates = []

        self.exports = kojihub.RootExports()
        self.exports.getLoggedInUser = mock.MagicMock()
        self.exports.getUser = mock.MagicMock()
        self.exports.hasPerm = mock.MagicMock()
        self.exports.getBuildNotification = mock.MagicMock()