[copr] bkabrda-workspace: Ask fedorapeople for mail, too (e19fa97)
by bkabrda@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit e19fa97a7e3f90fa18a7c973ccffb241a58d3ccb
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Mon Nov 26 08:11:17 2012 +0100
Ask fedorapeople for mail, too
>---------------------------------------------------------------
wsgi/coprs/views/misc.py | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/wsgi/coprs/views/misc.py b/wsgi/coprs/views/misc.py
index 224e8eb..3836a90 100644
--- a/wsgi/coprs/views/misc.py
+++ b/wsgi/coprs/views/misc.py
@@ -19,10 +19,7 @@ def login():
if flask.request.method == 'POST':
fasusername = flask.request.form.get('fasuname')
if fasusername:
- return oid.try_login('http://{0}.id.fedoraproject.org/'.format(fasusername))
- openid = flask.request.form.get('openid')
- if openid:
- return oid.try_login(openid)
+ return oid.try_login('http://{0}.id.fedoraproject.org/'.format(fasusername), ask_for = ["email"])
return flask.render_template('login.html',
next=oid.get_next_url(),
error=oid.fetch_error())
@@ -33,7 +30,7 @@ def create_or_login(resp):
flask.session['openid'] = resp.identity_url
user = models.User.query.filter(models.User.openid_name == resp.identity_url).first()
if not user: # create if not created already
- user = models.User(openid_name = resp.identity_url)
+ user = models.User(openid_name = resp.identity_url, mail = resp.email)
db.session.add(user)
db.session.commit()
flask.flash(u'Welcome, {0}'.format(user.name))
11 years, 5 months
[copr] bkabrda-workspace: Add some more data that we may use in future, regenerate the alembic initial DB setup (noone is using this, so no migrations are needed yet) (36c1716)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 36c17162b573ba930e172251ea80081972cc6bc9
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Mon Nov 26 08:04:57 2012 +0100
Add some more data that we may use in future, regenerate the alembic initial DB setup (noone is using this, so no migrations are needed yet)
>---------------------------------------------------------------
...b_setup.py => 2d24d28534b6_initial_db_setup.py} | 9 ++++++---
wsgi/coprs/models.py | 3 +++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/wsgi/alembic/versions/2999fd4de2a7_initial_db_setup.py b/wsgi/alembic/versions/2d24d28534b6_initial_db_setup.py
similarity index 90%
rename from wsgi/alembic/versions/2999fd4de2a7_initial_db_setup.py
rename to wsgi/alembic/versions/2d24d28534b6_initial_db_setup.py
index 8c0f24f..8ca01d7 100644
--- a/wsgi/alembic/versions/2999fd4de2a7_initial_db_setup.py
+++ b/wsgi/alembic/versions/2d24d28534b6_initial_db_setup.py
@@ -1,13 +1,13 @@
"""Initial DB setup
-Revision ID: 2999fd4de2a7
+Revision ID: 2d24d28534b6
Revises: None
-Create Date: 2012-11-19 13:09:17.167104
+Create Date: 2012-11-26 08:02:34.063991
"""
# revision identifiers, used by Alembic.
-revision = '2999fd4de2a7'
+revision = '2d24d28534b6'
down_revision = None
from alembic import op
@@ -19,7 +19,9 @@ def upgrade():
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('openid_name', sa.String(length=100), nullable=False),
+ sa.Column('mail', sa.String(length=150), nullable=False),
sa.Column('proven', sa.Boolean(), nullable=True),
+ sa.Column('admin', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('copr',
@@ -27,6 +29,7 @@ def upgrade():
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('chroots', sa.Text(), nullable=False),
sa.Column('repos', sa.Text(), nullable=True),
+ sa.Column('created_on', sa.Integer(), nullable=True),
sa.Column('build_count', sa.Integer(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
diff --git a/wsgi/coprs/models.py b/wsgi/coprs/models.py
index b36315e..3e4f3ae 100644
--- a/wsgi/coprs/models.py
+++ b/wsgi/coprs/models.py
@@ -50,7 +50,9 @@ class Serializer(object):
class User(db.Model, Serializer):
id = db.Column(db.Integer, primary_key = True)
openid_name = db.Column(db.String(100), nullable = False)
+ mail = db.Column(db.String(150), nullable = False)
proven = db.Column(db.Boolean, default = False)
+ admin = db.Column(db.Boolean, default = False)
@property
def name(self):
@@ -86,6 +88,7 @@ class Copr(db.Model, Serializer):
name = db.Column(db.String(100), nullable = False)
chroots = db.Column(db.Text, nullable = False)
repos = db.Column(db.Text)
+ created_on = db.Column(db.Integer)
# duplicate information, but speeds up a lot and makes queries simpler
build_count = db.Column(db.Integer, default = 0)
11 years, 5 months
[copr] bkabrda-workspace: More builds tests and minor fixes (405cb83)
by bkabrda@fedorahosted.org
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)
-(a)coprs_ns.route('/detail/<username>/<coprname>/cancel_build/<int:build_id>/')
+(a)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
11 years, 5 months
[copr] bkabrda-workspace: Fix the query to really be filtered by copr (bdfbe81)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit bdfbe810d40603284b0755e9898a4d5f0035898d
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 12:16:03 2012 +0100
Fix the query to really be filtered by copr
>---------------------------------------------------------------
wsgi/coprs/logic/builds_logic.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/wsgi/coprs/logic/builds_logic.py b/wsgi/coprs/logic/builds_logic.py
index f0d297d..4c87c0a 100644
--- a/wsgi/coprs/logic/builds_logic.py
+++ b/wsgi/coprs/logic/builds_logic.py
@@ -20,7 +20,7 @@ class BuildsLogic(object):
# if we get copr, query by its id
if copr:
- query.filter(models.Build.copr == copr)
+ query = query.filter(models.Build.copr == copr)
elif username and coprname:
query = query.join(models.Build.copr).\
options(db.contains_eager(models.Build.copr)).\
11 years, 5 months
[copr] bkabrda-workspace: Some initial builds tests and removal of unnecessary fixtures (3122b10)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 3122b10f886a0229e3bcdb8d3cfd93e69894d5cf
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 12:15:29 2012 +0100
Some initial builds tests and removal of unnecessary fixtures
>---------------------------------------------------------------
wsgi/tests/coprs_test_case.py | 3 --
wsgi/tests/test_views/test_coprs_ns/test_builds.py | 21 ++++++++++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/wsgi/tests/coprs_test_case.py b/wsgi/tests/coprs_test_case.py
index a70d721..297b6c8 100644
--- a/wsgi/tests/coprs_test_case.py
+++ b/wsgi/tests/coprs_test_case.py
@@ -51,9 +51,6 @@ class CoprsTestCase(object):
self.b3 = models.Build(copr = self.c2, user = self.u2, chroots = self.c2.chroots, submitted_on = 10)
self.b4 = models.Build(copr = self.c2, user = self.u2, chroots = self.c2.chroots, submitted_on = 100)
- self.cp1 = models.CoprPermission(copr = self.c2, user = self.u2, approved = True)
- self.cp2 = models.CoprPermission(copr = self.c3, user = self.u2, approved = False)
-
self.db.session.add_all([self.b1, self.b2, self.b3, self.b4])
self.db.session.commit()
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_builds.py b/wsgi/tests/test_views/test_coprs_ns/test_builds.py
new file mode 100644
index 0000000..857fb61
--- /dev/null
+++ b/wsgi/tests/test_views/test_coprs_ns/test_builds.py
@@ -0,0 +1,21 @@
+import flask
+
+from tests.coprs_test_case import CoprsTestCase
+
+class TestCoprShowBuilds(CoprsTestCase):
+ def test_copr_show_builds(self, f_users, f_coprs, f_builds):
+ r = self.tc.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name))
+ print r.data
+ assert r.data.count('<tr class=build-') == 2
+
+class TestCoprAddBuild(CoprsTestCase):
+ def test_copr_owner_can_add_build(self, f_users, f_coprs):
+ 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])
+ r = c.post('/coprs/detail/{0}/{1}/add_build/'.format(self.u1.name, self.c1.name),
+ data = {'pkgs': 'http://foo.bar'},
+ follow_redirects = True)
+ assert len(self.models.Build.query.all()) == 1
11 years, 5 months
[copr] bkabrda-workspace: More tests (a94e877)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit a94e87767843afe7d15eb8eabe7c76c802707eaf
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 11:36:04 2012 +0100
More tests
>---------------------------------------------------------------
wsgi/tests/coprs_test_case.py | 2 +-
.../tests/test_views/test_coprs_ns/test_general.py | 58 +++++++++++++++++++-
2 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/wsgi/tests/coprs_test_case.py b/wsgi/tests/coprs_test_case.py
index ea4903e..a70d721 100644
--- a/wsgi/tests/coprs_test_case.py
+++ b/wsgi/tests/coprs_test_case.py
@@ -60,7 +60,7 @@ class CoprsTestCase(object):
@pytest.fixture
def f_copr_permissions(self):
self.cp1 = models.CoprPermission(copr = self.c2, user = self.u1, approved = True)
- self.cp2 = models.CoprPermission(copr = self.c3, user = self.u2, approved = False)
+ self.cp2 = models.CoprPermission(copr = self.c3, user = self.u3, approved = False)
self.cp3 = models.CoprPermission(copr = self.c3, user = self.u1, approved = False)
self.db.session.add_all([self.cp1, self.cp2, self.cp3])
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_general.py b/wsgi/tests/test_views/test_coprs_ns/test_general.py
index e5f6478..4eb54c4 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_general.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_general.py
@@ -112,7 +112,7 @@ class TestCoprDetail(CoprsTestCase):
def test_copr_detail_contains_permissions(self, f_users, f_coprs, f_copr_permissions):
r = self.tc.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c3.name))
assert '<table class=permissions' in r.data
- assert '<tr><td>{0}'.format(self.u2.name) in r.data
+ assert '<tr><td>{0}'.format(self.u3.name) in r.data
assert '<tr><td>{0}'.format(self.u1.name) in r.data
def test_copr_detail_doesnt_contain_forms_for_anonymous_user(self, f_users, f_coprs):
@@ -158,6 +158,17 @@ class TestCoprEdit(CoprsTestCase):
# to the precise format of the tag
assert '<input hidden id="id" name="id" type="hidden" value="{0}">'.format(self.c1.id) in r.data
+ def test_edit_has_correct_permissions_form(self, f_users, f_coprs, f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u2, self.c3])
+ r = c.get('/coprs/detail/{0}/{1}/edit/'.format(self.u2.name, self.c3.name))
+ assert '<input id="user_3" name="user_3" type="checkbox" value="y">' in r.data
+ assert '<input id="user_1" name="user_1" type="checkbox" value="y">' in r.data
+
+
class TestCoprUpdate(CoprsTestCase):
def test_update_no_changes(self, f_users, f_coprs):
with self.tc as c:
@@ -179,7 +190,6 @@ class TestCoprApplyForBuilding(CoprsTestCase):
self.db.session.add_all([self.u1, self.u2, self.c1])
r = c.post('/coprs/detail/{0}/{1}/apply_for_building/'.format(self.u1.name, self.c1.name),
follow_redirects = True)
- print r.data
assert 'You have successfuly applied' in r.data
self.db.session.add_all([self.u1, self.u2, self.c1])
@@ -187,3 +197,47 @@ class TestCoprApplyForBuilding(CoprsTestCase):
filter(self.models.CoprPermission.copr_id == self.c1.id).\
first()
assert not new_perm.approved
+
+class TestCoprGiveUpBuilding(CoprsTestCase):
+ def test_give_up(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.u1, self.u2, self.c2])
+ r = c.post('/coprs/detail/{0}/{1}/give_up_building/'.format(self.u2.name, self.c2.name),
+ follow_redirects = True)
+ assert 'You have successfuly given up' in r.data
+
+ self.db.session.add_all([self.u1, self.u2, self.c2])
+ exists = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u1.id).\
+ filter(self.models.CoprPermission.copr_id == self.c2.id).\
+ first()
+ assert not exists
+
+class TestCoprUpdatePermissions(CoprsTestCase):
+ def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u2, self.c2])
+ # Although it shouldn't be needed, preset some data: https://github.com/ajford/flask-wtf/issues/55
+ r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c2.name),
+ data = {'csrf_token': u'20121123111948##1653cb2ef73cb9f7b4670472df7354416e61cf2d'},
+ follow_redirects = True)
+ self.db.session.add_all([self.u1])
+ assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u1.name, 'True') not in r.data
+
+ def test_update_more_permissions(self, f_users, f_coprs, f_copr_permissions):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u2, self.c3])
+ r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
+ data = {'user_1': 'y', 'user_3': 'y'},
+ follow_redirects = True)
+ self.db.session.add_all([self.u1, self.u3])
+ assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u1.name, 'True') in r.data
+ assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u3.name, 'True') in r.data
11 years, 5 months
[copr] bkabrda-workspace: Don't use with_permissions for getting a copr (using .first() on it results in just one permission) (4637aa1)
by bkabrda@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 4637aa1d3debc35586220cfd68aab4f81410367b
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 10:21:30 2012 +0100
Don't use with_permissions for getting a copr (using .first() on it results in just one permission)
>---------------------------------------------------------------
wsgi/coprs/logic/coprs_logic.py | 11 ++++++-----
wsgi/coprs/views/coprs_ns/coprs_general.py | 10 ++++++----
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/wsgi/coprs/logic/coprs_logic.py b/wsgi/coprs/logic/coprs_logic.py
index c2b967d..f378de8 100644
--- a/wsgi/coprs/logic/coprs_logic.py
+++ b/wsgi/coprs/logic/coprs_logic.py
@@ -7,7 +7,6 @@ class CoprsLogic(object):
@classmethod
def get(cls, user, username, coprname, **kwargs):
with_builds = kwargs.get('with_builds', False)
- with_permissions = kwargs.get('with_permissions', False)
query = db.session.query(models.Copr).\
join(models.Copr.owner).\
@@ -20,10 +19,6 @@ class CoprsLogic(object):
options(db.contains_eager(models.Copr.builds)).\
order_by(models.Build.submitted_on.desc())
- if with_permissions:
- query = query.outerjoin(models.Copr.copr_permissions).\
- options(db.contains_eager(models.Copr.copr_permissions))
-
return query
@classmethod
@@ -77,6 +72,12 @@ class CoprsPermissionLogic(object):
return query
@classmethod
+ def get_for_copr(cls, user, copr):
+ query = models.CoprPermission.query.filter(models.CoprPermission.copr == copr)
+
+ return query
+
+ @classmethod
def new(cls, user, copr_permission):
db.session.add(copr_permission)
diff --git a/wsgi/coprs/views/coprs_ns/coprs_general.py b/wsgi/coprs/views/coprs_ns/coprs_general.py
index a281019..c22fc6f 100644
--- a/wsgi/coprs/views/coprs_ns/coprs_general.py
+++ b/wsgi/coprs/views/coprs_ns/coprs_general.py
@@ -72,24 +72,26 @@ def copr_new():
def copr_detail(username, coprname):
form = forms.BuildForm()
try: # query[0:10][0] will raise an index error, if Copr doesn't exist
- query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname, with_builds = True, with_permissions = True)
+ query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname, with_builds = True)
copr = query[0:10][0]# we retrieved all builds, but we got one copr in a list...
except IndexError:
return page_not_found('Copr with name {0} does not exist.'.format(coprname))
- return flask.render_template('coprs/detail.html', copr = copr, form = form, permissions = copr.copr_permissions)
+ permissions = coprs_logic.CoprsPermissionLogic.get_for_copr(flask.g.user, copr).all()
+ return flask.render_template('coprs/detail.html', copr = copr, form = form, permissions = permissions)
@coprs_ns.route('/detail/<username>/<coprname>/edit/')
@login_required
def copr_edit(username, coprname):
- query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname, with_permissions = True)
+ query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname)
copr = query.first()
+
if not copr:
return page_not_found('Copr with name {0} does not exist.'.format(coprname))
form = forms.CoprForm(obj = copr)
- permissions = copr.copr_permissions
+ permissions = coprs_logic.CoprsPermissionLogic.get_for_copr(flask.g.user, copr).all()
permissions_form = forms.DynamicPermissionsFormFactory.create_form_cls(permissions)()
return flask.render_template('coprs/edit.html',
11 years, 5 months
[copr] bkabrda-workspace: Fix the form target in copr_permissions_form (036c99a)
by bkabrda@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 036c99a182143e0f86df84e487789a6e3fc4803d
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Nov 23 09:49:58 2012 +0100
Fix the form target in copr_permissions_form
>---------------------------------------------------------------
wsgi/coprs/templates/coprs/_coprs_forms.html | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/wsgi/coprs/templates/coprs/_coprs_forms.html b/wsgi/coprs/templates/coprs/_coprs_forms.html
index f655ffa..0031919 100644
--- a/wsgi/coprs/templates/coprs/_coprs_forms.html
+++ b/wsgi/coprs/templates/coprs/_coprs_forms.html
@@ -17,7 +17,7 @@
{% macro copr_permissions_form(form, copr, permissions) %}
{% if permissions %}
- <form action="{{ url_for('coprs_ns.copr_update_permissions', name = copr.name) }}" method=post>
+ <form action="{{ url_for('coprs_ns.copr_update_permissions', username = copr.owner.name, coprname = copr.name) }}" method=post>
{{ form.csrf_token }}
<table class=permissions-table>
<tr><th>Username</th><th>Allowed to build</th></tr>
11 years, 5 months
[copr] bkabrda-workspace: Few more tests and a connected fix in a url route (c7ce8df)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit c7ce8df8ca245a672cd49803a1a8a586ba9e36af
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Wed Nov 21 15:08:20 2012 +0100
Few more tests and a connected fix in a url route
>---------------------------------------------------------------
wsgi/coprs/views/coprs_ns/coprs_general.py | 2 +-
.../tests/test_views/test_coprs_ns/test_general.py | 27 ++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/wsgi/coprs/views/coprs_ns/coprs_general.py b/wsgi/coprs/views/coprs_ns/coprs_general.py
index 077609e..a281019 100644
--- a/wsgi/coprs/views/coprs_ns/coprs_general.py
+++ b/wsgi/coprs/views/coprs_ns/coprs_general.py
@@ -123,7 +123,7 @@ def copr_update(username, coprname):
return flask.render_template('coprs/edit.html', copr = copr, form = form)
-(a)coprs_ns.route('/detail/<username>/<coprname>/apply_for_building', methods = ['POST'])
+(a)coprs_ns.route('/detail/<username>/<coprname>/apply_for_building/', methods = ['POST'])
@login_required
def copr_apply_for_building(username, coprname):
copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_general.py b/wsgi/tests/test_views/test_coprs_ns/test_general.py
index af8f06c..e5f6478 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_general.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_general.py
@@ -128,6 +128,15 @@ class TestCoprDetail(CoprsTestCase):
r = c.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name))
assert '<input type=submit value="Apply for building">' in r.data
+ def test_copr_detail_doesnt_allow_owner_to_ask_for_building(self, f_users, f_coprs):
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u2, self.c2])
+ r = c.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name))
+ assert '<input type=submit value="Apply for building">' not in r.data
+
def test_copr_detail_allows_giving_up_building(self, f_users, f_coprs, f_copr_permissions):
with self.tc as c:
with c.session_transaction() as s:
@@ -160,3 +169,21 @@ class TestCoprUpdate(CoprsTestCase):
data = {'name': self.c1.name, 'release': self.c1.release, 'arches': self.c1.arches, 'id': self.c1.id},
follow_redirects = True)
assert 'Copr was updated successfully' in r.data
+
+class TestCoprApplyForBuilding(CoprsTestCase):
+ def test_apply(self, f_users, f_coprs):
+ 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.u2, self.c1])
+ r = c.post('/coprs/detail/{0}/{1}/apply_for_building/'.format(self.u1.name, self.c1.name),
+ follow_redirects = True)
+ print r.data
+ assert 'You have successfuly applied' in r.data
+
+ self.db.session.add_all([self.u1, self.u2, self.c1])
+ new_perm = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u2.id).\
+ filter(self.models.CoprPermission.copr_id == self.c1.id).\
+ first()
+ assert not new_perm.approved
11 years, 5 months
[copr] bkabrda-workspace: Some more tests, properly refresh instances after test client methods (90e7aae)
by bkabrda@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 90e7aae1352681a4e045a96154e388d864a5227c
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Wed Nov 21 14:32:20 2012 +0100
Some more tests, properly refresh instances after test client methods
>---------------------------------------------------------------
.../tests/test_views/test_coprs_ns/test_general.py | 63 ++++++++++++++------
1 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_general.py b/wsgi/tests/test_views/test_coprs_ns/test_general.py
index 4ceb2f2..af8f06c 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_general.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_general.py
@@ -16,6 +16,7 @@ class TestCoprsOwned(CoprsTestCase):
with c.session_transaction() as s:
s['openid'] = self.u3.openid_name
+ self.db.session.add(self.u3)
r = c.get('/coprs/owned/{0}/'.format(self.u3.name))
assert 'No entries' in r.data
@@ -24,6 +25,7 @@ class TestCoprsOwned(CoprsTestCase):
with c.session_transaction() as s:
s['openid'] = self.u1.openid_name
+ self.db.session.add(self.u1)
r = c.get('/coprs/owned/{0}/'.format(self.u1.name))
assert r.data.count('<div class=copr>') == 1
@@ -33,25 +35,26 @@ class TestCoprsAllowed(CoprsTestCase):
with c.session_transaction() as s:
s['openid'] = self.u3.openid_name
+ self.db.session.add(self.u3)
r = c.get('/coprs/allowed/{0}/'.format(self.u3.name))
assert 'No entries' in r.data
def test_allowed_one(self, f_users, f_coprs, f_copr_permissions):
- uname = self.u1.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u2.openid_name
- r = c.get('/coprs/allowed/{0}/'.format(uname))
+ self.db.session.add(self.u1)
+ r = c.get('/coprs/allowed/{0}/'.format(self.u1.name))
assert r.data.count('<div class=copr>') == 1
def test_allowed_one_but_asked_for_one_more(self, f_users, f_coprs, f_copr_permissions):
- uname = self.u1.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u1.openid_name
- r = c.get('/coprs/allowed/{0}/'.format(uname))
+ self.db.session.add(self.u1)
+ r = c.get('/coprs/allowed/{0}/'.format(self.u1.name))
assert r.data.count('<div class=copr>') == 1
class TestCoprNew(CoprsTestCase):
@@ -65,29 +68,31 @@ class TestCoprNew(CoprsTestCase):
assert "New entry was successfully posted" in r.data
def test_copr_new_exists_for_another_user(self, f_users, f_coprs):
- name = self.c1.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u3.openid_name
- foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == name).all())
+ self.db.session.add(self.c1)
+ foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all())
assert foocoprs > 0
- r = c.post('/coprs/new/', data = {'name': name, 'release': 'fedora-rawhide', 'arches': ['i386']}, follow_redirects = True)
- assert len(self.models.Copr.query.filter(self.models.Copr.name == name).all()) == foocoprs + 1
+ r = c.post('/coprs/new/', data = {'name': self.c1.name, 'release': 'fedora-rawhide', 'arches': ['i386']}, follow_redirects = True)
+ self.db.session.add(self.c1)
+ assert len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all()) == foocoprs + 1
assert "New entry was successfully posted" in r.data
def test_copr_new_exists_for_this_user(self, f_users, f_coprs):
- name = self.c1.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u1.openid_name
- foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == name).all())
+ self.db.session.add(self.c1)
+ foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all())
assert foocoprs > 0
- r = c.post('/coprs/new/', data = {'name': name, 'release': 'fedora-rawhide', 'arches': ['i386']}, follow_redirects = True)
- assert len(self.models.Copr.query.filter(self.models.Copr.name == name).all()) == foocoprs
+ r = c.post('/coprs/new/', data = {'name': self.c1.name, 'release': 'fedora-rawhide', 'arches': ['i386']}, follow_redirects = True)
+ self.db.session.add(self.c1)
+ assert len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all()) == foocoprs
assert "You already have copr named" in r.data
class TestCoprDetail(CoprsTestCase):
@@ -115,21 +120,43 @@ class TestCoprDetail(CoprsTestCase):
assert '<form' not in r.data
def test_copr_detail_allows_asking_for_building(self, f_users, f_coprs):
- uname = self.u2.name
- cname = self.c2.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u1.openid_name
- r = c.get('/coprs/detail/{0}/{1}/'.format(uname, cname))
+ self.db.session.add_all([self.u2, self.c2])
+ r = c.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name))
assert '<input type=submit value="Apply for building">' in r.data
def test_copr_detail_allows_giving_up_building(self, f_users, f_coprs, f_copr_permissions):
- uname = self.u2.name
- cname = self.c2.name
with self.tc as c:
with c.session_transaction() as s:
s['openid'] = self.u1.openid_name
- r = c.get('/coprs/detail/{0}/{1}/'.format(uname, cname))
+ self.db.session.add_all([self.u2, self.c2])
+ r = c.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name))
assert '<input type=submit value="Give up building">' in r.data
+
+class TestCoprEdit(CoprsTestCase):
+ def test_edit_prefills_id(self, f_users, f_coprs):
+ 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])
+ r = c.get('/coprs/detail/{0}/{1}/edit/'.format(self.u1.name, self.c1.name))
+ # TODO: use some kind of html parsing library to look for the hidden input, this ties us
+ # to the precise format of the tag
+ assert '<input hidden id="id" name="id" type="hidden" value="{0}">'.format(self.c1.id) in r.data
+
+class TestCoprUpdate(CoprsTestCase):
+ def test_update_no_changes(self, f_users, f_coprs):
+ 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])
+ r = c.post('/coprs/detail/{0}/{1}/update/'.format(self.u1.name, self.c1.name),
+ data = {'name': self.c1.name, 'release': self.c1.release, 'arches': self.c1.arches, 'id': self.c1.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
11 years, 5 months