From d00145c3eb0a7ca261c3277211eddcdfd20d4741 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Jan 10 2020 08:55:42 +0000 Subject: frontend: fix testsuite broken by b18cf83599a988fa In /backend/update/ route we need to set ended_on attribute for {success, failure} results, not {success, waiting}. Relates: #803 --- diff --git a/frontend/coprs_frontend/coprs/logic/actions_logic.py b/frontend/coprs_frontend/coprs/logic/actions_logic.py index f1953ca..83f5e39 100644 --- a/frontend/coprs_frontend/coprs/logic/actions_logic.py +++ b/frontend/coprs_frontend/coprs/logic/actions_logic.py @@ -69,8 +69,9 @@ class ActionsLogic(object): if value: setattr(action, attr, value) - if attr == "result" and value in [BackendResultEnum("success"), BackendResultEnum("waiting")]: - setattr(action, "ended_on", time.time()) + if upd_dict.get('result', None) in [BackendResultEnum("success"), + BackendResultEnum("failure")]: + action.ended_on = time.time() db.session.add(action) @classmethod diff --git a/frontend/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py b/frontend/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py index 4a3a5bf..7bf799c 100644 --- a/frontend/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py +++ b/frontend/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py @@ -1,5 +1,7 @@ import json +from unittest import mock + from copr_common.enums import BackendResultEnum, StatusEnum from tests.coprs_test_case import CoprsTestCase, new_app_context from coprs.logic.builds_logic import BuildsLogic @@ -300,20 +302,17 @@ class TestUpdateActions(CoprsTestCase): { "id": 1, "result": 1, - "message": null, - "ended_on": 1390866440 + "message": null }, { "id": 2, "result": 2, - "message": "problem!", - "ended_on": 1390866440 + "message": "problem!" }, { "id": 100, "result": 123, - "message": "wheeeee!", - "ended_on": 1390866440 + "message": "wheeeee!" } ] }""" @@ -332,9 +331,12 @@ class TestUpdateActions(CoprsTestCase): assert updated.message == "no problem" assert updated.ended_on == 1390866440 - def test_update_more_existent_and_non_existent_actions(self, f_users, - f_coprs, f_actions, - f_db): + + @mock.patch('coprs.logic.actions_logic.time.time') + def test_update_more_existent_and_non_existent_actions(self, mc_time, f_users, + f_coprs, f_actions, + f_db): + mc_time.return_value = 1390866440 r = self.tc.post("/backend/update/", content_type="application/json", headers=self.auth_header,