Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 64003c00f0d8d6689c471999267eee826401bc4a Author: Valentin Gologuzov vgologuz@redhat.com Date: Tue Nov 25 12:13:24 2014 +0100
[backend] unittest for backend.actions
backend/tests/mockremote/test_mockremote.py | 1 - backend/tests/test_action.py | 142 ++++++++++++++++++++++++++- 2 files changed, 137 insertions(+), 6 deletions(-)
diff --git a/backend/tests/mockremote/test_mockremote.py b/backend/tests/mockremote/test_mockremote.py index b79181a..4d3eb03 100644 --- a/backend/tests/mockremote/test_mockremote.py +++ b/backend/tests/mockremote/test_mockremote.py @@ -90,7 +90,6 @@ class TestMockRemote(object): self.PKG_NAME = "foobar" self.PKG_VERSION = "1.2.3"
- self.HOST = "127.0.0.1" self.SRC_PKG_URL = "http://example.com/%7B%7D-%7B%7D.src.rpm%22.format(self.PKG_NAME, self.PKG_VERSION) self.JOB = BuildJob({ diff --git a/backend/tests/test_action.py b/backend/tests/test_action.py index aaacacd..674bd10 100644 --- a/backend/tests/test_action.py +++ b/backend/tests/test_action.py @@ -41,8 +41,16 @@ else:
RESULTS_ROOT_URL = "http://example.com/results" +STDOUT = "stdout" +STDERR = "stderr"
+def assert_what_from_queue(q, msg_list, who="action"): + for msg in msg_list: + ev = q.get_nowait() + assert ev["who"] == who + assert msg in ev["what"] + @mock.patch("backend.actions.time") class TestAction(object):
@@ -479,9 +487,133 @@ class TestAction(object):
assert error_event_recorded
+ @mock.patch("backend.actions.createrepo_unsafe") + def test_handle_createrepo_ok(self, mc_createrepo_unsfe, mc_time): + mc_front_cb = MagicMock() + tmp_dir = self.make_temp_dir() + mc_createrepo_unsfe.return_value = 0, STDOUT, ""
-def assert_what_from_queue(q, msg_list, who="action"): - for msg in msg_list: - ev = q.get_nowait() - assert ev["who"] == who - assert msg in ev["what"] + action_data = json.dumps({ + "chroots": ["epel-6-i386", "fedora-20-x86_64"], + "username": "foo", + "projectname": "bar" + }) + test_action = Action( + action={ + "action_type": ActionType.CREATEREPO, + "data": action_data, + "id": 8 + }, + events=self.test_q, lock=None, + frontend_callback=mc_front_cb, + destdir=tmp_dir, + front_url=None, + results_root_url=RESULTS_ROOT_URL + ) + test_action.run() + + result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] + + assert result_dict["id"] == 8 + assert result_dict["result"] == ActionResult.SUCCESS + + exp_call_1 = mock.call(lock=None, path=tmp_dir + u'/foo/bar/epel-6-i386') + exp_call_2 = mock.call(lock=None, path=tmp_dir + u'/foo/bar/fedora-20-x86_64') + assert exp_call_1 in mc_createrepo_unsfe.call_args_list + assert exp_call_2 in mc_createrepo_unsfe.call_args_list + assert len(mc_createrepo_unsfe.call_args_list) == 2 + + + @mock.patch("backend.actions.createrepo_unsafe") + def test_handle_createrepo_failure_1(self, mc_createrepo_unsfe, mc_time): + mc_front_cb = MagicMock() + tmp_dir = self.make_temp_dir() + mc_createrepo_unsfe.return_value = 1, STDOUT, "" + + action_data = json.dumps({ + "chroots": ["epel-6-i386", "fedora-20-x86_64"], + "username": "foo", + "projectname": "bar" + }) + test_action = Action( + action={ + "action_type": ActionType.CREATEREPO, + "data": action_data, + "id": 9 + }, + events=self.test_q, lock=None, + frontend_callback=mc_front_cb, + destdir=tmp_dir, + front_url=None, + results_root_url=RESULTS_ROOT_URL + ) + test_action.run() + + result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] + + assert result_dict["id"] == 9 + assert result_dict["result"] == ActionResult.FAILURE + + @mock.patch("backend.actions.createrepo_unsafe") + def test_handle_createrepo_failure_2(self, mc_createrepo_unsfe, mc_time): + mc_front_cb = MagicMock() + tmp_dir = self.make_temp_dir() + mc_createrepo_unsfe.return_value = 0, STDOUT, STDERR + + action_data = json.dumps({ + "chroots": ["epel-6-i386", "fedora-20-x86_64"], + "username": "foo", + "projectname": "bar" + }) + test_action = Action( + action={ + "action_type": ActionType.CREATEREPO, + "data": action_data, + "id": 10 + }, + events=self.test_q, lock=None, + frontend_callback=mc_front_cb, + destdir=tmp_dir, + front_url=None, + results_root_url=RESULTS_ROOT_URL + ) + test_action.run() + + result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] + + assert result_dict["id"] == 10 + assert result_dict["result"] == ActionResult.FAILURE + + @mock.patch("backend.actions.createrepo_unsafe") + def test_handle_createrepo_failure_3(self, mc_createrepo_unsfe, mc_time): + mc_front_cb = MagicMock() + tmp_dir = self.make_temp_dir() + mc_createrepo_unsfe.side_effect = [ + (0, STDOUT, ""), + (1, STDOUT, STDERR), + ] + + + action_data = json.dumps({ + "chroots": ["epel-6-i386", "fedora-20-x86_64"], + "username": "foo", + "projectname": "bar" + }) + test_action = Action( + action={ + "action_type": ActionType.CREATEREPO, + "data": action_data, + "id": 10 + }, + events=self.test_q, lock=None, + frontend_callback=mc_front_cb, + destdir=tmp_dir, + front_url=None, + results_root_url=RESULTS_ROOT_URL + ) + test_action.run() + + result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] + + assert result_dict["id"] == 10 + assert result_dict["result"] == ActionResult.FAILURE
copr-commits@lists.fedorahosted.org