From 7c0df57e4843fd6bab275576c6a8d5f4983705f8 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Aug 08 2016 22:13:50 +0000 Subject: Merge branch 'small-prs' Merges #126 Merges #123 Merges #115 Merges #130 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index e3394ec..f1c3834 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -46,7 +46,6 @@ import os import re import rpm import shutil -import simplejson as json import stat import subprocess import sys @@ -58,6 +57,12 @@ import xmlrpclib import zipfile from koji.context import context +try: + import json +except ImportError: + import simplejson as json + + logger = logging.getLogger('koji.hub') def log_error(msg): @@ -10708,9 +10713,8 @@ class Host(object): c.execute(q,locals()) return [finished,unfinished] - def taskWaitResults(self,parent,tasks): - results = {} - #if we're getting results, we're done waiting + def taskWaitResults(self, parent, tasks): + # If we're getting results, we're done waiting self.taskUnwait(parent) c = context.cnx.cursor() canceled = koji.TASK_STATES['CANCELED'] @@ -10720,19 +10724,19 @@ class Host(object): SELECT id,state FROM task WHERE parent=%(parent)s""" if tasks is None: - #query all subtasks + # Query all subtasks tasks = [] c.execute(q,locals()) for id,state in c.fetchall(): if state == canceled: raise koji.GenericError, "Subtask canceled" - elif state in (closed,failed): + elif state in (closed, failed): tasks.append(id) - #would use a dict, but xmlrpc requires the keys to be strings + # Would use a dict, but xmlrpc requires the keys to be strings results = [] for id in tasks: task = Task(id) - results.append([id,task.getResult()]) + results.append([id, task.getResult()]) return results def getHostTasks(self): diff --git a/koji.spec b/koji.spec index a1b3f28..7e752bb 100644 --- a/koji.spec +++ b/koji.spec @@ -47,6 +47,9 @@ License: LGPLv2 and GPLv2 Requires: httpd Requires: mod_wsgi Requires: postgresql-python +%if 0%{?rhel} == 5 +Requires: python-simplejson +%endif Requires: %{name} = %{version}-%{release} %description hub diff --git a/tests/test_hub/test_delete_build.py b/tests/test_hub/test_delete_build.py index 727f2ec..d6fc103 100644 --- a/tests/test_hub/test_delete_build.py +++ b/tests/test_hub/test_delete_build.py @@ -11,7 +11,7 @@ class TestDeleteBuild(unittest.TestCase): @mock.patch('kojihub.context') @mock.patch('kojihub.get_build') def test_delete_build_raise_error(self, build, context): - + context.session.assertPerm = mock.MagicMock() references = ['tags', 'rpms', 'archives', 'images'] for ref in references: context = mock.MagicMock() @@ -27,7 +27,7 @@ class TestDeleteBuild(unittest.TestCase): @mock.patch('kojihub.context') @mock.patch('kojihub.get_build') def test_delete_build_return_false(self, build, context): - + context.session.assertPerm = mock.MagicMock() references = ['tags', 'rpms', 'archives', 'images'] for ref in references: context = mock.MagicMock() @@ -42,7 +42,7 @@ class TestDeleteBuild(unittest.TestCase): @mock.patch('kojihub.context') @mock.patch('kojihub.get_build') def test_delete_build_check_last_used_raise_error(self, build, context): - + context.session.assertPerm = mock.MagicMock() references = ['tags', 'rpms', 'archives', 'images', 'last_used'] for ref in references: context = mock.MagicMock() @@ -59,7 +59,7 @@ class TestDeleteBuild(unittest.TestCase): @mock.patch('kojihub.context') @mock.patch('kojihub.get_build') def test_delete_build_check_last_used_raise_error(self, build, context): - + context.session.assertPerm = mock.MagicMock() references = ['tags', 'rpms', 'archives', 'images', 'last_used'] for ref in references: context = mock.MagicMock() diff --git a/tests/test_hub/test_import_image_internal.py b/tests/test_hub/test_import_image_internal.py index 287c172..212d368 100644 --- a/tests/test_hub/test_import_image_internal.py +++ b/tests/test_hub/test_import_image_internal.py @@ -22,6 +22,9 @@ class TestImportImageInternal(unittest.TestCase): @mock.patch('kojihub.Task') @mock.patch('kojihub.context') def test_basic(self, context, Task, get_build, get_archive_type, import_archive, work): + task = mock.MagicMock() + task.assertHost = mock.MagicMock() + Task.return_value = task imgdata = { 'arch': 'x86_64', 'task_id': 1, @@ -51,6 +54,9 @@ class TestImportImageInternal(unittest.TestCase): @mock.patch('kojihub.Task') @mock.patch('kojihub.context') def test_with_rpm(self, context, Task, get_build, get_archive_type, import_archive, build, work, get_rpm): + task = mock.MagicMock() + task.assertHost = mock.MagicMock() + Task.return_value = task rpm = { #'location': 'foo', 'id': 6, diff --git a/tests/test_hub/test_insert_processor.py b/tests/test_hub/test_insert_processor.py index 202d914..1771681 100644 --- a/tests/test_hub/test_insert_processor.py +++ b/tests/test_hub/test_insert_processor.py @@ -33,6 +33,7 @@ class TestInsertProcessor(unittest.TestCase): def test_make_create(self, context): cursor = mock.MagicMock() context.cnx.cursor.return_value = cursor + context.session.assertLogin = mock.MagicMock() proc = kojihub.InsertProcessor('sometable', data={'foo': 'bar'}) proc.make_create(event_id=1, user_id=2) self.assertEquals(proc.data['create_event'], 1) @@ -54,6 +55,7 @@ class TestInsertProcessor(unittest.TestCase): def test_dup_check(self, context): cursor = mock.MagicMock() context.cnx.cursor.return_value = cursor + context.session.assertLogin = mock.MagicMock() proc = kojihub.InsertProcessor('sometable', data={'foo': 'bar'}) proc.dup_check() diff --git a/tests/test_plugins/test_runroot_hub.py b/tests/test_plugins/test_runroot_hub.py index 97fd1cf..dd13289 100644 --- a/tests/test_plugins/test_runroot_hub.py +++ b/tests/test_plugins/test_runroot_hub.py @@ -8,6 +8,7 @@ class TestRunrootHub(unittest.TestCase): @mock.patch('kojihub.make_task') @mock.patch('runroot_hub.context') def test_basic_invocation(self, context, make_task): + context.session.assertPerm = mock.MagicMock() runroot_hub.runroot( tagInfo='some_tag', arch='x86_64', diff --git a/tests/test_tasks.py b/tests/test_tasks.py index d51492a..92b1847 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -434,7 +434,7 @@ class TasksTestCase(TestCase): obj = TestTask(123, 'some_method', ['random_arg'], None, None, temp_path) self.assertEquals(obj.chownTree(temp_path, 2, 0), None) - mock_lchown.assert_has_calls([call(temp_path, 2, 0), call(dummy_file2, 2, 0), call(dummy_file, 2, 0)]) + mock_lchown.assert_has_calls([call(temp_path, 2, 0), call(dummy_file2, 2, 0), call(dummy_file, 2, 0)], any_order=True) def test_BaseTaskHandler_localPath_file_exists(self): """ Tests the localPath function to ensure that when a file exists, it returns that path without