Copr URLs
by Pierre-Yves Chibon
Hi all,
Something, I have been discussing with Tomas last week but not with
Slavek or the list, is the URLs we have in copr.
For example:
front page: /
detail of a copr: /coprs/detail/toshio/packagedb/
copr's permissions: /coprs/detail/toshio/packagedb/permissions/
copr's builds: /coprs/detail/toshio/packagedb/builds/
someone's copr: /coprs/owned/toshio/
I basically would like to change a couple of things. At the moment when
I'm looking at toshio's packagedb repos there is no way to (from the
url) easily go back to the list of toshio's copr.
So I would like to propose:
/ > home
/coprs/ > list all the repos (same as home, atm)
/coprs/<user>/ > list someone's copr
/coprs/<user>/<repo>/ > the detail of this copr
/coprs/<user>/<repo>/{permissions,builds,...}/ > same as now the
permissions, builds or other page for this repo (the repo file for yum
could end up here as /coprs/<user>/<repo>/repo/ )
It's something I have in mind but would like to discuss before doing
(unless someone beats me to it).
So, what do you think?
Pierre
10 years, 2 months
Network setup of builders
by Miroslav Suchý
Seth,
is is possible to set up builders that the they will have very limited
network connections? Probably just to copr-be or copr-fe?
I'm asking because currently you can do nearly everything on builder.
For example I made evil.spec, which have
%prep
wget http://www.googl.com -O index.html
cat index.html
Which is executed without problem:
http://copr-be.cloud.fedoraproject.org/results/msuchy/copr/fedora-18-x86_...
Of course instead wget I can e.g start my own ssh server or botnet. And
I will own that machine until our timeout expire.
On Koji we do not have such problem because builders are configured to
not allow any internet connections.
Right now we need internet connection on builders, because they need to
download src.rpm. But this can be fixed that user will not provide url
to src.rpm, but they will upload it to cloud-fe. This will be save,
because we will store and behave to src.rpm just as binary file and only
store it in some directory and not parse it.
Builder can then pick it up from copr-fe. Either by downloading from
some http export or via nfs read only share.
Opinions?
Mirek
10 years, 5 months
opening up and expanding.
by Seth Vidal
Sgallagh suggested opening up the current functionality of coprs to
proven packagers - to discover more bugs and to help us figure out what
else is needed.
I'd like to suggest two things:
1. open up what we have to provenpackagers as sgallagh suggested
2. setting up a second 'dev' instance so we can test there before
rolling over into the more public instance. - Also it will help us
verify the setup process.
I can easily setup a be and fe dev instances in the private openstack
cloud we have setup. It would also let us refresh those instances and
be sure we're still functional.
-sv
10 years, 5 months
[copr] master: restart apache after upgrade of frontend (f7fc5b2)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit f7fc5b24d802a8da0a094e0b423c74a4d38c6987
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Jun 28 20:07:09 2013 +0200
restart apache after upgrade of frontend
>---------------------------------------------------------------
copr.spec | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/copr.spec b/copr.spec
index 98be622..3d2e009 100644
--- a/copr.spec
+++ b/copr.spec
@@ -128,6 +128,9 @@ getent passwd copr-fe >/dev/null || \
useradd -r -g copr-fe -G copr-fe -d %{_datadir}/copr/coprs_frontend -s /bin/bash -c "COPR frontend user" copr-fe
/usr/bin/passwd -l copr-fe >/dev/null
+%post frontend
+service httpd condrestart
+
%files backend
%doc LICENSE README
%dir %{_datadir}/copr
10 years, 5 months
[copr] master: own directory where backend put results (d19435a)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit d19435adcbabed8be4f958dbe46e0918cd6e24f7
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Jun 28 19:53:23 2013 +0200
own directory where backend put results
>---------------------------------------------------------------
copr.spec | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/copr.spec b/copr.spec
index c8113a2..98be622 100644
--- a/copr.spec
+++ b/copr.spec
@@ -91,6 +91,10 @@ a2x -d manpage -f manpage man/copr-cli.1.asciidoc
%install
+#backend
+install -d %{buildroot}%{_sharedstatedir}/copr
+install -d %{buildroot}%{_sharedstatedir}/copr/results
+
#frontend
install -d %{buildroot}%{_sysconfdir}
install -d %{buildroot}%{_datadir}/copr/coprs_frontend
@@ -127,6 +131,8 @@ useradd -r -g copr-fe -G copr-fe -d %{_datadir}/copr/coprs_frontend -s /bin/bash
%files backend
%doc LICENSE README
%dir %{_datadir}/copr
+%dir %{_sharedstatedir}/copr
+%dir %attr(0755, copr, copr) %{_sharedstatedir}/copr/results
%files frontend
%doc LICENSE coprs.conf.example copr-setup.txt
10 years, 5 months
[copr] master: removal of hidden-file-or-dir /usr/share/copr/coprs_frontend/coprs/logic/.coprs_logic.py.swo (086d99b)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 086d99b4ed34c33899062c7e6c30b94410424c05
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Jun 28 19:26:12 2013 +0200
removal of hidden-file-or-dir /usr/share/copr/coprs_frontend/coprs/logic/.coprs_logic.py.swo
>---------------------------------------------------------------
coprs_frontend/coprs/logic/.coprs_logic.py.swo | Bin 12288 -> 0 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/logic/.coprs_logic.py.swo b/coprs_frontend/coprs/logic/.coprs_logic.py.swo
deleted file mode 100644
index b244106..0000000
Binary files a/coprs_frontend/coprs/logic/.coprs_logic.py.swo and /dev/null differ
10 years, 5 months
[copr] master: copr-backend.noarch: W: spelling-error %description -l en_US latests -> latest, latest's, la tests (34f4272)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 34f42720a027d70d9e6e59b9ceeb6c922459e318
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Jun 28 19:21:24 2013 +0200
copr-backend.noarch: W: spelling-error %description -l en_US latests -> latest, latest's, la tests
>---------------------------------------------------------------
copr.spec | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/copr.spec b/copr.spec
index 088e3f2..c8113a2 100644
--- a/copr.spec
+++ b/copr.spec
@@ -20,7 +20,7 @@ BuildRequires: python-argparse
%description
COPR is lightway Koji. It allows you to create new project in WebUI, and
-submit new builds and COPR will create yum repository from latests builds.
+submit new builds and COPR will create yum repository from latest builds.
%package backend
Summary: Backend for COPR
@@ -37,7 +37,7 @@ Requires: python-requests
%description backend
COPR is lightway Koji. It allows you to create new project in WebUI, and
-submit new builds and COPR will create yum repository from latests builds.
+submit new builds and COPR will create yum repository from latest builds.
This package contains backend.
10 years, 5 months
[copr] master: simplify configuration - introduce /etc/copr/copr*.conf (6e1179e)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 6e1179ed1b270eab35d361f9623532453fce07ab
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Jun 28 18:01:30 2013 +0200
simplify configuration - introduce /etc/copr/copr*.conf
Now config.py contains just defaults. You should put your own configuration
into /etc/copr/copr.conf. Initial file is provided.
Configuration for unit test is taken from /etc/copr/copr_unit_test.conf.
You can always provide your own config by passing COPR_CONFIG environment
variable. E.g:
COPR_CONFIG=/etc/copr/copr_devel.conf ./manage.py
This also allow to preserve user configuration when deploying new version of
copr, while introduce the new defaults.
Direct edit of config.py is not recommended. Especially in production.
>---------------------------------------------------------------
copr-setup.txt | 12 ++++++------
copr.spec | 8 +++++++-
coprs_frontend/config/copr.conf | 29 +++++++++++++++++++++++++++++
coprs_frontend/config/copr_devel.conf | 29 +++++++++++++++++++++++++++++
coprs_frontend/config/copr_unit_test.conf | 29 +++++++++++++++++++++++++++++
coprs_frontend/coprs/__init__.py | 5 +++++
coprs_frontend/coprs/config.py | 2 +-
coprs_frontend/manage.py | 1 +
8 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/copr-setup.txt b/copr-setup.txt
index f5a7ad6..266799d 100644
--- a/copr-setup.txt
+++ b/copr-setup.txt
@@ -66,13 +66,13 @@ Frontend:
- pip install -I SQLAlchemy MarkupSafe
- pip install pytest
-- edit credentials in coprs_frontend/coprs/config.py
+- edit credentials /etc/copr/copr.conf (or /etc/copr/copr-devel.conf for development mode)
- cd /usr/share/copr/coprs_frontend
- configure DB first - see DB section below
# for develop setup do:
-- ./manage.py create_db --alembic alembic.ini
+COPR_CONFIG=/etc/copr/copr_devel.conf ./manage.py create_db --alembic alembic.ini
# for production setup do:
-COPRS_ENVIRON_PRODUCTION=1 ./manage.py create_db --alembic alembic.ini
+./manage.py create_db --alembic alembic.ini
- for developing you can run:
./manage.py runserver -t <FQDN>
@@ -83,7 +83,7 @@ COPRS_ENVIRON_PRODUCTION=1 ./manage.py create_db --alembic alembic.ini
- setenforce 0 (sorry, putting on TODO)
- Add chroots. E.g:
- su - copr-fe -c 'OPRS_ENVIRON_PRODUCTION=1 ./manage.py create_chroot fedora-18-x86_64 fedora-18-i386'
+ su - copr-fe -c './manage.py create_chroot fedora-18-x86_64 fedora-18-i386'
DB config
@@ -95,8 +95,8 @@ SQLite
~~~~~~
- yum install sqlite
-- in file coprs_frontend/coprs/config.py put:
- SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.abspath(DATABASE)
+- in file /etc/copr/copr.conf put:
+ SQLALCHEMY_DATABASE_URI = 'sqlite:////usr/share/copr/data/copr.db'
This will use sqlite db file in /usr/share/copr/data/copr.db (manage.py will create that file)
- Note that you have to either create db as copr-fe user or you have to run:
chown copr-fe:copr-fe /usr/share/copr/data/copr.db
diff --git a/copr.spec b/copr.spec
index 19c40f4..088e3f2 100644
--- a/copr.spec
+++ b/copr.spec
@@ -92,6 +92,7 @@ a2x -d manpage -f manpage man/copr-cli.1.asciidoc
%install
#frontend
+install -d %{buildroot}%{_sysconfdir}
install -d %{buildroot}%{_datadir}/copr/coprs_frontend
install -d %{buildroot}%{_datadir}/copr/data/openid_store
install -d %{buildroot}%{_datadir}/copr/data/openid_store/associations
@@ -102,6 +103,7 @@ install -d %{buildroot}%{_datadir}/copr/data/whooshee/copr_user_whoosheer
cp -a coprs_frontend/* %{buildroot}%{_datadir}/copr/coprs_frontend
mv %{buildroot}%{_datadir}/copr/coprs_frontend/coprs.conf.example ./
+mv %{buildroot}%{_datadir}/copr/coprs_frontend/config %{buildroot}%{_sysconfdir}/copr
rm %{buildroot}%{_datadir}/copr/coprs_frontend/CONTRIBUTION_GUIDELINES
touch %{buildroot}%{_datadir}/copr/data/copr.db
@@ -137,7 +139,11 @@ useradd -r -g copr-fe -G copr-fe -d %{_datadir}/copr/coprs_frontend -s /bin/bash
%{_datadir}/copr/coprs_frontend
%ghost %{_datadir}/copr/data/copr.db
-%config(noreplace)%{_datadir}/copr/coprs_frontend/coprs/config.py
+%{_datadir}/copr/coprs_frontend/coprs/config.py
+
+%defattr(600, copr-fe, copr-fe, 700)
+%dir %{_sysconfdir}/copr
+%config(noreplace) %{_sysconfdir}/copr/*
%files cli
%doc LICENSE README.rst
diff --git a/coprs_frontend/config/copr.conf b/coprs_frontend/config/copr.conf
new file mode 100644
index 0000000..576db7b
--- /dev/null
+++ b/coprs_frontend/config/copr.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+#DATABASE = '/usr/share/copr/data/copr.db'
+#OPENID_STORE = '/usr/share/copr/data/openid_store'
+#WHOOSHEE_DIR = '/usr/share/copr/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://copr-fe:coprpass@/coprdb'
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root@localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+DEBUG = False
+SQLALCHEMY_ECHO = False
+
+##CSRF_ENABLED = True
diff --git a/coprs_frontend/config/copr_devel.conf b/coprs_frontend/config/copr_devel.conf
new file mode 100644
index 0000000..cd9eb32
--- /dev/null
+++ b/coprs_frontend/config/copr_devel.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+#DATABASE = '/usr/share/copr/data/copr.db'
+#OPENID_STORE = '/usr/share/copr/data/openid_store'
+#WHOOSHEE_DIR = '/usr/share/copr/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+#SQLALCHEMY_DATABASE_URI = 'sqlite:////usr/share/copr/data/copr.db'
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root@localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+DEBUG = True
+SQLALCHEMY_ECHO = True
+
+#CSRF_ENABLED = True
diff --git a/coprs_frontend/config/copr_unit_test.conf b/coprs_frontend/config/copr_unit_test.conf
new file mode 100644
index 0000000..0efcc07
--- /dev/null
+++ b/coprs_frontend/config/copr_unit_test.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+DATABASE = '/usr/share/copr/coprs_frontend/tests/data/copr.db'
+OPENID_STORE = '/usr/share/copr/coprs_frontend/tests/data/openid_store'
+WHOOSHEE_DIR = '/usr/share/copr/coprs_frontend/tests/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root@localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+#DEBUG = False
+#SQLALCHEMY_ECHO = False
+
+CSRF_ENABLED = False
diff --git a/coprs_frontend/coprs/__init__.py b/coprs_frontend/coprs/__init__.py
index 103d7e1..bb2157f 100644
--- a/coprs_frontend/coprs/__init__.py
+++ b/coprs_frontend/coprs/__init__.py
@@ -15,6 +15,11 @@ elif 'COPRS_ENVIRON_UNITTEST' in os.environ:
app.config.from_object('coprs.config.UnitTestConfig')
else:
app.config.from_object('coprs.config.DevelopmentConfig')
+if os.environ.get('COPR_CONFIG'):
+ app.config.from_envvar('COPR_CONFIG')
+else:
+ app.config.from_pyfile('/etc/copr/copr.conf', silent=True)
+
oid = OpenID(app, app.config['OPENID_STORE'])
db = SQLAlchemy(app)
diff --git a/coprs_frontend/coprs/config.py b/coprs_frontend/coprs/config.py
index 1b735e4..a84cee6 100644
--- a/coprs_frontend/coprs/config.py
+++ b/coprs_frontend/coprs/config.py
@@ -23,7 +23,7 @@ class Config(object):
API_TOKEN_EXPIRATION = 180
# logging options
- SEND_LOGS_TO = []
+ SEND_LOGS_TO = ['root@localhost']
LOGGING_LEVEL = logging.ERROR
class ProductionConfig(Config):
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index 1b798e9..ab811d8 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -16,6 +16,7 @@ from coprs.logic import coprs_logic
class TestCommand(Command):
def run(self, test_args):
os.environ['COPRS_ENVIRON_UNITTEST'] = '1'
+ os.environ['COPR_CONFIG'] = '/etc/copr/copr_unit_test.conf'
os.environ['PYTHONPATH'] = '.'
subprocess.call(['py.test'] + (test_args or []))
10 years, 5 months
Introduction + [PATCH]
by Robert Kuska
Hi everyone,
my name is Robert Kuska and I would like to start working
on coprs_frontend.
My plan is to start with test suites and documentation and
after successful diving in also contribute and develope
the frontend itself.
I am sending my first patch proposal along with this
introduction as an attachment (It's quite a long). I made a
decorator as a replacement for context managers methods
in tests. I hope it's fine.
Regards
Robert Kuska
rkuska(a)redhat.com
10 years, 5 months
[copr] master: Replace "with" statements with @TransactionDecorator decorator (1269f2d)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 1269f2dfa485d27c9b94929f2a7069027baf1c29
Author: Robert Kuska <rkuska(a)redhat.com>
Date: Thu Jun 27 10:08:07 2013 +0200
Replace "with" statements with @TransactionDecorator decorator
>---------------------------------------------------------------
coprs_frontend/tests/coprs_test_case.py | 45 ++
.../test_views/test_coprs_ns/test_coprs_builds.py | 95 ++--
.../test_views/test_coprs_ns/test_coprs_general.py | 557 +++++++++-----------
3 files changed, 323 insertions(+), 374 deletions(-)
diff --git a/coprs_frontend/tests/coprs_test_case.py b/coprs_frontend/tests/coprs_test_case.py
index 6659bbf..8c5a697 100644
--- a/coprs_frontend/tests/coprs_test_case.py
+++ b/coprs_frontend/tests/coprs_test_case.py
@@ -1,8 +1,10 @@
import base64
import os
import time
+from functools import wraps
import pytest
+import decorator
import coprs
@@ -122,3 +124,46 @@ class CoprsTestCase(object):
result=helpers.BackendResultEnum('success'),
created_on=int(time.time()))
self.db.session.add_all([self.a1, self.a2, self.a3])
+
+
+
+
+class TransactionDecorator(object):
+
+ """
+ This is decorator as a class.
+
+ Its purpose is to replace repetative lines of 'with' statements
+ in test's functions. Everytime you find your self writing test function
+ which uses following 'with's construct:
+
+ with self.tc as test_client:
+ with c.session_transaction() as session:
+ session['openid'] = self.u.openid_name
+
+ where 'u' stands for any user from 'f_users' fixture, use this to decorate
+ your test function:
+
+ @TransactionDecorator('u')
+ def test_function_without_with_statements(self, f_users):
+ # write code as you were in with 'self.tc as test_client' indent
+ # you can also access object 'test_client' through 'self.test_client'
+
+ where decorator parameter ''u'' stands for string representation of any
+ user from 'f_users' fixture from which you wish to store 'openid_name'.
+ Please note that you **must** include 'f_users' fixture in decorated
+ function parameters.
+
+ """
+
+ def __init__(self, user):
+ self.user = user
+
+ def __call__(self, fn):
+ @wraps(fn)
+ def wrapper(fn, fn_self, *args):
+ with fn_self.tc as fn_self.test_client:
+ with fn_self.test_client.session_transaction() as session:
+ session['openid'] = getattr(fn_self, self.user).openid_name
+ return fn(fn_self, *args)
+ return decorator.decorator(wrapper, fn)
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
index 574ca57..f512b18 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
@@ -1,6 +1,6 @@
import flask
-from tests.coprs_test_case import CoprsTestCase
+from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
class TestCoprShowBuilds(CoprsTestCase):
def test_copr_show_builds(self, f_users, f_coprs, f_builds, f_db):
@@ -8,71 +8,56 @@ class TestCoprShowBuilds(CoprsTestCase):
assert r.data.count('<tr class="build-') == 2
class TestCoprAddBuild(CoprsTestCase):
+ @TransactionDecorator('u1')
def test_copr_owner_can_add_build(self, f_users, f_coprs, f_db):
- 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}/new_build/'.format(self.u1.name, self.c1.name),
- data = {'pkgs': 'http://testing'},
- follow_redirects = True)
- assert self.models.Build.query.first().pkgs == 'http://testing'
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/new_build/'.format(self.u1.name, self.c1.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert self.models.Build.query.first().pkgs == 'http://testing'
+ @TransactionDecorator('u1')
def test_copr_allowed_user_can_add_build(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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 = self.test_client.post('/coprs/detail/{0}/{1}/new_build/'.format(self.u2.name, self.c2.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert self.models.Build.query.first().pkgs == 'http://testing'
- self.db.session.add_all([self.u2, self.c2])
- r = c.post('/coprs/detail/{0}/{1}/new_build/'.format(self.u2.name, self.c2.name),
- data = {'pkgs': 'http://testing'},
- follow_redirects = True)
- assert self.models.Build.query.first().pkgs == 'http://testing'
+ @TransactionDecorator('u1')
def test_copr_not_yet_allowed_user_cant_add_build(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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}/new_build/'.format(self.u2.name, self.c3.name),
- data = {'pkgs': 'http://testing'},
- follow_redirects = True)
- assert not self.models.Build.query.first()
+ self.db.session.add_all([self.u2, self.c3])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/new_build/'.format(self.u2.name, self.c3.name),
+ data = {'pkgs': 'http://testing'},
+ follow_redirects = True)
+ assert not self.models.Build.query.first()
+ @TransactionDecorator('u3')
def test_copr_user_without_permission_cant_add_build(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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}/new_build/'.format(self.u1.name, self.c1.name),
- data = {'pkgs': 'http://testing'},
- follow_redirects = True)
- assert not self.models.Build.query.first()
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/new_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):
+
+ @TransactionDecorator('u1')
def test_copr_build_submitter_can_cancel_build(self, f_users, f_coprs, f_builds, f_db):
- 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 = self.test_client.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
- 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
+ @TransactionDecorator('u2')
def test_copr_build_non_submitter_cannot_cancel_build(self, f_users, f_coprs, f_builds, f_db):
- 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
+ self.db.session.add_all([self.u1, self.c1, self.b1])
+ r = self.test_client.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
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
index 906ece1..00551dd 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
@@ -5,7 +5,7 @@ from flexmock import flexmock
from coprs.signals import copr_created
-from tests.coprs_test_case import CoprsTestCase
+from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
class TestCoprsShow(CoprsTestCase):
def test_show_no_entries(self):
@@ -16,140 +16,109 @@ class TestCoprsShow(CoprsTestCase):
assert r.data.count('<div class="copr">') == 3
class TestCoprsOwned(CoprsTestCase):
+ @TransactionDecorator('u3')
def test_owned_none(self, f_users, f_coprs, f_db):
- with self.tc as c:
- 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 coprs...' in r.data
+ self.db.session.add(self.u3)
+ r = self.test_client.get('/coprs/owned/{0}/'.format(self.u3.name))
+ assert 'No coprs...' in r.data
+ @TransactionDecorator('u1')
def test_owned_one(self, f_users, f_coprs, f_db):
- with self.tc as c:
- 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
+ self.db.session.add(self.u1)
+ r = self.test_client.get('/coprs/owned/{0}/'.format(self.u1.name))
+ assert r.data.count('<div class="copr">') == 1
class TestCoprsAllowed(CoprsTestCase):
- def test_allowed_none(self, f_users, f_coprs, f_copr_permissions, f_db):
- with self.tc as c:
- 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 coprs...' in r.data
+ @TransactionDecorator('u3')
+ def test_allowed_none(self, f_users, f_coprs, f_copr_permissions, f_db):
+ self.db.session.add(self.u3)
+ r = self.test_client.get('/coprs/allowed/{0}/'.format(self.u3.name))
+ assert 'No coprs...' in r.data
+ @TransactionDecorator('u2')
def test_allowed_one(self, f_users, f_coprs, f_copr_permissions, f_db):
- with self.tc as c:
- with c.session_transaction() as s:
- s['openid'] = self.u2.openid_name
-
- self.db.session.add(self.u1)
- r = c.get('/coprs/allowed/{0}/'.format(self.u1.name))
- assert r.data.count('<div class="copr">') == 1
+ self.db.session.add(self.u1)
+ r = self.test_client.get('/coprs/allowed/{0}/'.format(self.u1.name))
+ assert r.data.count('<div class="copr">') == 1
+ @TransactionDecorator('u1')
def test_allowed_one_but_asked_for_one_more(self, f_users, f_coprs, f_copr_permissions, f_db):
- with self.tc as c:
- with c.session_transaction() as s:
- s['openid'] = self.u1.openid_name
-
- self.db.session.add(self.u1)
- r = c.get('/coprs/allowed/{0}/'.format(self.u1.name))
- assert r.data.count('<div class="copr">') == 1
+ self.db.session.add(self.u1)
+ r = self.test_client.get('/coprs/allowed/{0}/'.format(self.u1.name))
+ assert r.data.count('<div class="copr">') == 1
class TestCoprNew(CoprsTestCase):
success_string = 'New copr was successfully created'
+ @TransactionDecorator('u1')
def test_copr_new_normal(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
+ r = self.test_client.post('/coprs/new/', data = {'name': 'foo', 'fedora-rawhide-i386': 'y', 'arches': ['i386']}, follow_redirects = True)
+ assert self.models.Copr.query.filter(self.models.Copr.name == 'foo').first()
+ assert self.success_string in r.data
- r = c.post('/coprs/new/', data = {'name': 'foo', 'fedora-rawhide-i386': 'y', 'arches': ['i386']}, follow_redirects = True)
- assert self.models.Copr.query.filter(self.models.Copr.name == 'foo').first()
- assert self.success_string in r.data
-
- # make sure no initial build was submitted
- assert self.models.Build.query.first() == None
+ # make sure no initial build was submitted
+ assert self.models.Build.query.first() == None
+ @TransactionDecorator('u1')
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'
+ # TODO: this should probably be mocked...
+ signals_received = []
+ def test_receiver(sender, **kwargs):
+ signals_received.append(kwargs['copr'])
+ copr_created.connect(test_receiver)
+ r = self.test_client.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'
+ @TransactionDecorator('u3')
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:
- s['openid'] = self.u3.openid_name
-
- self.db.session.add(self.c1)
- foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all())
- assert foocoprs > 0
+ 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': self.c1.name, 'fedora-rawhide-i386': 'y'}, 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 self.success_string in r.data
+ r = self.test_client.post('/coprs/new/', data = {'name': self.c1.name, 'fedora-rawhide-i386': 'y'}, 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 self.success_string in r.data
+ @TransactionDecorator('u1')
def test_copr_new_exists_for_this_user(self, f_users, f_coprs, f_mock_chroots, f_db):
- with self.tc as c:
- with c.session_transaction() as s:
- s['openid'] = self.u1.openid_name
-
- self.db.session.add(self.c1)
- foocoprs = len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all())
- assert foocoprs > 0
+ 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': self.c1.name, 'fedora-rawhide-i386': 'y'}, 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
+ r = self.test_client.post('/coprs/new/', data = {'name': self.c1.name, 'fedora-rawhide-i386': 'y'}, 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
+ @TransactionDecorator('u1')
def test_copr_new_with_initial_pkgs(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
+ r = self.test_client.post('/coprs/new/', data = {'name': 'foo', 'fedora-rawhide-i386': 'y', 'initial_pkgs': ['http://f', 'http://b']}, follow_redirects = True)
+ copr = self.models.Copr.query.filter(self.models.Copr.name == 'foo').first()
+ assert copr
+ assert self.success_string in r.data
- r = c.post('/coprs/new/', data = {'name': 'foo', 'fedora-rawhide-i386': 'y', 'initial_pkgs': ['http://f', 'http://b']}, follow_redirects = True)
- copr = self.models.Copr.query.filter(self.models.Copr.name == 'foo').first()
- assert copr
- assert self.success_string in r.data
-
- assert self.models.Build.query.first().copr == copr
- assert copr.build_count == 1
- assert 'Initial packages were successfully submitted' in r.data
+ assert self.models.Build.query.first().copr == copr
+ assert copr.build_count == 1
+ assert 'Initial packages were successfully submitted' in r.data
+ @TransactionDecorator('u1')
def test_copr_new_is_allowed_even_if_deleted_has_same_name(self, f_users, f_coprs, f_mock_chroots, f_db):
- with self.tc as c:
- with c.session_transaction() as s:
- s['openid'] = self.u1.openid_name
-
- self.db.session.add(self.c1)
- self.c1.deleted = True
- self.c1.owner = self.u1
- self.db.session.commit()
+ self.db.session.add(self.c1)
+ self.c1.deleted = True
+ self.c1.owner = self.u1
+ self.db.session.commit()
- self.db.session.add(self.c1)
- r = c.post('/coprs/new/', data = {'name': self.c1.name, 'fedora-rawhide-i386': 'y', 'arches': ['i386']}, follow_redirects = True)
- self.db.session.add_all([self.c1, self.u1])
- assert len(self.models.Copr.query.filter(self.models.Copr.name==self.c1.name).\
- filter(self.models.Copr.owner==self.u1).\
- all()) == 2
- assert self.success_string in r.data
+ self.db.session.add(self.c1)
+ r = self.test_client.post('/coprs/new/', data = {'name': self.c1.name, 'fedora-rawhide-i386': 'y', 'arches': ['i386']}, follow_redirects = True)
+ self.db.session.add_all([self.c1, self.u1])
+ assert len(self.models.Copr.query.filter(self.models.Copr.name==self.c1.name).\
+ filter(self.models.Copr.owner==self.u1).\
+ all()) == 2
+ assert self.success_string in r.data
class TestCoprDetail(CoprsTestCase):
@@ -176,236 +145,194 @@ class TestCoprDetail(CoprsTestCase):
assert '<td>{0}'.format(self.u3.name) in r.data
assert '<td>{0}'.format(self.u1.name) in r.data
+ @TransactionDecorator('u1')
def test_copr_detail_allows_asking_for_permissions(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c2.name))
- # u1 is approved builder, check for that
- assert '/permissions_applier_change/' in r.data
+ self.db.session.add_all([self.u2, self.c2])
+ r = self.test_client.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c2.name))
+ # u1 is approved builder, check for that
+ assert '/permissions_applier_change/' in r.data
+ @TransactionDecorator('u2')
def test_copr_detail_doesnt_allow_owner_to_ask_for_permissions(self, f_users, f_coprs, f_db):
- 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}/permissions/'.format(self.u2.name, self.c2.name))
- assert '/permissions_applier_change/' not in r.data
+ self.db.session.add_all([self.u2, self.c2])
+ r = self.test_client.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c2.name))
+ assert '/permissions_applier_change/' not in r.data
+ @TransactionDecorator('u2')
def test_detail_has_correct_permissions_form(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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}/permissions/'.format(self.u2.name, self.c3.name))
+ self.db.session.add_all([self.u2, self.c3])
+ r = self.test_client.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c3.name))
- assert r.data.count('nothing') == 2
- assert '<select id="copr_builder_1" name="copr_builder_1">' in r.data
- assert '<select id="copr_admin_1" name="copr_admin_1">' in r.data
+ assert r.data.count('nothing') == 2
+ assert '<select id="copr_builder_1" name="copr_builder_1">' in r.data
+ assert '<select id="copr_admin_1" name="copr_admin_1">' in r.data
def test_copr_detail_doesnt_show_cancel_build_for_anonymous(self, f_users, f_coprs, f_builds, f_db):
r = self.tc.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name))
assert '/cancel_build/' not in r.data
+ @TransactionDecorator('u1')
def test_copr_detail_doesnt_allow_non_submitter_to_cancel_build(self, f_users, f_coprs, f_builds, f_db):
- 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.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name))
- assert '/cancel_build/' not in r.data
+ self.db.session.add_all([self.u2, self.c2])
+ r = self.test_client.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name))
+ assert '/cancel_build/' not in r.data
+ @TransactionDecorator('u2')
def test_copr_detail_allows_submitter_to_cancel_build(self, f_users, f_coprs, f_builds, f_db):
- 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}/builds/'.format(self.u2.name, self.c2.name))
- assert '/cancel_build/' in r.data
+ self.db.session.add_all([self.u2, self.c2])
+ r = self.test_client.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name))
+ assert '/cancel_build/' in r.data
class TestCoprEdit(CoprsTestCase):
- def test_edit_prefills_id(self, f_users, f_coprs, f_db):
- 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
+ @TransactionDecorator('u1')
+ def test_edit_prefills_id(self, f_users, f_coprs, f_db):
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.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, f_mock_chroots, f_db):
- 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, 'fedora-18-x86_64': 'y', 'id': self.c1.id},
- follow_redirects = True)
- assert 'Copr was updated successfully' in r.data
+ @TransactionDecorator('u1')
+ def test_update_no_changes(self, f_users, f_coprs, f_mock_chroots, f_db):
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update/'.format(self.u1.name, self.c1.name),
+ data = {'name': self.c1.name, 'fedora-18-x86_64': 'y', 'id': self.c1.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
+ @TransactionDecorator('u1')
def test_copr_admin_can_update(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db):
- 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}/update/'.format(self.u2.name, self.c3.name),
- data = {'name': self.c3.name, 'fedora-rawhide-i386': 'y', 'id': self.c3.id},
- follow_redirects = True)
- assert 'Copr was updated successfully' in r.data
+ self.db.session.add_all([self.u2, self.c3])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update/'.format(self.u2.name, self.c3.name),
+ data = {'name': self.c3.name, 'fedora-rawhide-i386': 'y', 'id': self.c3.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
+ @TransactionDecorator('u1')
def test_update_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db):
- 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.mc1, self.mc2, self.mc3])
- r = c.post('/coprs/detail/{0}/{1}/update/'.format(self.u1.name, self.c1.name),
- data = {'name': self.c1.name, self.mc2.chroot_name: 'y', self.mc3.chroot_name: 'y', 'id': self.c1.id},
- follow_redirects = True)
- assert 'Copr was updated successfully' in r.data
- self.db.session.add_all([self.c1, self.mc1, self.mc2, self.mc3])
- mock_chroots = self.models.MockChroot.query.join(self.models.CoprChroot).\
- filter(self.models.CoprChroot.copr_id==\
- self.c1.id).all()
- mock_chroots_names = map(lambda x: x.chroot_name, mock_chroots)
- assert self.mc2.chroot_name in mock_chroots_names
- assert self.mc3.chroot_name in mock_chroots_names
- assert self.mc1.chroot_name not in mock_chroots_names
-
+ self.db.session.add_all([self.u1, self.c1, self.mc1, self.mc2, self.mc3])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update/'.format(self.u1.name, self.c1.name),
+ data = {'name': self.c1.name, self.mc2.chroot_name: 'y', self.mc3.chroot_name: 'y', 'id': self.c1.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
+ self.db.session.add_all([self.c1, self.mc1, self.mc2, self.mc3])
+ mock_chroots = self.models.MockChroot.query.join(self.models.CoprChroot).\
+ filter(self.models.CoprChroot.copr_id==\
+ self.c1.id).all()
+ mock_chroots_names = map(lambda x: x.chroot_name, mock_chroots)
+ assert self.mc2.chroot_name in mock_chroots_names
+ assert self.mc3.chroot_name in mock_chroots_names
+ assert self.mc1.chroot_name not in mock_chroots_names
+
+ @TransactionDecorator('u2')
def test_update_deletes_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db):
# https://fedorahosted.org/copr/ticket/42
- 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, self.mc1])
- # add one more mock_chroot, so that we can remove two
- cc = self.models.CoprChroot()
- cc.mock_chroot = self.mc1
- self.c2.copr_chroots.append(cc)
-
- r = c.post('/coprs/detail/{0}/{1}/update/'.format(self.u2.name, self.c2.name),
- data = {'name': self.c2.name, self.mc1.chroot_name: 'y', 'id': self.c2.id},
- follow_redirects = True)
- assert 'Copr was updated successfully' in r.data
- self.db.session.add_all([self.c2, self.mc1])
- mock_chroots = self.models.MockChroot.query.join(self.models.CoprChroot).\
- filter(self.models.CoprChroot.copr_id==\
- self.c2.id).all()
- assert len(mock_chroots) == 1
+ self.db.session.add_all([self.u2, self.c2, self.mc1])
+ # add one more mock_chroot, so that we can remove two
+ cc = self.models.CoprChroot()
+ cc.mock_chroot = self.mc1
+ self.c2.copr_chroots.append(cc)
+
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update/'.format(self.u2.name, self.c2.name),
+ data = {'name': self.c2.name, self.mc1.chroot_name: 'y', 'id': self.c2.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
+ self.db.session.add_all([self.c2, self.mc1])
+ mock_chroots = self.models.MockChroot.query.join(self.models.CoprChroot).\
+ filter(self.models.CoprChroot.copr_id==\
+ self.c2.id).all()
+ assert len(mock_chroots) == 1
class TestCoprApplyForPermissions(CoprsTestCase):
+
+ @TransactionDecorator('u2')
def test_apply(self, f_users, f_coprs, f_db):
- 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}/permissions_applier_change/'.format(self.u1.name, self.c1.name),
- data = {'copr_builder': '1'},
- follow_redirects = True)
- assert 'Successfuly updated' 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 new_perm.copr_builder == 1
- assert new_perm.copr_admin == 0
+ self.db.session.add_all([self.u1, self.u2, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/permissions_applier_change/'.format(self.u1.name, self.c1.name),
+ data = {'copr_builder': '1'},
+ follow_redirects = True)
+ assert 'Successfuly updated' 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 new_perm.copr_builder == 1
+ assert new_perm.copr_admin == 0
+
+
+ @TransactionDecorator('u1')
def test_apply_doesnt_lower_other_values_from_admin_to_request(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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.cp1, self.c2])
- r = c.post('/coprs/detail/{0}/{1}/permissions_applier_change/'.format(self.u2.name, self.c2.name),
- data = {'copr_builder': 1, 'copr_admin': '1'},
- follow_redirects = True)
- assert 'Successfuly updated' in r.data
-
- self.db.session.add_all([self.u1, self.c2])
- new_perm = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u1.id).\
- filter(self.models.CoprPermission.copr_id == self.c2.id).\
- first()
- assert new_perm.copr_builder == 2
- assert new_perm.copr_admin == 1
+ self.db.session.add_all([self.u1, self.u2, self.cp1, self.c2])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/permissions_applier_change/'.format(self.u2.name, self.c2.name),
+ data = {'copr_builder': 1, 'copr_admin': '1'},
+ follow_redirects = True)
+ assert 'Successfuly updated' in r.data
+
+ self.db.session.add_all([self.u1, self.c2])
+ new_perm = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u1.id).\
+ filter(self.models.CoprPermission.copr_id == self.c2.id).\
+ first()
+ assert new_perm.copr_builder == 2
+ assert new_perm.copr_admin == 1
class TestCoprUpdatePermissions(CoprsTestCase):
- def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c2.name),
- data = {'copr_builder_1': '0'},
- follow_redirects = True)
+ @TransactionDecorator('u2')
+ def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions, f_db):
+ self.db.session.add_all([self.u2, self.c2])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c2.name),
+ data = {'copr_builder_1': '0'},
+ follow_redirects = True)
- # very volatile, but will fail fast if something changes
- check_string = '<select id="copr_builder_1" name="copr_builder_1"><option value="0">nothing</option><option value="1">'
- check_string += 'request</option><option selected value="2">approved</option></select>'
- assert check_string not in r.data
+ # very volatile, but will fail fast if something changes
+ check_string = '<select id="copr_builder_1" name="copr_builder_1"><option value="0">nothing</option><option value="1">'
+ check_string += 'request</option><option selected value="2">approved</option></select>'
+ assert check_string not in r.data
+ @TransactionDecorator('u2')
def test_update_more_permissions(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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 = {'copr_builder_1': '2', 'copr_admin_1': '1', 'copr_admin_3': '2'},
- follow_redirects = True)
- self.db.session.add_all([self.c3, self.u1, self.u3])
- u1_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
- filter(self.models.CoprPermission.user_id == self.u1.id).\
- first()
- assert u1_c3_perms.copr_builder == self.helpers.PermissionEnum('approved')
- assert u1_c3_perms.copr_admin == self.helpers.PermissionEnum('request')
-
- u3_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
- filter(self.models.CoprPermission.user_id == self.u3.id).\
- first()
- assert u3_c3_perms.copr_builder == self.helpers.PermissionEnum('nothing')
- assert u3_c3_perms.copr_admin == self.helpers.PermissionEnum('approved')
-
+ self.db.session.add_all([self.u2, self.c3])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
+ data = {'copr_builder_1': '2', 'copr_admin_1': '1', 'copr_admin_3': '2'},
+ follow_redirects = True)
+ self.db.session.add_all([self.c3, self.u1, self.u3])
+ u1_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
+ filter(self.models.CoprPermission.user_id == self.u1.id).\
+ first()
+ assert u1_c3_perms.copr_builder == self.helpers.PermissionEnum('approved')
+ assert u1_c3_perms.copr_admin == self.helpers.PermissionEnum('request')
+
+ u3_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
+ filter(self.models.CoprPermission.user_id == self.u3.id).\
+ first()
+ assert u3_c3_perms.copr_builder == self.helpers.PermissionEnum('nothing')
+ assert u3_c3_perms.copr_admin == self.helpers.PermissionEnum('approved')
+
+ @TransactionDecorator('u1')
def test_copr_admin_can_update_permissions(self, f_users, f_coprs, f_copr_permissions, f_db):
- 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}/update_permissions/'.format(self.u2.name, self.c3.name),
- data = {'copr_builder_1': '2', 'copr_admin_3': '2'},
- follow_redirects = True)
- assert 'Copr permissions were updated' in r.data
+ self.db.session.add_all([self.u2, self.c3])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
+ data = {'copr_builder_1': '2', 'copr_admin_3': '2'},
+ follow_redirects = True)
+ assert 'Copr permissions were updated' in r.data
+ @TransactionDecorator('u1')
def test_copr_admin_can_give_up_his_permissions(self, f_users, f_coprs, f_copr_permissions, f_db):
# if admin is giving up his permission and there are more permissions for
# this copr, then if the admin is altered first, he won't be permitted
# to alter the other permissions and the whole update would fail
- 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, self.cp2, self.cp3])
# mock out the order of CoprPermission objects, so that we are sure
# the admin is the first one and therefore this fails if
# the view doesn't reorder the permissions
flexmock(self.models.Copr, copr_permissions=[self.cp3, self.cp2])
- r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
+ r = self.test_client.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
data = {'copr_admin_1': '1', 'copr_admin_3': '1'},
follow_redirects = True)
self.db.session.add_all([self.u1, self.c3])
@@ -417,46 +344,38 @@ class TestCoprUpdatePermissions(CoprsTestCase):
class TestCoprDelete(CoprsTestCase):
+
+ @TransactionDecorator('u1')
def test_delete(self, f_users, f_coprs, f_db):
- 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}/delete/'.format(self.u1.name, self.c1.name),
- data = {'verify': 'yes'},
- follow_redirects = True)
- assert 'Copr was deleted successfully' in r.data
- self.db.session.add(self.c1)
- assert self.models.Action.query.first().id == self.c1.id
- assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first().deleted
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/delete/'.format(self.u1.name, self.c1.name),
+ data = {'verify': 'yes'},
+ follow_redirects = True)
+ assert 'Copr was deleted successfully' in r.data
+ self.db.session.add(self.c1)
+ assert self.models.Action.query.first().id == self.c1.id
+ assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first().deleted
+ @TransactionDecorator('u1')
def test_copr_delete_does_not_delete_if_verify_filled_wrongly(self, f_users, f_coprs, f_db):
- 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}/delete/'.format(self.u1.name, self.c1.name),
- data = {'verify': 'no'},
- follow_redirects = True)
- assert 'Copr was deleted successfully' not in r.data
- assert not self.models.Action.query.first()
- assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first()
+ self.db.session.add_all([self.u1, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/delete/'.format(self.u1.name, self.c1.name),
+ data = {'verify': 'no'},
+ follow_redirects = True)
+ assert 'Copr was deleted successfully' not in r.data
+ assert not self.models.Action.query.first()
+ assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first()
+ @TransactionDecorator('u2')
def test_non_owner_cant_delete(self, f_users, f_coprs, f_db):
- 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}/delete/'.format(self.u1.name, self.c1.name),
- data = {'verify': 'yes'},
- follow_redirects = True)
- self.db.session.add_all([self.c1])
- assert 'Copr was deleted successfully' not in r.data
- assert not self.models.Action.query.first()
- assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first()
+ self.db.session.add_all([self.u1, self.u2, self.c1])
+ r = self.test_client.post('/coprs/detail/{0}/{1}/delete/'.format(self.u1.name, self.c1.name),
+ data = {'verify': 'yes'},
+ follow_redirects = True)
+ self.db.session.add_all([self.c1])
+ assert 'Copr was deleted successfully' not in r.data
+ assert not self.models.Action.query.first()
+ assert self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first()
class TestCoprRepoGeneration(CoprsTestCase):
@pytest.fixture
10 years, 5 months