Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
---------------------------------------------------------------
commit 405cb8314d91c23acff789350ffcfa3c8d689476
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 12:33:50 2012 +0100
More builds tests and minor fixes
---------------------------------------------------------------
wsgi/coprs/views/coprs_ns/coprs_builds.py | 4 +-
wsgi/tests/test_views/test_coprs_ns/test_builds.py | 62 +++++++++++++++++++-
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/wsgi/coprs/views/coprs_ns/coprs_builds.py
b/wsgi/coprs/views/coprs_ns/coprs_builds.py
index 1f1ac53..10268fb 100644
--- a/wsgi/coprs/views/coprs_ns/coprs_builds.py
+++ b/wsgi/coprs/views/coprs_ns/coprs_builds.py
@@ -56,7 +56,7 @@ def copr_add_build(username, coprname):
return flask.render_template('coprs/detail.html', copr = copr, form =
form)
-@coprs_ns.route('/detail/<username>/<coprname>/cancel_build/<int:build_id>/')
+@coprs_ns.route('/detail/<username>/<coprname>/cancel_build/<int:build_id>/',
methods = ['POST'])
@login_required
def copr_cancel_build(username, coprname, build_id):
# only the user who ran the build can cancel it
@@ -66,7 +66,7 @@ def copr_cancel_build(username, coprname, build_id):
try:
builds_logic.BuildsLogic.cancel_build(flask.g.user, build)
except exceptions.InsufficientRightsException as ex:
- flask.flask(ex.message)
+ flask.flash(ex.message)
else:
db.session.commit()
flask.flash('Build was canceled')
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_builds.py
b/wsgi/tests/test_views/test_coprs_ns/test_builds.py
index 857fb61..0408ccf 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_builds.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_builds.py
@@ -16,6 +16,64 @@ class TestCoprAddBuild(CoprsTestCase):
self.db.session.add_all([self.u1, self.c1])
r = c.post('/coprs/detail/{0}/{1}/add_build/'.format(self.u1.name,
self.c1.name),
- data = {'pkgs': 'http://foo.bar'},
+ data = {'pkgs': 'http://testing'},
follow_redirects = True)
- assert len(self.models.Build.query.all()) == 1
+ assert self.models.Build.query.first().pkgs == 'http://testing'
+
+ def test_copr_allowed_user_can_add_build(self, f_users, f_coprs,
f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u1.openid_name
+
+ self.db.session.add_all([self.u2, self.c2])
+ r = c.post('/coprs/detail/{0}/{1}/add_build/'.format(self.u2.name,
self.c2.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert self.models.Build.query.first().pkgs == 'http://testing'
+
+ def test_copr_not_yet_allowed_user_cant_add_build(self, f_users, f_coprs,
f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u1.openid_name
+
+ self.db.session.add_all([self.u2, self.c3])
+ r = c.post('/coprs/detail/{0}/{1}/add_build/'.format(self.u2.name,
self.c3.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert not self.models.Build.query.first()
+
+ def test_copr_user_without_permission_cant_add_build(self, f_users, f_coprs,
f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u3.openid_name
+
+ self.db.session.add_all([self.u1, self.c1])
+ r = c.post('/coprs/detail/{0}/{1}/add_build/'.format(self.u1.name,
self.c1.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert not self.models.Build.query.first()
+
+class TestCoprCancelBuild(CoprsTestCase):
+ def test_copr_build_submitter_can_cancel_build(self, f_users, f_coprs, f_builds):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u1.openid_name
+
+ self.db.session.add_all([self.u1, self.c1, self.b1])
+ r =
c.post('/coprs/detail/{0}/{1}/cancel_build/{2}/'.format(self.u1.name,
self.c1.name, self.b1.id),
+ data = {},
+ follow_redirects = True)
+ self.db.session.add(self.b1)
+ assert self.b1.canceled == True
+
+ def test_copr_build_non_submitter_can_cancel_build(self, f_users, f_coprs,
f_builds):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u1, self.c1, self.b1])
+ r =
c.post('/coprs/detail/{0}/{1}/cancel_build/{2}/'.format(self.u1.name,
self.c1.name, self.b1.id),
+ data = {},
+ follow_redirects = True)
+ self.db.session.add(self.b1)
+ assert self.b1.canceled == False