Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit c3b82862bf8a59617139d611e07ad78fd50a39e4
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Oct 23 15:12:34 2014 +0200
[backend] minor changes in createrepo
---------------------------------------------------------------
{cli => backend}/.coveragerc | 0
backend/backend/createrepo.py | 10 ++++++----
backend/run/copr_create_repo.py | 18 +++++++++++-------
backend/run_test.sh | 2 +-
backend/tests/test_createrepo.py | 5 ++---
backend/tests/test_run_copr_create_repo.py | 27 +++++++++++++++++----------
6 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/cli/.coveragerc b/backend/.coveragerc
similarity index 100%
copy from cli/.coveragerc
copy to backend/.coveragerc
diff --git a/backend/backend/createrepo.py b/backend/backend/createrepo.py
index 0c1bbfe..0319c8e 100644
--- a/backend/backend/createrepo.py
+++ b/backend/backend/createrepo.py
@@ -43,8 +43,9 @@ def createrepo_unsafe(path, lock=None):
def get_auto_createrepo_status(front_url, username, projectname):
client = CoprClient({"copr_url": front_url})
result = client.get_project_details(projectname, username)
- if "auto_createrepo" in result.data:
- return bool(result.data["auto_createrepo"])
+
+ if "auto_createrepo" in result.data["detail"]:
+ return bool(result.data["detail"]["auto_createrepo"])
else:
return True
@@ -53,6 +54,7 @@ def createrepo(path, front_url, username, projectname, lock=None):
# TODO: add means of logging
if get_auto_createrepo_status(front_url, username, projectname):
- createrepo_unsafe(path, lock)
-
+ return createrepo_unsafe(path, lock)
+ else:
+ return None
diff --git a/backend/run/copr_create_repo.py b/backend/run/copr_create_repo.py
index 56022ed..ea11a1a 100644
--- a/backend/run/copr_create_repo.py
+++ b/backend/run/copr_create_repo.py
@@ -6,9 +6,7 @@ from backend.createrepo import createrepo
from backend.helpers import SortedOptParser
-
def main(args):
- print(args)
parser = SortedOptParser(
"mockremote -u user_name -p copr_project repo_dir")
@@ -19,8 +17,8 @@ def main(args):
parser.add_option("-p", "--project", dest="project",
help="copr project name")
- parser.add_option("-a", "--api_url", dest="api_url",
- help="copr frontend api url")
+ parser.add_option("-f", "--front_url",
dest="front_url",
+ help="copr frontend url")
opts, args = parser.parse_args(args)
@@ -32,7 +30,7 @@ def main(args):
print("No project was specified, exiting", file=sys.stderr)
sys.exit(1)
- if not opts.api_url:
+ if not opts.front_url:
print("No api url was specified, exiting", file=sys.stderr)
sys.exit(1)
@@ -40,8 +38,14 @@ def main(args):
print("No directory with repo was specified, exiting",
file=sys.stderr)
sys.exit(1)
- createrepo(path=args[0], front_url=opts.api_url,
- username=opts.user, projectname=opts.project)
+ result = createrepo(path=args[0], front_url=opts.front_url,
+ username=opts.user, projectname=opts.project)
+ if not result:
+ print("Createrepo was skipped")
+ else:
+ retcode, stdout, stderr = result
+ print("STDOUT: {}".format(stdout))
+ print("STDERR: {}".format(stderr))
if __name__ == "__main__":
diff --git a/backend/run_test.sh b/backend/run_test.sh
index fa1d6ef..dfa8b45 100755
--- a/backend/run_test.sh
+++ b/backend/run_test.sh
@@ -1,4 +1,4 @@
#!/bin/sh
-PYTHONPATH=backend:run:$PYTHONPATH python -B -m pytest -s --cov-report term-missing --cov
./backend ./tests/ $@
+PYTHONPATH=backend:run:$PYTHONPATH python -B -m pytest -s --cov-report term-missing --cov
./backend --cov ./run ./tests/ $@
#PYTHONPATH=../python/:./copr_cli:$PYTHONPATH python3 -B -m pytest --cov-report
term-missing --cov ./copr_cli/ $@
diff --git a/backend/tests/test_createrepo.py b/backend/tests/test_createrepo.py
index 0d48e51..23dfad6 100644
--- a/backend/tests/test_createrepo.py
+++ b/backend/tests/test_createrepo.py
@@ -27,7 +27,7 @@ from backend.createrepo import createrepo, createrepo_unsafe
@mock.patch('backend.createrepo.createrepo_unsafe')
@mock.patch('backend.createrepo.CoprClient')
def test_createrepo_conditional(mc_client, mc_create_unsafe):
- mc_client.return_value.get_project_details.return_value = MagicMock(data={})
+ mc_client.return_value.get_project_details.return_value =
MagicMock(data={"detail": {}})
createrepo(path="/tmp/",
front_url="http://example.com/api",
username="foo", projectname="bar", lock=None)
@@ -35,7 +35,7 @@ def test_createrepo_conditional(mc_client, mc_create_unsafe):
mc_create_unsafe.reset_mock()
for val in [True, False]:
- mc_client.return_value.get_project_details.return_value =
MagicMock(data={"auto_createrepo": val})
+ mc_client.return_value.get_project_details.return_value =
MagicMock(data={"detail": {"auto_createrepo": val}})
createrepo(path="/tmp/",
front_url="http://example.com/api",
username="foo", projectname="bar", lock=None)
@@ -129,5 +129,4 @@ class TestCreaterepoUnsafe(object):
createrepo_unsafe(path, None)
- print(mc_popen.call_args)
assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
diff --git a/backend/tests/test_run_copr_create_repo.py
b/backend/tests/test_run_copr_create_repo.py
index 4bc4781..c5e0bd9 100644
--- a/backend/tests/test_run_copr_create_repo.py
+++ b/backend/tests/test_run_copr_create_repo.py
@@ -26,16 +26,23 @@ from copr_create_repo import main as createrepo_main
@mock.patch("copr_create_repo.createrepo")
class TestArgParser(object):
- def test_arg_parser_good_input(self, mc_main, capsys):
- args = ['-u', 'foo', '-p', 'bar', '-a',
'http://example.com/api/', '/tmp']
+ def test_arg_parser_good_input(self, mc_createrepo, capsys):
+ args = ['-u', 'foo', '-p', 'bar', '-f',
'http://example.com/api/', '/tmp']
+ mc_createrepo.return_value = 0, "", ""
createrepo_main(args)
- stdout, stderr = capsys.readouterr()
- assert mc_main.call_args == mock.call(username='foo',
projectname='bar',
-
front_url='http://example.com/api/';,
path='/tmp')
+
+ assert mc_createrepo.call_args == mock.call(username='foo',
projectname='bar',
+
front_url='http://example.com/api/';, path='/tmp')
+
+ mc_createrepo.return_value = None
+ createrepo_main(args)
+
+ assert mc_createrepo.call_args == mock.call(username='foo',
projectname='bar',
+
front_url='http://example.com/api/';, path='/tmp')
def test_arg_parser_missing_path(self, mc_main, capsys):
- args = ['-u', 'foo', '-p', 'bar', '-a',
'http://example.com/api/']
+ args = ['-u', 'foo', '-p', 'bar', '-f',
'http://example.com/api/']
with pytest.raises(SystemExit) as err:
createrepo_main(args)
@@ -45,7 +52,7 @@ class TestArgParser(object):
assert "No directory" in stderr
def test_arg_parser_missing_user(self, mc_main, capsys):
- args = ['-p', 'bar', '-a',
'http://example.com/api/', '/tmp']
+ args = ['-p', 'bar', '-f',
'http://example.com/api/', '/tmp']
with pytest.raises(SystemExit) as err:
createrepo_main(args)
@@ -56,7 +63,7 @@ class TestArgParser(object):
def test_arg_parser_missing_project(self, mc_main, capsys):
- args = ['-u', 'foo', '-a',
'http://example.com/api/', '/tmp']
+ args = ['-u', 'foo', '-f',
'http://example.com/api/', '/tmp']
with pytest.raises(SystemExit) as err:
createrepo_main(args)
@@ -65,7 +72,7 @@ class TestArgParser(object):
stdout, stderr = capsys.readouterr()
assert "No project" in stderr
- def test_arg_parser_missing_project(self, mc_main, capsys):
+ def test_arg_parser_missing_front(self, mc_main, capsys):
args = ['-u', 'foo', '-p', 'bar',
'/tmp']
with pytest.raises(SystemExit) as err:
@@ -73,5 +80,5 @@ class TestArgParser(object):
assert err.value.code == 1
stdout, stderr = capsys.readouterr()
- assert "No api url" in stderr
+ assert "No front url" in stderr