Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 045dce0b7b5ad547b803bdbe10892134ca8868d8 Author: Bohuslav Kabrda bkabrda@redhat.com Date: Fri Feb 15 15:08:42 2013 +0100
Add copr_created signal
coprs_frontend/coprs/logic/coprs_logic.py | 2 ++ coprs_frontend/coprs/signals.py | 1 + .../tests/test_views/test_coprs_ns/test_general.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py index 0a1d373..f124006 100644 --- a/coprs_frontend/coprs/logic/coprs_logic.py +++ b/coprs_frontend/coprs/logic/coprs_logic.py @@ -4,6 +4,7 @@ from coprs import db from coprs import exceptions from coprs import helpers from coprs import models +from coprs import signals from coprs import whoosheers
class CoprsLogic(object): @@ -80,6 +81,7 @@ class CoprsLogic(object): if check_for_duplicates and cls.exists_for_current_user(user, copr.name).all(): raise exceptions.DuplicateException( 'Copr: "{0}" already exists'.format(copr.name)) + signals.copr_created.send(cls, copr=copr) db.session.add(copr)
@classmethod diff --git a/coprs_frontend/coprs/signals.py b/coprs_frontend/coprs/signals.py index cc9b996..47c990c 100644 --- a/coprs_frontend/coprs/signals.py +++ b/coprs_frontend/coprs/signals.py @@ -3,3 +3,4 @@ import blinker coprs_signals = blinker.Namespace()
build_finished = coprs_signals.signal('build-finished') +copr_created = coprs_signals.signal('copr-created') diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py index f57ecde..572bfef 100644 --- a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py +++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py @@ -1,5 +1,7 @@ import flask
+from coprs.signals import copr_created + from tests.coprs_test_case import CoprsTestCase
class TestCoprsShow(CoprsTestCase): @@ -72,6 +74,20 @@ class TestCoprNew(CoprsTestCase): # make sure no initial build was submitted assert self.models.Build.query.first() == None
+ def test_copr_new_emits_signal(self, f_users, f_mock_chroots, f_db): + with self.tc as c: + with c.session_transaction() as s: + s['openid'] = self.u1.openid_name + # TODO: this should probably be mocked... + signals_received = [] + def test_receiver(sender, **kwargs): + signals_received.append(kwargs['copr']) + copr_created.connect(test_receiver) + r = c.post('/coprs/new/', data={'name': 'foo', 'fedora-rawhide-i386': 'y', 'arches': ['i386']}, follow_redirects=True) + assert len(signals_received) == 1 + assert signals_received[0].name == 'foo' + + def test_copr_new_exists_for_another_user(self, f_users, f_coprs, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s:
copr-devel@lists.fedorahosted.org