From a9f19321f3e89e360e40f98a2b28a5117b51f728 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 15:43:11 +0000 Subject: [PATCH 1/8] Use the path variable to avoid returning None/foo when creating a new project --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index be0ae3d..9211850 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1299,8 +1299,8 @@ def new_project(session, user, name, blacklist, allowed_prefix, repo = pagure.lib.get_project(session, name, namespace=namespace) if repo: raise pagure.exceptions.RepoExistsException( - 'The project repo "%s/%s" already exists in the database' % ( - namespace, name) + 'The project repo "%s" already exists in the database' % ( + path) ) project = model.Project( From d3e4c9063171d1cdd9c6694946ca019c6a58b5f9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 15:43:35 +0000 Subject: [PATCH 2/8] When ordering the projects, put the ones without namespace first --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 91f5be6..7a14e2e 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -408,7 +408,7 @@ class Project(BASE): secondaryjoin="pagure_group.c.id==projects_groups.c.group_id", backref=backref( "projects", - order_by="func.lower(projects.c.namespace), func.lower(projects.c.name)" + order_by="func.lower(projects.c.namespace).desc(), func.lower(projects.c.name)" ) ) From f58afb7ce2508ecc4edc9809ba32e025c3c14125 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 15:43:54 +0000 Subject: [PATCH 3/8] Use faitout if an URL is specified as environment variable: FAITOUT_URL --- diff --git a/tests/__init__.py b/tests/__init__.py index e1af9ae..3f0782e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -41,13 +41,15 @@ from pagure.lib.repo import PagureRepo DB_PATH = 'sqlite:///:memory:' FAITOUT_URL = 'http://faitout.fedorainfracloud.org/' +if os.environ.get('FAITOUT_URL'): + FAITOUT_URL = os.environ.get('FAITOUT_URL') HERE = os.path.join(os.path.dirname(os.path.abspath(__file__))) LOG = logging.getLogger("pagure") LOG.setLevel(logging.DEBUG) LOG.info('BUILD_ID: %s', os.environ.get('BUILD_ID')) -if os.environ.get('BUILD_ID'): +if os.environ.get('BUILD_ID')or os.environ.get('FAITOUT_URL'): try: import requests req = requests.get('%s/new' % FAITOUT_URL) From b63f2839d148bdcea36819b7cd786343bec907c7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 15:45:02 +0000 Subject: [PATCH 4/8] Fix running the unit-tests against faitout --- diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 6f5d2cc..9e510a3 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - (c) 2015 - Copyright Red Hat Inc + (c) 2015-2017 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon @@ -374,6 +374,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): """ Test the api_new_project method of the flask api. """ p_gga.return_value = True + tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, 'tickets')) tests.create_tokens(self.session) tests.create_tokens_acl(self.session) @@ -437,7 +438,8 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.assertDictEqual( data, { - "error": "The tickets repo \"test.git\" already exists", + "error": "The project repo \"test\" already exists " + "in the database", "error_code": "ENOCODE" } ) diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 63daf1c..a9fb004 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - (c) 2015 - Copyright Red Hat Inc + (c) 2015-2017 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon @@ -12,11 +12,14 @@ __requires__ = ['SQLAlchemy >= 0.8'] import pkg_resources -import unittest +import datetime +import os import shutil import sys -import os import tempfile +import time +import unittest + import pygit2 from mock import patch @@ -1206,6 +1209,12 @@ index 0000000..60f7480 #print patch self.assertEqual(patch, exp) + # Enforce having a different last_updated field + # This is required as the test run fine and fast with sqlite but is + # much slower with postgresql so we end-up with an updated + # last_updated in postgresql but not with sqlite + time.sleep(1) + # Test again after adding a comment msg = pagure.lib.add_issue_comment( session=self.session, @@ -1232,7 +1241,7 @@ diff --git a/123 b/456 index 458821a..77674a8 --- a/123 +++ b/456 -@@ -3,7 +3,25 @@ +@@ -3,13 +3,31 @@ "blocks": [], "close_status": null, "closed_at": null, @@ -1259,6 +1268,13 @@ index 458821a..77674a8 "content": "We should work on this", "custom_fields": [], "date_created": null, + "depends": [], + "id": 1, +- "last_updated": "", ++ "last_updated": "", + "milestone": null, + "priority": null, + "private": false, """ npatch = [] @@ -1288,6 +1304,9 @@ index 458821a..77674a8 row = '--- a/123' elif row.startswith('+++ b/'): row = '+++ b/456' + elif 'last_updated' in row: + t = row.split(': ')[0] + row = '%s: "",' % t npatch.append(row) patch = '\n'.join(npatch) #print patch diff --git a/tests/test_pagure_lib_model.py b/tests/test_pagure_lib_model.py index 336ecfe..48e45eb 100644 --- a/tests/test_pagure_lib_model.py +++ b/tests/test_pagure_lib_model.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - (c) 2015 - Copyright Red Hat Inc + (c) 2015-2017 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon @@ -205,7 +205,7 @@ class PagureLibModeltests(tests.Modeltests): group_name='testgrp', display_name='Test group', description=None, - group_type='users', + group_type='user', user_id=1, # pingou ) item.close_status = ['Invalid', 'Fixed', 'Duplicate'] From 9ee9ee399c02d764c84b5bb22e96bd99dd073c07 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 17:50:39 +0000 Subject: [PATCH 5/8] Provide some more info about the test running --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index 701beb1..1e5d32d 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -7,6 +7,10 @@ git checkout origin/master git config --global user.email "you@example.com" git config --global user.name "Your Name" git merge --no-ff "proposed/$BRANCH" -m "Merge PR" + +echo "Running tests for branch $BRANCH of repo $REPO" +echo "Last commit:" +git log -1 fi From 7cbdb19779ace32a59a8206e3848c3aa2866c881 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 17:53:01 +0000 Subject: [PATCH 6/8] Ignore return code from pylint and pep8 --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index 1e5d32d..4143ed1 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -50,6 +50,6 @@ python setup.py build PYTHONPATH=pagure ./nosetests -v --with-xcoverage --cover-erase --cover-package=pagure -PYTHONPATH=pagure pylint -f parseable pagure | tee pylint.out -pep8 pagure/*.py pagure/*/*.py | tee pep8.out +PYTHONPATH=pagure pylint -f parseable pagure | tee pylint.out || true +pep8 pagure/*.py pagure/*/*.py | tee pep8.out || true From 8d14435991e5f715ef8e88acebd8fc55b940ebb2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 18:22:04 +0000 Subject: [PATCH 7/8] Try another way to check the test results --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index 4143ed1..b701f9c 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -44,12 +44,14 @@ trap deactive SIGINT SIGTERM EXIT # Reload where the nosetests app is (within the venv) hash -r -set -e python setup.py build PYTHONPATH=pagure ./nosetests -v --with-xcoverage --cover-erase --cover-package=pagure -PYTHONPATH=pagure pylint -f parseable pagure | tee pylint.out || true -pep8 pagure/*.py pagure/*/*.py | tee pep8.out || true +if [ "$?" = "0" ]; then + PYTHONPATH=pagure pylint -f parseable pagure | tee pylint.out + pep8 pagure/*.py pagure/*/*.py | tee pep8.out + +fi From b1bbd1cc4a5e1af05565f5ff4bb930305a317691 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 15 2017 18:30:09 +0000 Subject: [PATCH 8/8] Typo in the deactivate command --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index b701f9c..cfb7cc3 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -38,7 +38,7 @@ then else source pagureenv-$DATE-$HASH/bin/activate fi -trap deactive SIGINT SIGTERM EXIT +trap deactivate SIGINT SIGTERM EXIT # Reload where the nosetests app is (within the venv)