Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 27ed68f10c22756d44c7343a10e76faecbf5deeb Author: Valentin Gologuzov vgologuz@redhat.com Date: Tue Dec 2 14:29:42 2014 +0100
[frontend] re-enabling of auto_createrepo should produce createrepo action
.../coprs_frontend/coprs/logic/actions_logic.py | 12 ++++ frontend/coprs_frontend/coprs/logic/coprs_logic.py | 23 ++++++++ .../test_views/test_coprs_ns/test_coprs_general.py | 57 ++++++++++++++++++++ 3 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/logic/actions_logic.py b/frontend/coprs_frontend/coprs/logic/actions_logic.py index a410612..a32dfe7 100644 --- a/frontend/coprs_frontend/coprs/logic/actions_logic.py +++ b/frontend/coprs_frontend/coprs/logic/actions_logic.py @@ -17,6 +17,18 @@ class ActionsLogic(object): return query
@classmethod + def get_many(cls, action_type=None, result=None): + query = models.Action.query + if action_type is not None: + query = query.filter(models.Action.action_type == + int(action_type)) + if result is not None: + query = query.filter(models.Action.result == + int(result)) + + return query + + @classmethod def get_waiting(cls): """ Return actions that aren't finished diff --git a/frontend/coprs_frontend/coprs/logic/coprs_logic.py b/frontend/coprs_frontend/coprs/logic/coprs_logic.py index 2dba3d0..3c2d8f5 100644 --- a/frontend/coprs_frontend/coprs/logic/coprs_logic.py +++ b/frontend/coprs_frontend/coprs/logic/coprs_logic.py @@ -1,5 +1,8 @@ import time + from sqlalchemy import and_ +from sqlalchemy.event import listen +from sqlalchemy.orm.attributes import NEVER_SET
from coprs import db from coprs import exceptions @@ -8,6 +11,8 @@ from coprs import models from coprs import signals from coprs.logic import users_logic
+from coprs.logic.actions_logic import ActionsLogic +
class CoprsLogic(object): """ @@ -319,6 +324,24 @@ class CoprPermissionsLogic(object): db.session.delete(copr_permission)
+def on_auto_createrepo_change(target_copr, value_acr, old_value_acr, initiator): + """ Emit createrepo action when auto_createrepo re-enabled""" + if old_value_acr == NEVER_SET: + # created new copr, not interesting + return + if not old_value_acr and value_acr: + # re-enabled + ActionsLogic.send_createrepo( + target_copr.owner.name, + target_copr.name, + " ".join(map(str, target_copr.active_chroots)) + ) + + +listen(models.Copr.auto_createrepo, 'set', on_auto_createrepo_change, + active_history=True, retval=False) + + class CoprChrootsLogic(object): @classmethod def mock_chroots_from_names(cls, user, names): diff --git a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py index 311036a..f9d5069 100644 --- a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py +++ b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py @@ -1,3 +1,4 @@ +import json import flask import pytest
@@ -6,9 +7,11 @@ import mock import time
from coprs import models +from coprs.helpers import ActionTypeEnum from coprs.signals import copr_created
from coprs.logic.coprs_logic import CoprsLogic +from coprs.logic.actions_logic import ActionsLogic
from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
@@ -391,6 +394,60 @@ class TestCoprUpdate(CoprsTestCase):
assert len(mock_chroots) == 1
+ @TransactionDecorator("u1") + def test_re_enable_auto_createrepo_produce_action( + self, f_users, f_coprs, f_mock_chroots, f_db): + + self.db.session.add_all( + [self.u1, self.c1, self.mc1, self.mc2, self.mc3]) + + + username = self.u1.name + coprname = self.c1.name + copr_id = self.c1.id + chroot = self.mc1.name + + # 1.ensure ACR enabled + + self.db.session.commit() + c1_actual = CoprsLogic.get(None, self.u1.name, self.c1.name).one() + assert c1_actual.auto_createrepo + # 1. disabling ACR + self.test_client.post( + "/coprs/{0}/{1}/update/".format(username, coprname), + data={"name": coprname, chroot: "y", "id": copr_id, + "disable_createrepo": True}, + follow_redirects=True + ) + self.db.session.commit() + + # check current status + c1_actual = CoprsLogic.get(None, username, coprname).one() + assert not c1_actual.auto_createrepo + # no actions issued before + assert len(ActionsLogic.get_many().all()) == 0 + + # 2. enabling ACR + self.test_client.post( + "/coprs/{0}/{1}/update/".format(username, coprname), + data={"name": coprname, chroot: "y", "id": copr_id, + "disable_createrepo": "false"}, + follow_redirects=True + ) + self.db.session.commit() + + c1_actual = CoprsLogic.get(None, username, coprname).one() + + # ACR enabled + assert c1_actual.auto_createrepo + # added action + assert len(ActionsLogic.get_many().all()) > 0 + action = ActionsLogic.get_many(action_type=ActionTypeEnum("createrepo")).one() + + data_dict = json.loads(action.data) + assert data_dict["username"] == username + assert data_dict["projectname"] == coprname +
class TestCoprApplyForPermissions(CoprsTestCase):
copr-commits@lists.fedorahosted.org