[copr] master: [keygen] package only python3 version, targeting f19+ (31e064a)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 31e064a93da7ca2b0c54ed4d1f7795fc4d885ced
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Sep 24 10:19:41 2014 +0200
[keygen] package only python3 version, targeting f19+
>---------------------------------------------------------------
keygen/copr-keygen.spec | 125 +++++++++++------------------------------------
1 files changed, 28 insertions(+), 97 deletions(-)
diff --git a/keygen/copr-keygen.spec b/keygen/copr-keygen.spec
index 4d5e4fd..01aa093 100644
--- a/keygen/copr-keygen.spec
+++ b/keygen/copr-keygen.spec
@@ -4,11 +4,7 @@
%global __python2 %{__python}
%endif
-%if 0%{?fedora}
-%global with_python3 1
-%else
-%global with_python3 0
-%endif
+# this package doesn't support rhel7- since it doesn't have python3* packages
Name: copr-keygen
Version: 1.56
@@ -26,23 +22,19 @@ Source0: %{name}-%{version}.tar.gz
BuildArch: noarch
BuildRequires: util-linux
-BuildRequires: python-setuptools
-BuildRequires: python-requests
-BuildRequires: python2-devel
BuildRequires: systemd
-%if 0%{?rhel} < 7 && 0%{?rhel} > 0
-BuildRequires: python-argparse
-%endif
-BuildRequires: python-six
-BuildRequires: python-flask
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-six
+BuildRequires: python3-flask
# for tests
-BuildRequires: pytest
-BuildRequires: python-mock
-BuildRequires: python-pytest-cov
+BuildRequires: python3-pytest
+BuildRequires: python3-pytest-cov
+BuildRequires: python3-mock
-#for doc package
+#for doc package # move to python3 when available in fedora
BuildRequires: sphinx
BuildRequires: python-sphinxcontrib-httpdomain
@@ -51,57 +43,40 @@ Requires: gnupg
Requires: mod_wsgi
Requires: httpd
Requires: obs-signd
-Requires: python-six
Requires: passwd
-Requires: python-flask
-# for tests:
-Requires: pytest
-%if 0%{?rhel} < 7 && 0%{?rhel} > 0
-BuildRequires: python-argparse
-%endif
+Requires: python3-setuptools
+Requires: python3-six
+Requires: python3-flask
-%description -n copr-keygen
-COPR is lightweight build system. It allows you to create new project in WebUI,
-and submit new builds and COPR will create yum repository from latest builds.
-
-This package contains aux service that generate keys for package signing.
-
-
-%if 0%{?with_python3}
-%package -n python3-copr-keygen
-Summary: Python interface for Copr
-Group: Applications/Productivity
-
-BuildRequires: python3-devel
-BuildRequires: python3-setuptools
-BuildRequires: python3-pytest
-BuildRequires: python3-pytest-cov
-BuildRequires: python3-mock
-BuildRequires: python3-requests
-BuildRequires: python3-six
-BuildRequires: python3-flask
+# tests
+Requires: python3-pytest
+Requires: python3-pytest-cov
+Requires: python3-mock
-Requires: python3-setuptools
-Requires: python3-six
-Requires: python3-requests
-Requires: python3-flask
-
-%description -n python3-copr-keygen
+%description -n copr-keygen
COPR is lightweight build system. It allows you to create new project in WebUI,
and submit new builds and COPR will create yum repository from latest builds.
This package contains aux service that generate keys for package signing.
-%endif # with_python3
-
%if 0%{?fedora}
%package -n copr-keygen-doc
-Summary: Code documentation for COPR
+Summary: Code documentation for copr-keygen component of Copr buildsystem.
Obsoletes: copr-doc < 1.38
+BuildRequires: python-devel
+BuildRequires: python-setuptools
+BuildRequires: python-mock
+BuildRequires: python-requests
+BuildRequires: python-six
+BuildRequires: python-flask
+
+BuildRequires: python-sphinx
+
+
%description doc
COPR is lightweight build system. It allows you to create new project in WebUI,
and submit new builds and COPR will create yum repository from latests builds.
@@ -113,26 +88,12 @@ This package contains document for copr-keygen service.
%prep
%setup -q
-%if 0%{?with_python3}
-rm -rf %{py3dir}
-cp -a . %{py3dir}
-find %{py3dir} -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python3}|'
-%endif # with_python3
%build
-CFLAGS="%{optflags}" %{__python2} setup.py build
-
-%if 0%{?with_python3}
-pushd %{py3dir}
-
CFLAGS="%{optflags}" %{__python3} setup.py build
-popd
-%endif # with_python3
-
-
%if 0%{?fedora}
# build documentation
pushd docs
@@ -143,15 +104,8 @@ popd
%install
-%if 0%{?with_python3}
-pushd %{py3dir}
%{__python3} setup.py install --skip-build --root %{buildroot}
find %{buildroot}%{python3_sitelib} -name '*.exe' | xargs rm -f
-popd
-%endif # with_python3
-
-%{__python2} setup.py install --skip-build --root %{buildroot}
-find %{buildroot}%{python2_sitelib} -name '*.exe' | xargs rm -f
install -d %{buildroot}%{_sysconfdir}/copr-keygen
@@ -178,13 +132,8 @@ cp -a docs/_build/html %{buildroot}%{_pkgdocdir}/
%endif
%check
-PYTHONPATH=./src:$PYTHONPATH %{__python2} -m pytest --cov-report term-missing --cov ./src tests
-%if 0%{?with_python3}
-pushd %{py3dir}
PYTHONPATH=./src:$PYTHONPATH %{__python3} -m pytest --cov-report term-missing --cov ./src tests
-popd
-%endif # with_python3
%pre
@@ -205,21 +154,6 @@ service httpd condrestart
%doc configs/local_settings.py.example
%{_datadir}/copr-keygen/*
-%{python2_sitelib}/*
-
-%{_bindir}/gpg_copr.sh
-
-%defattr(600, copr-signer, copr-signer, 700)
-%{_sharedstatedir}/copr-keygen
-%config(noreplace) %{_sysconfdir}/copr-keygen
-%config(noreplace) %{_sysconfdir}/sudoers.d/copr_signer
-
-%if 0%{?with_python3}
-%files -n python3-copr-keygen
-%doc LICENSE docs/INSTALL.rst docs/README.rst
-%doc configs/local_settings.py.example
-
-%{_datadir}/copr-keygen/*
%{python3_sitelib}/*
%{_bindir}/gpg_copr.sh
@@ -228,12 +162,9 @@ service httpd condrestart
%{_sharedstatedir}/copr-keygen
%config(noreplace) %{_sysconfdir}/copr-keygen
%config(noreplace) %{_sysconfdir}/sudoers.d/copr_signer
-%endif # with_python3
-
%files -n copr-keygen-doc
-%doc LICENSE
%doc %{_pkgdocdir}
9 years, 7 months
[copr] master: [frontend] added helper function and flask filter which allows to ensure that url starts with either http or https, see config (0a96985)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 0a96985ee73c163753d7ec5bd9367fd44345a383
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Tue Sep 23 19:10:20 2014 +0200
[frontend] added helper function and flask filter which allows to ensure that url starts with either http or https, see config
>---------------------------------------------------------------
frontend/copr-frontend.spec | 4 +
frontend/coprs_frontend/config/copr.conf | 6 +
frontend/coprs_frontend/config/copr_devel.conf | 6 +
frontend/coprs_frontend/config/copr_unit_test.conf | 3 +
frontend/coprs_frontend/coprs/config.py | 10 ++
frontend/coprs_frontend/coprs/filters.py | 10 ++
frontend/coprs_frontend/coprs/helpers.py | 35 ++++++-
.../coprs_frontend/coprs/templates/coprs/copr.repo | 2 +-
.../coprs/templates/coprs/detail/overview.html | 3 +-
.../coprs/views/api_ns/api_general.py | 9 +-
.../coprs/views/coprs_ns/coprs_general.py | 12 ++-
frontend/coprs_frontend/manage.py | 4 +-
frontend/coprs_frontend/tests/test_helpers.py | 99 +++++++++++++++++++-
.../test_views/test_coprs_ns/test_coprs_general.py | 20 +++-
14 files changed, 199 insertions(+), 24 deletions(-)
diff --git a/frontend/copr-frontend.spec b/frontend/copr-frontend.spec
index e30d70b..c72ad51 100644
--- a/frontend/copr-frontend.spec
+++ b/frontend/copr-frontend.spec
@@ -50,15 +50,18 @@ Requires: python-psycopg2
Requires: python-pylibravatar
Requires: python-whoosh >= 2.5.3
Requires: pytz
+Requires: python-six
# for tests:
Requires: pytest
Requires: python-flexmock
+Requires: python-mock
Requires: python-decorator
Requires: yum
%if 0%{?rhel} < 7 && 0%{?rhel} > 0
BuildRequires: python-argparse
%endif
# check
+BuildRequires: python-six
BuildRequires: python-flask
BuildRequires: python-flask-script
BuildRequires: python-flask-sqlalchemy
@@ -69,6 +72,7 @@ BuildRequires: python-flask-wtf
BuildRequires: pytest
BuildRequires: yum
BuildRequires: python-flexmock
+BuildRequires: python-mock
BuildRequires: python-decorator
BuildRequires: python-markdown
BuildRequires: pytz
diff --git a/frontend/coprs_frontend/config/copr.conf b/frontend/coprs_frontend/config/copr.conf
index 4f70fe7..ffb0eac 100644
--- a/frontend/coprs_frontend/config/copr.conf
+++ b/frontend/coprs_frontend/config/copr.conf
@@ -38,6 +38,12 @@ SQLALCHEMY_ECHO = False
# send emails when user's perms change in project?
SEND_EMAILS = True
+## post-process url leading to backend
+## possible options: None, "http", "https"
+# ENFORCE_PROTOCOL_FOR_BACKEND_URL = "https"
+## post-process url leading to frontend
+# ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
+
# Kerberos authentication configuration. Example configuration abbreviated
# like 'RH' (should not changed once used, reflects what is stored in database).
# This requires mod_auth_kerb package (Fedora/RHEL) installed on your frontend
diff --git a/frontend/coprs_frontend/config/copr_devel.conf b/frontend/coprs_frontend/config/copr_devel.conf
index eafc0b1..f161ca1 100644
--- a/frontend/coprs_frontend/config/copr_devel.conf
+++ b/frontend/coprs_frontend/config/copr_devel.conf
@@ -34,3 +34,9 @@ SQLALCHEMY_ECHO = True
# send emails when user's perms change in project?
SEND_EMAILS = True
+
+## post-process url leading to backend
+## possible options: None, "http", "https"
+ENFORCE_PROTOCOL_FOR_BACKEND_URL = "http"
+## post-process url leading to frontend
+ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "http"
diff --git a/frontend/coprs_frontend/config/copr_unit_test.conf b/frontend/coprs_frontend/config/copr_unit_test.conf
index b8de251..85e12ae 100644
--- a/frontend/coprs_frontend/config/copr_unit_test.conf
+++ b/frontend/coprs_frontend/config/copr_unit_test.conf
@@ -34,3 +34,6 @@ WTF_CSRF_ENABLED = False
# send emails when user's perms change in project?
SEND_EMAILS = False
+
+ENFORCE_PROTOCOL_FOR_BACKEND_URL = "https"
+ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
diff --git a/frontend/coprs_frontend/coprs/config.py b/frontend/coprs_frontend/coprs/config.py
index 14be052..15ef753 100644
--- a/frontend/coprs_frontend/coprs/config.py
+++ b/frontend/coprs_frontend/coprs/config.py
@@ -32,6 +32,12 @@ class Config(object):
SEND_LEGAL_TO = ["root@localhost"]
+ # prefer http or https, default setting preserve old behaviour
+ USE_HTTPS_FOR_RESULTS = True
+
+ ENFORCE_PROTOCOL_FOR_BACKEND_URL = "https"
+ ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
+
class ProductionConfig(Config):
DEBUG = False
@@ -44,6 +50,10 @@ class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_ECHO = True
+ ENFORCE_PROTOCOL_FOR_BACKEND_URL = "http"
+ ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "http"
+
+
class UnitTestConfig(Config):
CSRF_ENABLED = False
diff --git a/frontend/coprs_frontend/coprs/filters.py b/frontend/coprs_frontend/coprs/filters.py
index 03e80cf..a27ffa4 100644
--- a/frontend/coprs_frontend/coprs/filters.py
+++ b/frontend/coprs_frontend/coprs/filters.py
@@ -130,3 +130,13 @@ def build_state_decoration(state):
description = "This package has already been built previously"
return description
+
+
+(a)app.template_filter("fix_url_https_backend")
+def fix_url_https_backend(url):
+ return helpers.fix_protocol_for_backend(url)
+
+
+(a)app.template_filter("fix_url_https_frontend")
+def fix_url_https_fronend(url):
+ return helpers.fix_protocol_for_frontend(url)
diff --git a/frontend/coprs_frontend/coprs/helpers.py b/frontend/coprs_frontend/coprs/helpers.py
index 653f4c5..1740da3 100644
--- a/frontend/coprs_frontend/coprs/helpers.py
+++ b/frontend/coprs_frontend/coprs/helpers.py
@@ -5,6 +5,7 @@ import urlparse
import flask
from coprs import constants
+from coprs import app
from rpmUtils.miscutils import splitFilename
@@ -145,8 +146,10 @@ def parse_package_name(pkg):
return pkg
-def render_repo(copr, mock_chroot, url):
- """ Render .repo file. No checks if copr or mock_chroot exists. """
+def generate_repo_url(mock_chroot, url):
+ """ Generates url with build results for .repo file.
+ No checks if copr or mock_chroot exists.
+ """
if mock_chroot.os_release == "fedora":
if mock_chroot.os_version != "rawhide":
mock_chroot.os_version = "$releasever"
@@ -155,9 +158,33 @@ def render_repo(copr, mock_chroot, url):
url, "{0}-{1}-{2}/".format(mock_chroot.os_release,
mock_chroot.os_version, "$basearch"))
- url = url.replace("http://", "https://")
- return flask.render_template("coprs/copr.repo", copr=copr, url=url)
+ return url
+
+
+def fix_protocol_for_backend(url):
+ """
+ Ensure that url either has http or https protocol according to the
+ option in app config "ENFORCE_PROTOCOL_FOR_BACKEND_URL"
+ """
+ if app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] == "https":
+ return url.replace("http://", "https://")
+ elif app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] == "http":
+ return url.replace("https://", "http://")
+ else:
+ return url
+
+def fix_protocol_for_frontend(url):
+ """
+ Ensure that url either has http or https protocol according to the
+ option in app config "ENFORCE_PROTOCOL_FOR_FRONTEND_URL"
+ """
+ if app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] == "https":
+ return url.replace("http://", "https://")
+ elif app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] == "http":
+ return url.replace("https://", "http://")
+ else:
+ return url
class Serializer(object):
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/copr.repo b/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
index a2707fe..7f9f63a 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
+++ b/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
@@ -1,6 +1,6 @@
[{{ copr.owner.name }}-{{ copr.name }}]
name=Copr repo for {{ copr.name }} owned by {{ copr.owner.name }}
-baseurl={{ url }}
+baseurl={{ url | fix_url_https_backend }}
skip_if_unavailable=True
gpgcheck=0
enabled=1
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html
index 8c1f789..64afb47 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html
@@ -62,9 +62,8 @@
coprname=copr.name,
chroot=mock_chroot.os_release+"-"+mock_chroot.os_version,
repofile=copr.owner.name+'-'+copr.name+'-'+mock_chroot.os_release+"-"+mock_chroot.os_version+'.repo',
- _scheme='https',
_external=True
- )}}">
+ )|fix_url_https_frontend}}">
{{ copr.owner.name }}-{{ copr.name }}-{{mock_chroot.os_release+"-"+mock_chroot.os_version}}.repo
</a>
</td>
diff --git a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
index 48f4d0b..3bb0351 100644
--- a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -8,6 +8,7 @@ from coprs import db
from coprs import exceptions
from coprs import forms
from coprs import helpers
+from coprs.helpers import fix_protocol_for_backend
from coprs.logic.api_logic import BuildWrapper, MonitorWrapper
from coprs.views.misc import login_required, api_login_required
@@ -184,8 +185,8 @@ def api_coprs_by_owner(username=None):
if build.results:
for chroot in repo.active_chroots:
release = release_tmpl.format(chroot=chroot)
- yum_repos[release] = urlparse.urljoin(
- build.results, release + '/')
+ yum_repos[release] = fix_protocol_for_backend(
+ urlparse.urljoin(build.results, release + '/'))
break
output["repos"].append({"name": repo.name,
@@ -221,8 +222,8 @@ def api_coprs_by_owner_detail(username, coprname):
if build.results:
for chroot in copr.active_chroots:
release = release_tmpl.format(chroot=chroot)
- yum_repos[release] = urlparse.urljoin(
- build.results, release + '/')
+ yum_repos[release] = fix_protocol_for_backend(
+ urlparse.urljoin(build.results, release + '/'))
break
output["detail"] = {"name": copr.name,
"additional_repos": copr.repos,
diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index ed7d9ca..aba25c5 100644
--- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -22,7 +22,7 @@ from coprs.views.coprs_ns import coprs_ns
from coprs.logic import builds_logic
from coprs.logic import coprs_logic
-from coprs.helpers import parse_package_name, render_repo
+from coprs.helpers import parse_package_name, generate_repo_url
@coprs_ns.route("/", defaults={"page": 1})
@@ -525,13 +525,17 @@ def generate_repo_file(username, coprname, chroot, repofile):
"Repository not initialized: No finished builds in {0}/{1}."
.format(username, coprname))
- response = flask.make_response(render_repo(copr, mock_chroot, url))
+ repo_url = generate_repo_url(mock_chroot, url)
+ response = flask.make_response(
+ flask.render_template("coprs/copr.repo", copr=copr, url=repo_url))
+
response.mimetype = "text/plain"
- response.headers["Content-Disposition"] = "filename={0}.repo".format(
- reponame)
+ response.headers["Content-Disposition"] = \
+ "filename={0}.repo".format(reponame)
return response
+
@coprs_ns.route("/<username>/<coprname>/monitor/")
def copr_build_monitor(username, coprname):
try:
diff --git a/frontend/coprs_frontend/manage.py b/frontend/coprs_frontend/manage.py
index b8826c7..e23468d 100755
--- a/frontend/coprs_frontend/manage.py
+++ b/frontend/coprs_frontend/manage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
import argparse
import os
@@ -22,7 +22,7 @@ class TestCommand(Command):
if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):
os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"
os.environ["PYTHONPATH"] = "."
- return subprocess.call(["py.test"] + (test_args or []))
+ return subprocess.call(["/usr/bin/python", "-m", "pytest"] + (test_args or []))
option_list = (
Option("-a",
diff --git a/frontend/coprs_frontend/tests/test_helpers.py b/frontend/coprs_frontend/tests/test_helpers.py
index 6851bf6..df019da 100644
--- a/frontend/coprs_frontend/tests/test_helpers.py
+++ b/frontend/coprs_frontend/tests/test_helpers.py
@@ -1,4 +1,14 @@
-from coprs.helpers import parse_package_name
+from copy import deepcopy
+import six
+
+if six.PY3:
+ from unittest import mock
+else:
+ import mock
+
+from coprs import app
+from coprs.helpers import parse_package_name, generate_repo_url, \
+ fix_protocol_for_frontend, fix_protocol_for_backend
from tests.coprs_test_case import CoprsTestCase
@@ -25,3 +35,90 @@ class TestHelpers(CoprsTestCase):
for pkg, expected in EXP.iteritems():
assert parse_package_name(pkg) == expected
+
+ def test_generate_repo_url(self):
+ test_sets = []
+ http_url = "http://example.com/repo"
+ https_url = "https://example.com/repo"
+
+ mock_chroot = mock.MagicMock()
+ mock_chroot.os_release = "fedora"
+ mock_chroot.os_version = "20"
+
+ test_sets.extend([
+ dict(args=(mock_chroot, http_url),
+ expected="http://example.com/fedora-$releasever-$basearch/"),
+ dict(args=(mock_chroot, https_url),
+ expected="https://example.com/fedora-$releasever-$basearch/")])
+
+ m2 = deepcopy(mock_chroot)
+ m2.os_version = "rawhide"
+
+ test_sets.extend([
+ dict(args=(m2, http_url),
+ expected="http://example.com/fedora-rawhide-$basearch/"),
+ dict(args=(m2, https_url),
+ expected="https://example.com/fedora-rawhide-$basearch/")])
+
+ m3 = deepcopy(mock_chroot)
+ m3.os_release = "rhel7"
+ m3.os_version = "7.1"
+
+ test_sets.extend([
+ dict(args=(m3, http_url),
+ expected="http://example.com/rhel7-7.1-$basearch/"),
+ dict(args=(m3, https_url),
+ expected="https://example.com/rhel7-7.1-$basearch/")])
+
+ app.config["USE_HTTPS_FOR_RESULTS"] = True
+ for test_set in test_sets:
+ result = generate_repo_url(*test_set["args"])
+ assert result == test_set["expected"]
+
+ def test_fix_protocol_for_backend(self):
+ http_url = "http://example.com/repo"
+ https_url = "https://example.com/repo"
+
+ orig = app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"]
+ print("Orig: {}".format(orig))
+ try:
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = "https"
+ assert fix_protocol_for_backend(https_url) == https_url
+ assert fix_protocol_for_backend(http_url) == https_url
+
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = "http"
+ assert fix_protocol_for_backend(https_url) == http_url
+ assert fix_protocol_for_backend(http_url) == http_url
+
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = None
+ assert fix_protocol_for_backend(https_url) == https_url
+ assert fix_protocol_for_backend(http_url) == http_url
+
+ except Exception as e:
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
+ raise e
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
+
+
+ def test_fix_protocol_for_frontend(self):
+ http_url = "http://example.com/repo"
+ https_url = "https://example.com/repo"
+
+ orig = app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"]
+ try:
+ app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "https"
+ assert fix_protocol_for_frontend(https_url) == https_url
+ assert fix_protocol_for_frontend(http_url) == https_url
+
+ app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "http"
+ assert fix_protocol_for_frontend(https_url) == http_url
+ assert fix_protocol_for_frontend(http_url) == http_url
+
+ app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = None
+ assert fix_protocol_for_frontend(https_url) == https_url
+ assert fix_protocol_for_frontend(http_url) == http_url
+
+ except Exception as e:
+ app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = orig
+ raise e
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
diff --git a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
index a180c7d..07808ed 100644
--- a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
+++ b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
@@ -618,9 +618,17 @@ class TestCoprRepoGeneration(CoprsTestCase):
def test_works_on_older_builds(self, f_users, f_coprs,
f_custom_builds, f_db):
- r = self.tc.get(
- "/coprs/{0}/{1}/repo/fedora-18-x86_64/"
- .format(self.u1.name, self.c1.name))
-
- assert r.status_code == 200
- assert "baseurl=https://bar.baz" in r.data
+ from coprs import app
+ orig = app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"]
+ try:
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = "https"
+ r = self.tc.get(
+ "/coprs/{0}/{1}/repo/fedora-18-x86_64/"
+ .format(self.u1.name, self.c1.name))
+
+ assert r.status_code == 200
+ assert "baseurl=https://bar.baz" in r.data
+ except Exception as e:
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
+ raise e
+ app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
9 years, 7 months
[copr] master: Automatic commit of package [copr-keygen] release [1.56-1]. (11cd152)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 11cd1527cec89c03920897d8fa7f437dca2dd0d2
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Sep 22 18:52:36 2014 +0200
Automatic commit of package [copr-keygen] release [1.56-1].
>---------------------------------------------------------------
keygen/copr-keygen.spec | 7 ++++++-
rel-eng/packages/copr-keygen | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/keygen/copr-keygen.spec b/keygen/copr-keygen.spec
index 9ff94b3..4d5e4fd 100644
--- a/keygen/copr-keygen.spec
+++ b/keygen/copr-keygen.spec
@@ -11,7 +11,7 @@
%endif
Name: copr-keygen
-Version: 1.55
+Version: 1.56
Release: 1%{?dist}
Summary: Part of Copr build system. Aux service that generate keys for sign.
@@ -238,6 +238,11 @@ service httpd condrestart
%changelog
+* Mon Sep 22 2014 Valentin Gologuzov <vgologuz(a)redhat.com> 1.56-1
+- [keygen] .spec: run tests, build py3 version for fedora
+- [keygen] py3 compatibility
+- [keygen] added unittests
+
* Thu Sep 18 2014 Valentin Gologuzov <vgologuz(a)redhat.com> 1.55-1
- [keygen] cleanup in .spec
diff --git a/rel-eng/packages/copr-keygen b/rel-eng/packages/copr-keygen
index de7e118..d0cc52d 100644
--- a/rel-eng/packages/copr-keygen
+++ b/rel-eng/packages/copr-keygen
@@ -1 +1 @@
-1.55-1 keygen/
+1.56-1 keygen/
9 years, 7 months
[copr] master: [keygen] .spec changes: run tests during the build, build py3 version on fedora (ca9ec6f)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit ca9ec6f41bd65e4d854c42b8d2309dad8e9680cb
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Sep 22 18:20:22 2014 +0200
[keygen] .spec changes: run tests during the build, build py3 version on fedora
>---------------------------------------------------------------
keygen/copr-keygen.spec | 107 ++++++++++++++++++++++++++++++--
keygen/run_tests.sh | 4 +
keygen/run_tests_coverage.sh | 3 -
keygen/{test => tests}/test_handles.py | 0
keygen/{test => tests}/test_logic.py | 0
python/python-copr.spec | 4 +-
6 files changed, 107 insertions(+), 11 deletions(-)
diff --git a/keygen/copr-keygen.spec b/keygen/copr-keygen.spec
index 0f537b7..9ff94b3 100644
--- a/keygen/copr-keygen.spec
+++ b/keygen/copr-keygen.spec
@@ -4,6 +4,12 @@
%global __python2 %{__python}
%endif
+%if 0%{?fedora}
+%global with_python3 1
+%else
+%global with_python3 0
+%endif
+
Name: copr-keygen
Version: 1.55
Release: 1%{?dist}
@@ -31,6 +37,11 @@ BuildRequires: python-argparse
BuildRequires: python-six
BuildRequires: python-flask
+# for tests
+BuildRequires: pytest
+BuildRequires: python-mock
+BuildRequires: python-pytest-cov
+
#for doc package
BuildRequires: sphinx
BuildRequires: python-sphinxcontrib-httpdomain
@@ -50,13 +61,44 @@ BuildRequires: python-argparse
%endif
-%description
+%description -n copr-keygen
+COPR is lightweight build system. It allows you to create new project in WebUI,
+and submit new builds and COPR will create yum repository from latest builds.
+
+This package contains aux service that generate keys for package signing.
+
+
+%if 0%{?with_python3}
+%package -n python3-copr-keygen
+Summary: Python interface for Copr
+Group: Applications/Productivity
+
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pytest
+BuildRequires: python3-pytest-cov
+BuildRequires: python3-mock
+BuildRequires: python3-requests
+BuildRequires: python3-six
+BuildRequires: python3-flask
+
+Requires: python3-setuptools
+Requires: python3-six
+Requires: python3-requests
+Requires: python3-flask
+
+
+%description -n python3-copr-keygen
COPR is lightweight build system. It allows you to create new project in WebUI,
and submit new builds and COPR will create yum repository from latest builds.
This package contains aux service that generate keys for package signing.
-%package doc
+%endif # with_python3
+
+
+%if 0%{?fedora}
+%package -n copr-keygen-doc
Summary: Code documentation for COPR
Obsoletes: copr-doc < 1.38
@@ -64,25 +106,50 @@ Obsoletes: copr-doc < 1.38
COPR is lightweight build system. It allows you to create new project in WebUI,
and submit new builds and COPR will create yum repository from latests builds.
-This package contains aux service that generate keys for package signing.
+This package contains document for copr-keygen service.
+
+%endif # ?fedora
%prep
%setup -q
-
+%if 0%{?with_python3}
+rm -rf %{py3dir}
+cp -a . %{py3dir}
+find %{py3dir} -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python3}|'
+%endif # with_python3
%build
CFLAGS="%{optflags}" %{__python2} setup.py build
+%if 0%{?with_python3}
+pushd %{py3dir}
+
+CFLAGS="%{optflags}" %{__python3} setup.py build
+
+popd
+%endif # with_python3
+
+
+%if 0%{?fedora}
+# build documentation
pushd docs
- make html
+make %{?_smp_mflags} html
popd
+%endif # ?fedora
%install
+%if 0%{?with_python3}
+pushd %{py3dir}
+%{__python3} setup.py install --skip-build --root %{buildroot}
+find %{buildroot}%{python3_sitelib} -name '*.exe' | xargs rm -f
+popd
+%endif # with_python3
+
%{__python2} setup.py install --skip-build --root %{buildroot}
find %{buildroot}%{python2_sitelib} -name '*.exe' | xargs rm -f
@@ -106,9 +173,19 @@ install -d -m 500 %{buildroot}%{_sharedstatedir}/copr-keygen/gnupg
cp -a configs/sudoers/copr_signer %{buildroot}%{_sysconfdir}/sudoers.d/copr_signer
# docs
+%if 0%{?fedora}
cp -a docs/_build/html %{buildroot}%{_pkgdocdir}/
+%endif
%check
+PYTHONPATH=./src:$PYTHONPATH %{__python2} -m pytest --cov-report term-missing --cov ./src tests
+
+%if 0%{?with_python3}
+pushd %{py3dir}
+PYTHONPATH=./src:$PYTHONPATH %{__python3} -m pytest --cov-report term-missing --cov ./src tests
+popd
+%endif # with_python3
+
%pre
getent group copr-signer >/dev/null || groupadd -r copr-signer
@@ -137,7 +214,25 @@ service httpd condrestart
%config(noreplace) %{_sysconfdir}/copr-keygen
%config(noreplace) %{_sysconfdir}/sudoers.d/copr_signer
-%files doc
+%if 0%{?with_python3}
+%files -n python3-copr-keygen
+%doc LICENSE docs/INSTALL.rst docs/README.rst
+%doc configs/local_settings.py.example
+
+%{_datadir}/copr-keygen/*
+%{python3_sitelib}/*
+
+%{_bindir}/gpg_copr.sh
+
+%defattr(600, copr-signer, copr-signer, 700)
+%{_sharedstatedir}/copr-keygen
+%config(noreplace) %{_sysconfdir}/copr-keygen
+%config(noreplace) %{_sysconfdir}/sudoers.d/copr_signer
+%endif # with_python3
+
+
+
+%files -n copr-keygen-doc
%doc LICENSE
%doc %{_pkgdocdir}
diff --git a/keygen/run_tests.sh b/keygen/run_tests.sh
new file mode 100644
index 0000000..898dc35
--- /dev/null
+++ b/keygen/run_tests.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+PYTHONPATH=./src:$PYTHONPATH python -B -m pytest --cov-report term-missing --cov ./src tests
+PYTHONPATH=./src:$PYTHONPATH python3 -B -m pytest --cov-report term-missing --cov ./src tests
diff --git a/keygen/run_tests_coverage.sh b/keygen/run_tests_coverage.sh
deleted file mode 100644
index d14139c..0000000
--- a/keygen/run_tests_coverage.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-PYTHONPATH=./src:$PYTHONPATH python -B -m pytest --cov-report term-missing --cov ./src
diff --git a/keygen/test/__init__.py b/keygen/test/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/keygen/test/test_handles.py b/keygen/tests/test_handles.py
similarity index 100%
rename from keygen/test/test_handles.py
rename to keygen/tests/test_handles.py
diff --git a/keygen/test/test_logic.py b/keygen/tests/test_logic.py
similarity index 100%
rename from keygen/test/test_logic.py
rename to keygen/tests/test_logic.py
diff --git a/python/python-copr.spec b/python/python-copr.spec
index 10a540a..a44ed97 100644
--- a/python/python-copr.spec
+++ b/python/python-copr.spec
@@ -86,7 +86,7 @@ and submit new builds and COPR will create yum repository from latest builds.
This package includes documentation for python-copr. Mostly useful for
developers only.
-%endif
+%endif # ?fedora
%prep
%setup -q
@@ -118,7 +118,7 @@ mv copr/README.rst ./
pushd docs
make %{?_smp_mflags} html
popd
-%endif
+%endif # ?fedora
%install
9 years, 7 months
[copr] master: [backend] py3 compatibility (49bad50)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 49bad50c2f6c48feb5cd608e02dd77e53bd58a03
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Sep 22 17:00:54 2014 +0200
[backend] py3 compatibility
>---------------------------------------------------------------
keygen/run/dev_run.py | 8 ++++++++
keygen/src/copr_keygen/__init__.py | 6 ++++--
keygen/src/copr_keygen/exceptions.py | 4 ++++
keygen/src/copr_keygen/logic.py | 2 +-
keygen/test/test_handles.py | 3 +--
keygen/test/test_logic.py | 2 +-
6 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/keygen/run/dev_run.py b/keygen/run/dev_run.py
new file mode 100755
index 0000000..dd051d5
--- /dev/null
+++ b/keygen/run/dev_run.py
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+import sys
+sys.path.append("../src/")
+from copr_keygen import app
+
+if __name__ == '__main__':
+ app.run()
diff --git a/keygen/src/copr_keygen/__init__.py b/keygen/src/copr_keygen/__init__.py
index 7fcb2a9..232f12d 100644
--- a/keygen/src/copr_keygen/__init__.py
+++ b/keygen/src/copr_keygen/__init__.py
@@ -60,7 +60,8 @@ def gen_key():
"""
try:
- query = json.loads(request.data)
+ charset = request.headers.get('charset', 'utf-8')
+ query = json.loads(request.data.decode(charset))
except Exception as e:
raise BadRequestException("Failed to parse request body: {}".format(e))
@@ -95,7 +96,7 @@ def gen_key():
@app.errorhandler(KeygenServiceBaseException)
def handle_invalid_usage(error):
- response = Response(error.message, content_type="text/plain;charset=UTF-8")
+ response = Response(error.msg, content_type="text/plain;charset=UTF-8")
response.status_code = error.status_code
response.data = str(error)
return response
@@ -110,3 +111,4 @@ def handle_invalid_usage(error):
## #cmd = "gpg --with-colons --fingerprint gafoo |
# awk -F: '$1 == "fpr" {print $10;}'"
# #TODO: complete implementation
+
diff --git a/keygen/src/copr_keygen/exceptions.py b/keygen/src/copr_keygen/exceptions.py
index 6378c84..f59e3d7 100644
--- a/keygen/src/copr_keygen/exceptions.py
+++ b/keygen/src/copr_keygen/exceptions.py
@@ -1,6 +1,10 @@
class KeygenServiceBaseException(Exception):
status_code = 500
+ @property
+ def msg(self):
+ return str(self)
+
def __init__(self, *args, **kwargs):
super(KeygenServiceBaseException, self).__init__(*args)
self.kwargs = kwargs
diff --git a/keygen/src/copr_keygen/logic.py b/keygen/src/copr_keygen/logic.py
index 88bcd64..779be8e 100644
--- a/keygen/src/copr_keygen/logic.py
+++ b/keygen/src/copr_keygen/logic.py
@@ -93,7 +93,7 @@ def create_new_key(
name_real=name_real,
comment=name_comment,
name_email=name_email,
- expire=expire or 0))
+ expire=expire or 0).encode('utf-8'))
cmd = [
app.config["GPG_BINARY"], "-v", "--batch",
diff --git a/keygen/test/test_handles.py b/keygen/test/test_handles.py
index d81b66f..5744fcc 100644
--- a/keygen/test/test_handles.py
+++ b/keygen/test/test_handles.py
@@ -17,7 +17,7 @@ def test_ping():
with app.test_client() as c:
rv = c.get('/ping')
assert rv.status_code == 200
- assert rv.data == "pong\n"
+ assert rv.data == b"pong\n"
json_data = json.dumps({
@@ -39,7 +39,6 @@ class TestGenKey(object):
create_new_key.return_value = None
with app.test_client() as c:
- #pass
rv = c.post('/gen_key', data=json_data)
assert rv.status_code == 201
diff --git a/keygen/test/test_logic.py b/keygen/test/test_logic.py
index c4b0dc1..1c80113 100644
--- a/keygen/test/test_logic.py
+++ b/keygen/test/test_logic.py
@@ -121,7 +121,7 @@ class TestUserExists(TestCase):
@mock.patch("copr_keygen.logic.user_exists")
@mock.patch("copr_keygen.logic.Popen")
-class TestCreateKey(TestCase):
+class TestGenKey(TestCase):
def test_simple_create(self, popen, user_exists):
"""
Check correct key generation.
9 years, 7 months
[copr] master: [keygen] adding unittests (44b3944)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 44b394434dd61f3c7ceeaa9f8c806e6cc2ca54b8
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Sep 22 16:11:55 2014 +0200
[keygen] adding unittests
>---------------------------------------------------------------
.gitignore | 1 +
keygen/__init__.py | 1 +
keygen/requirements.txt | 4 +
keygen/run_tests_coverage.sh | 3 +
keygen/src/copr_keygen/__init__.py | 19 ++-
keygen/src/copr_keygen/logic.py | 19 ++-
.../coprs/logic => keygen/test}/__init__.py | 0
keygen/test/test_handles.py | 93 +++++++++++
keygen/test/test_logic.py | 171 ++++++++++++++++++++
9 files changed, 294 insertions(+), 17 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5352e85..bfa76cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
*.pyc
*.pyo
*.swp
+.coverage
data/
cli/dist/
build/
diff --git a/keygen/__init__.py b/keygen/__init__.py
new file mode 100644
index 0000000..f19a366
--- /dev/null
+++ b/keygen/__init__.py
@@ -0,0 +1 @@
+__author__ = 'vgologuz'
diff --git a/keygen/requirements.txt b/keygen/requirements.txt
index c12bb8d..edd49dd 100644
--- a/keygen/requirements.txt
+++ b/keygen/requirements.txt
@@ -1,3 +1,7 @@
sphinxcontrib-httpdomain
flask
six
+mock
+pytest
+pytest-cov
+
diff --git a/keygen/run_tests_coverage.sh b/keygen/run_tests_coverage.sh
new file mode 100644
index 0000000..d14139c
--- /dev/null
+++ b/keygen/run_tests_coverage.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+PYTHONPATH=./src:$PYTHONPATH python -B -m pytest --cov-report term-missing --cov ./src
diff --git a/keygen/src/copr_keygen/__init__.py b/keygen/src/copr_keygen/__init__.py
index e072a5b..7fcb2a9 100644
--- a/keygen/src/copr_keygen/__init__.py
+++ b/keygen/src/copr_keygen/__init__.py
@@ -93,19 +93,20 @@ def gen_key():
return response
+(a)app.errorhandler(KeygenServiceBaseException)
+def handle_invalid_usage(error):
+ response = Response(error.message, content_type="text/plain;charset=UTF-8")
+ response.status_code = error.status_code
+ response.data = str(error)
+ return response
+
+
# @app.route('/remove_key', methods=["post"])
# def remove_key():
# raise NotImplementedError()
# query = json.loads(request.data)
# print(repr(query))
# mail = query["name_email"]
-#
-# #cmd = "gpg --with-colons --fingerprint gafoo | awk -F: '$1 == "fpr" {print $10;}'"
+## #cmd = "gpg --with-colons --fingerprint gafoo |
+# awk -F: '$1 == "fpr" {print $10;}'"
# #TODO: complete implementation
-
-
-(a)app.errorhandler(KeygenServiceBaseException)
-def handle_invalid_usage(error):
- response = Response(error.message, content_type="text/plain;charset=UTF-8")
- response.status_code = error.status_code
- return response
diff --git a/keygen/src/copr_keygen/logic.py b/keygen/src/copr_keygen/logic.py
index 2963961..88bcd64 100644
--- a/keygen/src/copr_keygen/logic.py
+++ b/keygen/src/copr_keygen/logic.py
@@ -6,20 +6,23 @@ import tempfile
from .exceptions import GpgErrorException
-def _ensure_passphrase_exist(app, name_email):
+def ensure_passphrase_exist(app, name_email):
""" Need this to tell signd server that `name_email` available in keyring
Key not protected by passphrase, so we write *something* to passphrase file.
"""
+ def create():
+ with open(location, "w") as handle:
+ handle.write("1")
+ handle.write(os.linesep)
location = os.path.join(app.config["PHRASES_DIR"], name_email)
try:
with open(location) as handle:
- if handle.read():
- pass
+ content = handle.read()
+ if not content:
+ create()
except IOError:
- with open(location, "w") as handle:
- handle.write("1")
- handle.write(os.linesep)
+ create()
def user_exists(app, mail):
@@ -42,7 +45,7 @@ def user_exists(app, mail):
if handle.returncode == 0:
# TODO: validate that we really got exactly one line in stdout
- _ensure_passphrase_exist(app, mail)
+ ensure_passphrase_exist(app, mail)
return True
elif "error reading key" in stderr:
return False
@@ -83,7 +86,7 @@ def create_new_key(
if user_exists(app, name_email):
return
- with tempfile.NamedTemporaryFile(delete=False) as out:
+ with tempfile.NamedTemporaryFile() as out:
out.write(template.format(
key_type="RSA",
key_length=key_length or 2048,
diff --git a/frontend/coprs_frontend/coprs/logic/__init__.py b/keygen/test/__init__.py
similarity index 100%
copy from frontend/coprs_frontend/coprs/logic/__init__.py
copy to keygen/test/__init__.py
diff --git a/keygen/test/test_handles.py b/keygen/test/test_handles.py
new file mode 100644
index 0000000..d81b66f
--- /dev/null
+++ b/keygen/test/test_handles.py
@@ -0,0 +1,93 @@
+import json
+import six
+
+if six.PY3:
+ from unittest import mock
+else:
+ import mock
+
+
+from copr_keygen import app
+from copr_keygen.exceptions import KeygenServiceBaseException
+
+
+def test_ping():
+ """ Simple check for simple handle
+ """
+ with app.test_client() as c:
+ rv = c.get('/ping')
+ assert rv.status_code == 200
+ assert rv.data == "pong\n"
+
+
+json_data = json.dumps({
+ "name_real": "foo_bar",
+ "name_email": "foo_bar(a)example.com"
+})
+json_data_missing_email = json.dumps({"name_real": "foo_bar"})
+json_data_missing_name = json.dumps({"name_email": "foo_bar(a)example.com"})
+
+
+(a)mock.patch("copr_keygen.create_new_key")
+(a)mock.patch("copr_keygen.user_exists")
+class TestGenKey(object):
+
+ def test_gen_key(self, user_exists, create_new_key):
+ """ Check reactions to different sets of input data
+ """
+ user_exists.return_value = False
+ create_new_key.return_value = None
+
+ with app.test_client() as c:
+ #pass
+ rv = c.post('/gen_key', data=json_data)
+ assert rv.status_code == 201
+
+ rv = c.post('/gen_key', data=None)
+ assert rv.status_code == 400
+ #
+ rv = c.post('/gen_key', data=json_data_missing_email)
+ assert rv.status_code == 400
+ #
+ rv = c.post('/gen_key', data=json_data_missing_name)
+ assert rv.status_code == 400
+
+ def test_gen_key_user_not_exists(self, user_exists, create_new_key):
+ """ Check that key is really created when user not exists
+ """
+ user_exists.return_value = False
+ create_new_key.return_value = None
+
+ with app.test_client() as c:
+ rv = c.post('/gen_key', data=json_data)
+ assert rv.status_code == 201
+
+ assert user_exists.called
+ assert create_new_key.called
+
+ def test_gen_key_with_existing_user(self, user_exists, create_new_key):
+ """ Check that key is not created when user not exists
+ """
+ user_exists.return_value = True
+
+ with app.test_client() as c:
+ rv = c.post('/gen_key', data=json_data)
+ assert rv.status_code == 200
+
+ assert user_exists.called
+ assert not create_new_key.called
+
+ def test_server_error_at_user_exists(self, user_exists, _):
+ user_exists.side_effect = KeygenServiceBaseException()
+
+ with app.test_client() as c:
+ rv = c.post('/gen_key', data=json_data)
+ assert rv.status_code == 500
+
+ def test_server_error_at_create_new_key(self, user_exists, create_new_key):
+ user_exists.return_value = False
+ create_new_key.side_effect = KeygenServiceBaseException()
+
+ with app.test_client() as c:
+ rv = c.post('/gen_key', data=json_data)
+ assert rv.status_code == 500
diff --git a/keygen/test/test_logic.py b/keygen/test/test_logic.py
new file mode 100644
index 0000000..c4b0dc1
--- /dev/null
+++ b/keygen/test/test_logic.py
@@ -0,0 +1,171 @@
+from unittest import TestCase
+import tempfile
+import shutil
+import os
+
+import six
+
+if six.PY3:
+ from unittest import mock
+else:
+ import mock
+
+import pytest
+
+from copr_keygen import app
+from copr_keygen.exceptions import GpgErrorException
+from copr_keygen.logic import ensure_passphrase_exist
+
+import copr_keygen.logic as logic
+
+
+TMP_DIR = tempfile.gettempdir()
+
+TEST_EMAIL = "foobar(a)example.com"
+TEST_NAME = "foobar"
+TEST_KEYLENGTH = 2048
+
+
+class TestEnsurePassphrase(TestCase):
+ def __init__(self, *args, **kwargs):
+ super(TestEnsurePassphrase, self).__init__(*args, **kwargs)
+ self.path = None
+ from copr_keygen import app as mock_app
+
+ self.mock_app = mock_app
+
+ @property
+ def target(self):
+ return os.path.join(self.path, TEST_EMAIL)
+
+ def setUp(self):
+ self.path = tempfile.mkdtemp()
+ self.mock_app.config["PHRASES_DIR"] = self.path
+
+ def tearDown(self):
+ shutil.rmtree(self.path)
+
+ def test_file_creation(self):
+ ensure_passphrase_exist(self.mock_app, TEST_EMAIL)
+
+ assert os.path.exists(self.target)
+ assert os.path.getsize(self.target) > 0
+
+ def test_add_content_to_empty_file(self):
+ open(self.target, "w").close()
+ assert os.path.getsize(self.target) == 0
+ ensure_passphrase_exist(self.mock_app, TEST_EMAIL)
+ assert os.path.getsize(self.target) > 0
+
+
+def test_ensure_passphrase_exist():
+ path = os.path.join(TMP_DIR, "TEST_GNUPG_PASSPHRASES")
+ os.mkdir(path)
+ try:
+ from copr_keygen import app as mock_app
+
+ mock_app.config["PHRASES_DIR"] = path
+ ensure_passphrase_exist(mock_app, TEST_EMAIL)
+
+ target = os.path.join(path, TEST_EMAIL)
+ assert os.path.exists(target)
+ assert os.path.getsize(target) > 0
+
+ # now we placing empty file
+ os.remove(target)
+ open(target, "w").close()
+ assert os.path.getsize(target) == 0
+ ensure_passphrase_exist(mock_app, TEST_EMAIL)
+ assert os.path.getsize(target) > 0
+
+ except Exception as e:
+ shutil.rmtree(path, ignore_errors=True)
+ raise e
+
+ shutil.rmtree(path, ignore_errors=True)
+
+
+class MockPopenHandle(object):
+ def __init__(self, returncode=None, stdout=None, stderr=None):
+ self.returncode = returncode or 0
+ self.stdout = stdout or "mock stdout"
+ self.stderr = stderr or "mock stderr"
+
+ def communicate(self):
+ return self.stdout, self.stderr
+
+
+(a)mock.patch("copr_keygen.logic.ensure_passphrase_exist")
+(a)mock.patch("copr_keygen.logic.Popen")
+class TestUserExists(TestCase):
+ def test_exists(self, popen, ensure_passphrase):
+ popen.return_value = MockPopenHandle(0)
+ ensure_passphrase.return_value = True
+ assert logic.user_exists(app, TEST_EMAIL)
+
+ def test_not_exists(self, popen, ensure_passphrase):
+ popen.return_value = MockPopenHandle(1, stderr="error reading key")
+ ensure_passphrase.return_value = True
+ assert not logic.user_exists(app, TEST_EMAIL)
+
+ def test_gpg_unknown_err(self, popen, ensure_passphrase):
+ popen.return_value = MockPopenHandle(1)
+ with pytest.raises(GpgErrorException):
+ logic.user_exists(app, TEST_EMAIL)
+
+ def test_popen_unknown_err(self, popen, ensure_passphrase):
+ popen.side_effect = OSError()
+ with pytest.raises(GpgErrorException):
+ logic.user_exists(app, TEST_EMAIL)
+
+
+(a)mock.patch("copr_keygen.logic.user_exists")
+(a)mock.patch("copr_keygen.logic.Popen")
+class TestCreateKey(TestCase):
+ def test_simple_create(self, popen, user_exists):
+ """
+ Check correct key generation.
+ At first user not exist, but after popen call,
+ it exists
+ """
+
+ user_exists_returns = [False, True]
+ user_exists.side_effect = \
+ lambda *args, **kwargs: user_exists_returns.pop(0)
+ popen.return_value = MockPopenHandle(0)
+
+ res = logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
+ assert res is None
+
+ def test_strange_situation_create(self, popen, user_exists):
+ """
+ After key generation `user_exists` invoked again, and if it doesn't
+ see key it should raise an error
+ """
+
+ user_exists.return_value = False
+ popen.return_value = MockPopenHandle(0)
+
+ with pytest.raises(GpgErrorException):
+ logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
+
+ def test_skip_creation_for_existing_user(self, popen, user_exists):
+ user_exists.return_value = True
+ logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
+
+ user_exists.assert_called_once()
+ assert not popen.called
+
+ def test_error_popen(self, popen, user_exists):
+ user_exists.return_value = False
+ popen.side_effect = OSError()
+ with pytest.raises(GpgErrorException):
+ logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
+
+ def test_error_gpg(self, popen, user_exists):
+ user_exists.return_value = False
+ err_msg = "Error message 123"
+ popen.return_value = MockPopenHandle(1, stderr=err_msg)
+ with pytest.raises(GpgErrorException) as e:
+ logic.create_new_key(app, TEST_NAME, TEST_EMAIL, TEST_KEYLENGTH)
+ assert e.msg == err_msg
9 years, 7 months
[copr] master: [python-copr] minor fixes, added usage examples to docs (3026da4)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 3026da47cb3a504f4394b8dfa00488e29bf6c681
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Sep 19 14:16:25 2014 +0200
[python-copr] minor fixes, added usage examples to docs
>---------------------------------------------------------------
python/copr/client/client.py | 11 ++--
python/copr/client/parsers.py | 2 +-
python/copr/client/responses.py | 7 +++
python/docs/Examples.rst | 98 +++++++++++++++++++++++++++++++++++++++
python/docs/conf.py | 4 +-
python/docs/index.rst | 8 ++-
6 files changed, 119 insertions(+), 11 deletions(-)
diff --git a/python/copr/client/client.py b/python/copr/client/client.py
index a84330c..170bdd1 100644
--- a/python/copr/client/client.py
+++ b/python/copr/client/client.py
@@ -300,10 +300,10 @@ class CoprClient(object):
NewBuildListParser,
]
)
- response.handle = BuildHandle(
- self, response=response, build_id=None,
- projectname=projectname, username=username
- )
+ response.handle = BaseHandle(
+ self, response=response,
+ projectname=projectname, username=username)
+
return response
def get_project_details(self, projectname, username=None):
@@ -318,7 +318,7 @@ class CoprClient(object):
- text fields: "description", "instructions", "last_modified",
"name"
- - **chroots_list**: list of
+ - **chroots**: list of
:py:class:`~.responses.ProjectChrootWrapper`
"""
if not username:
@@ -485,6 +485,7 @@ class CoprClient(object):
data=result_data,
parsers=[
CommonMsgErrorOutParser,
+ ProjectDetailsFieldsParser,
fabric_simple_fields_parser(["buildroot_pkgs"])
]
)
diff --git a/python/copr/client/parsers.py b/python/copr/client/parsers.py
index 159653b..aa8338c 100644
--- a/python/copr/client/parsers.py
+++ b/python/copr/client/parsers.py
@@ -82,7 +82,7 @@ class ProjectChrootsParser(IParser):
chrootname=chrootname,
repo_url=url
)
- for chrootname, url in data["detail"]["yum_repos"].iteritems()
+ for chrootname, url in data["detail"]["yum_repos"].items()
]
else:
raise KeyError("Response missing data about chroots")
diff --git a/python/copr/client/responses.py b/python/copr/client/responses.py
index 10aea13..7871234 100644
--- a/python/copr/client/responses.py
+++ b/python/copr/client/responses.py
@@ -132,6 +132,13 @@ class ProjectHandle(BaseHandle):
return self.client.delete_project(
self.projectname, username=self.username)
+ def create_new_build(self, src_pkgs, chroots=None):
+ """
+ Shortcut to :meth"`~.client.CoprClient.create_new_build'
+ """
+ return self.client.create_new_build(self.projectname,
+ src_pkgs, chroots)
+
class BuildHandle(BaseHandle):
"""
diff --git a/python/docs/Examples.rst b/python/docs/Examples.rst
new file mode 100644
index 0000000..540ca2b
--- /dev/null
+++ b/python/docs/Examples.rst
@@ -0,0 +1,98 @@
+Create client
+-------------
+::
+
+ from copr.client import CoprClient
+ cl = CoprClient.create_from_file_config()
+
+
+Get projects list
+-----------------
+::
+
+ # your projects
+ result = cl.get_projects_list().projects_list
+
+ # other user projects
+ result = cl.get_projects_list(username="rhscl")
+
+ # print list for humans and machines
+ from pprint import pprint
+ for prj in result.projects_list:
+ print(prj)
+ pprint(prj.get_project_details().data)
+
+
+Search for projects
+-------------------
+::
+
+ result = cl.search_projects("python")
+ # print list for humans
+ for prj in result.projects_list:
+ print(prj)
+
+
+
+Create/update/delete project
+----------------------------
+::
+
+ result = cl.create_project("hello_world", chroots=["fedora-20-x86_64"],
+ description="My cool app")
+
+ # assert correct description
+ assert result.handle.get_project_details().description == "My cool app"
+
+ # add instruction
+ result.handle.modify_project(instructions="How does one patch KDE2 under FreeBSD?")
+ # which is shorter than
+ cl.modify_project("hello_world", instructions="...")
+
+ # delete project
+ result.handle.delete_project()
+ # again shortcut for
+ cl.delete_project("hello_world")
+
+
+
+Work with builds
+----------------
+::
+
+ # building new package
+ result = cl.create_new_build("hello_world",
+ pkgs=["http://example.com/pkg.src.rpm",])
+
+ # retrieve build statuses
+ for bw in result.builds_list:
+ print("{}:{}".format(bw.build_id, bw.handle.get_build_details().status))
+
+ # cancel all created build
+ for bw in result.builds_list:
+ bw.handle.cancel_build()
+
+ # get build status for each chroot
+ for bw in result.builds_list:
+ print("build: {}".format(bw.build_id))
+ for ch, status in bw.handle.get_build_details().data["chroots"].items():
+ print("\t chroot {}:\t {}".format(ch, status))
+
+ # simple build progress:
+ import time, datetime
+ watched = set(result.builds_list)
+ done = set()
+ while watched != done:
+ print("time: {}".format(datetime.datetime.now()))
+ for bw in watched:
+ if bw in done:
+ continue
+ status = bw.handle.get_build_details().status
+ print("{}: {}".format(bw.build_id, status))
+ if status in ["skipped", "failed", "succeeded"]:
+ done.add(bw)
+ time.sleep(10)
+
+ # cancel all created build
+ for bw in result.builds_list:
+ bw.handle.cancel_build()
diff --git a/python/docs/conf.py b/python/docs/conf.py
index f26ddbf..c8bb7ce 100644
--- a/python/docs/conf.py
+++ b/python/docs/conf.py
@@ -50,9 +50,9 @@ copyright = u'2014, Valentin Gologuzov'
# built documents.
#
# The short X.Y version.
-version = '1.48'
+version = '1.52'
# The full version, including alpha/beta/rc tags.
-release = '1.48'
+release = '1.52'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/python/docs/index.rst b/python/docs/index.rst
index 653c34a..75bd2a6 100644
--- a/python/docs/index.rst
+++ b/python/docs/index.rst
@@ -64,19 +64,21 @@ are wrapped into the Response object.
Depending on used methods Responses will have different set of
provided attributes and methods.
+.. toctree::
+ Examples
-Auto-generated documentation
-----------------------------
+Autodoc
+-------
See method signatures and response objects in
the auto generated documentation:
.. toctree::
-
CoprClient
Responses
+
Indices and tables
==================
9 years, 7 months
[copr] master: added new record to tito releasers.conf (f8f64ab)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit f8f64ab320b283a8d7e84a22ac2b24b06b152fd0
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Sep 18 18:44:21 2014 +0200
added new record to tito releasers.conf
>---------------------------------------------------------------
rel-eng/releasers.conf | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/rel-eng/releasers.conf b/rel-eng/releasers.conf
index e14db9e..0897d56 100644
--- a/rel-eng/releasers.conf
+++ b/rel-eng/releasers.conf
@@ -22,3 +22,11 @@ project_name = copr-dev
upload_command = scp %(srpm)s lomenotecka.cz:www/copr/
remote_location = http://miroslav.suchy.cz/copr/
builder.test = 1
+
+
+[copr-vgologuz]
+releaser = tito.release.CoprReleaser
+project_name = msuchy/copr
+upload_command = scp %(srpm)s people.redhat.com:public_html/copr-rel/
+remote_location = http://people.redhat.com/~vgologuz/copr-rel/
+
9 years, 7 months