diff --git a/tests/__init__.py b/tests/__init__.py index fe49fc7..eff48a2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -140,8 +140,10 @@ def user_set(APP, user): yield -class Modeltests(unittest.TestCase): - """ Model tests. """ +class SimplePagureTest(unittest.TestCase): + """ + Simple Test class that does not set a broker/worker + """ def __init__(self, method_name='runTest'): """ Constructor. """ @@ -171,14 +173,9 @@ class Modeltests(unittest.TestCase): perfrepo.reset_stats() perfrepo.REQUESTS = [] - def setUp(self): # pylint: disable=invalid-name - """ Set up the environnment, ran before every tests. """ - # Clean up test performance info - perfrepo.reset_stats() - perfrepo.REQUESTS = [] + def setUp(self): + self.perfReset() - pagure.REDIS = None - pagure.lib.REDIS = None if self.path is not None: raise Exception('Double init?!') self.path = tempfile.mkdtemp(prefix='pagure-tests-path-') @@ -199,44 +196,9 @@ class Modeltests(unittest.TestCase): with open(os.path.join(self.path, 'config'), 'w') as f: f.write(CONFIG_TEMPLATE % config_values) - # Create a broker - broker_url = os.path.join(self.path, 'broker') - - self.broker = subprocess.Popen( - ['/usr/bin/redis-server', '--unixsocket', broker_url, '--port', - '0', '--loglevel', 'warning', '--logfile', '/dev/null'], - stdout=None, stderr=None) - self.broker.poll() - if self.broker.returncode is not None: - raise Exception('Broker failed to start') - self.session = pagure.lib.model.create_tables( self.dbpath, acls=pagure.APP.config.get('ACLS', {})) - celery_broker_url = 'redis+socket://' + broker_url - pagure.APP.config['BROKER_URL'] = celery_broker_url - reload(pagure.lib.tasks) - - # Start a worker - # Using cocurrency 2 to test with some concurrency, but not be heavy - # Using eventlet so that worker.terminate kills everything - self.workerlog = open(os.path.join(self.path, 'worker.log'), 'w') - self.worker = subprocess.Popen( - ['/usr/bin/celery', '-A', 'pagure.lib.tasks', 'worker', - '--loglevel=info', '--concurrency=2', '--pool=eventlet', - '--without-gossip', '--without-mingle', '--quiet'], - env={'PAGURE_BROKER_URL': celery_broker_url, - 'PAGURE_CONFIG': os.path.join(self.path, 'config'), - 'PYTHONPATH': '.'}, - cwd=os.path.normpath(os.path.join(os.path.dirname(__file__), - '..')), - stdout=self.workerlog, - stderr=self.workerlog) - self.worker.poll() - if self.worker.returncode is not None: - raise Exception('Worker failed to start') - time.sleep(2) - # Create a couple of users item = pagure.lib.model.User( user='pingou', @@ -282,11 +244,8 @@ class Modeltests(unittest.TestCase): pagure.APP.config['ATTACHMENTS_FOLDER'] = os.path.join( self.path, 'attachments') self.app = pagure.APP.test_client() - self.app.get = create_maybe_waiter(self.app.get, self.app.get) - self.app.post = create_maybe_waiter(self.app.post, self.app.get) - def tearDown(self): # pylint: disable=invalid-name - """ Remove the test.db database if there is one. """ + def tearDown(self): self.session.close() # Clear DB @@ -295,19 +254,6 @@ class Modeltests(unittest.TestCase): db_name = self.dbpath.rsplit('/', 1)[1] requests.get('%s/clean/%s' % (FAITOUT_URL, db_name)) - # Terminate worker and broker - # We just send a SIGKILL (kill -9), since when the test finishes, we - # don't really care about the output of either worker or broker - # anymore - self.worker.kill() - self.worker.wait() - self.worker = None - self.workerlog.close() - self.workerlog = None - self.broker.kill() - self.broker.wait() - self.broker = None - # Remove testdir shutil.rmtree(self.path) self.path = None @@ -321,6 +267,71 @@ class Modeltests(unittest.TestCase): return output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] +class Modeltests(SimplePagureTest): + """ Model tests. """ + + def setUp(self): # pylint: disable=invalid-name + """ Set up the environnment, ran before every tests. """ + # Clean up test performance info + super(Modeltests, self).setUp() + + pagure.REDIS = None + pagure.lib.REDIS = None + + # Create a broker + broker_url = os.path.join(self.path, 'broker') + + self.broker = subprocess.Popen( + ['/usr/bin/redis-server', '--unixsocket', broker_url, '--port', + '0', '--loglevel', 'warning', '--logfile', '/dev/null'], + stdout=None, stderr=None) + self.broker.poll() + if self.broker.returncode is not None: + raise Exception('Broker failed to start') + + celery_broker_url = 'redis+socket://' + broker_url + pagure.APP.config['BROKER_URL'] = celery_broker_url + reload(pagure.lib.tasks) + + # Start a worker + # Using cocurrency 2 to test with some concurrency, but not be heavy + # Using eventlet so that worker.terminate kills everything + self.workerlog = open(os.path.join(self.path, 'worker.log'), 'w') + self.worker = subprocess.Popen( + ['/usr/bin/celery', '-A', 'pagure.lib.tasks', 'worker', + '--loglevel=info', '--concurrency=2', '--pool=eventlet', + '--without-gossip', '--without-mingle', '--quiet'], + env={'PAGURE_BROKER_URL': celery_broker_url, + 'PAGURE_CONFIG': os.path.join(self.path, 'config'), + 'PYTHONPATH': '.'}, + cwd=os.path.normpath(os.path.join(os.path.dirname(__file__), + '..')), + stdout=self.workerlog, + stderr=self.workerlog) + self.worker.poll() + if self.worker.returncode is not None: + raise Exception('Worker failed to start') + time.sleep(2) + + self.app.get = create_maybe_waiter(self.app.get, self.app.get) + self.app.post = create_maybe_waiter(self.app.post, self.app.get) + + def tearDown(self): # pylint: disable=invalid-name + """ Remove the test.db database if there is one. """ + super(Modeltests, self).tearDown() + # Terminate worker and broker + # We just send a SIGKILL (kill -9), since when the test finishes, we + # don't really care about the output of either worker or broker + # anymore + self.worker.kill() + self.worker.wait() + self.worker = None + self.workerlog.close() + self.workerlog = None + self.broker.kill() + self.broker.wait() + self.broker = None + class FakeGroup(object): # pylint: disable=too-few-public-methods """ Fake object used to make the FakeUser object closer to the diff --git a/tests/test_pagure_flask.py b/tests/test_pagure_flask.py index 9157677..d8fdf7a 100644 --- a/tests/test_pagure_flask.py +++ b/tests/test_pagure_flask.py @@ -29,7 +29,7 @@ import pagure.lib.model import tests -class PagureGetRemoteRepoPath(tests.Modeltests): +class PagureGetRemoteRepoPath(tests.SimplePagureTest): """ Tests for pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_api.py b/tests/test_pagure_flask_api.py index fbee2a2..7891a4e 100644 --- a/tests/test_pagure_flask_api.py +++ b/tests/test_pagure_flask_api.py @@ -26,7 +26,7 @@ import pagure.lib import tests -class PagureFlaskApitests(tests.Modeltests): +class PagureFlaskApitests(tests.SimplePagureTest): """ Tests for flask API controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_api_auth.py b/tests/test_pagure_flask_api_auth.py index afdd070..567959f 100644 --- a/tests/test_pagure_flask_api_auth.py +++ b/tests/test_pagure_flask_api_auth.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskApiAuthtests(tests.Modeltests): +class PagureFlaskApiAuthtests(tests.SimplePagureTest): """ Tests for the authentication in the flask API of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_api_group.py b/tests/test_pagure_flask_api_group.py index 19977b7..3e267fa 100644 --- a/tests/test_pagure_flask_api_group.py +++ b/tests/test_pagure_flask_api_group.py @@ -22,7 +22,7 @@ import pagure.lib import tests -class PagureFlaskApiGroupTests(tests.Modeltests): +class PagureFlaskApiGroupTests(tests.SimplePagureTest): """ Tests for the flask API of pagure for issue """ def setUp(self): diff --git a/tests/test_pagure_flask_docs.py b/tests/test_pagure_flask_docs.py index 90077cb..b6608d0 100644 --- a/tests/test_pagure_flask_docs.py +++ b/tests/test_pagure_flask_docs.py @@ -31,7 +31,7 @@ import tests from pagure.lib.repo import PagureRepo -class PagureFlaskDocstests(tests.Modeltests): +class PagureFlaskDocstests(tests.SimplePagureTest): """ Tests for flask docs of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_form.py b/tests/test_pagure_flask_form.py index 2b16546..0b4a6a5 100644 --- a/tests/test_pagure_flask_form.py +++ b/tests/test_pagure_flask_form.py @@ -28,7 +28,7 @@ import pagure.forms import tests -class PagureFlaskFormTests(tests.Modeltests): +class PagureFlaskFormTests(tests.SimplePagureTest): """ Tests for forms of the flask application """ def setUpt(self): diff --git a/tests/test_pagure_flask_ui_app_give_project.py b/tests/test_pagure_flask_ui_app_give_project.py index c3a0416..ea5cb08 100644 --- a/tests/test_pagure_flask_ui_app_give_project.py +++ b/tests/test_pagure_flask_ui_app_give_project.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskGiveRepotests(tests.Modeltests): +class PagureFlaskGiveRepotests(tests.SimplePagureTest): """ Tests for give a project on pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_login.py b/tests/test_pagure_flask_ui_login.py index 5312a0d..d4ce901 100644 --- a/tests/test_pagure_flask_ui_login.py +++ b/tests/test_pagure_flask_ui_login.py @@ -35,7 +35,7 @@ from pagure.lib.repo import PagureRepo import pagure.ui.login -class PagureFlaskLogintests(tests.Modeltests): +class PagureFlaskLogintests(tests.SimplePagureTest): """ Tests for flask app controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_no_master_branch.py b/tests/test_pagure_flask_ui_no_master_branch.py index 9f82fa9..a410eb8 100644 --- a/tests/test_pagure_flask_ui_no_master_branch.py +++ b/tests/test_pagure_flask_ui_no_master_branch.py @@ -29,7 +29,7 @@ import tests from pagure.lib.repo import PagureRepo -class PagureFlaskNoMasterBranchtests(tests.Modeltests): +class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest): """ Tests for flask application when the git repo has no master branch. """ diff --git a/tests/test_pagure_flask_ui_old_commit.py b/tests/test_pagure_flask_ui_old_commit.py index ac09026..03595a4 100644 --- a/tests/test_pagure_flask_ui_old_commit.py +++ b/tests/test_pagure_flask_ui_old_commit.py @@ -30,7 +30,7 @@ import tests from pagure.lib.repo import PagureRepo -class PagureFlaskRepoOldUrltests(tests.Modeltests): +class PagureFlaskRepoOldUrltests(tests.SimplePagureTest): """ Tests for flask app controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins.py b/tests/test_pagure_flask_ui_plugins.py index 420860b..57f0780 100644 --- a/tests/test_pagure_flask_ui_plugins.py +++ b/tests/test_pagure_flask_ui_plugins.py @@ -40,7 +40,7 @@ class FakeForm(wtforms.Form): ) -class PagureFlaskPluginstests(tests.Modeltests): +class PagureFlaskPluginstests(tests.SimplePagureTest): """ Tests for flask plugins controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_fedmsg.py b/tests/test_pagure_flask_ui_plugins_fedmsg.py index ad41463..d057793 100644 --- a/tests/test_pagure_flask_ui_plugins_fedmsg.py +++ b/tests/test_pagure_flask_ui_plugins_fedmsg.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginFedmsgtests(tests.Modeltests): +class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest): """ Tests for fedmsg plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_irc.py b/tests/test_pagure_flask_ui_plugins_irc.py index ff3f74d..301f493 100644 --- a/tests/test_pagure_flask_ui_plugins_irc.py +++ b/tests/test_pagure_flask_ui_plugins_irc.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginIRCtests(tests.Modeltests): +class PagureFlaskPluginIRCtests(tests.SimplePagureTest): """ Tests for pagure_hook plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_mail.py b/tests/test_pagure_flask_ui_plugins_mail.py index 6cafe65..1ad2c5e 100644 --- a/tests/test_pagure_flask_ui_plugins_mail.py +++ b/tests/test_pagure_flask_ui_plugins_mail.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginMailtests(tests.Modeltests): +class PagureFlaskPluginMailtests(tests.SimplePagureTest): """ Tests for flask plugins controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_noff.py b/tests/test_pagure_flask_ui_plugins_noff.py index 1f90245..1b1c5df 100644 --- a/tests/test_pagure_flask_ui_plugins_noff.py +++ b/tests/test_pagure_flask_ui_plugins_noff.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginNoFFtests(tests.Modeltests): +class PagureFlaskPluginNoFFtests(tests.SimplePagureTest): """ Tests for Block non fast-forward pushes plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_pagure_ci.py b/tests/test_pagure_flask_ui_plugins_pagure_ci.py index aea146d..9c28e8b 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ci.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ci.py @@ -24,7 +24,7 @@ import pagure.lib import tests -class PagureFlaskPluginPagureCItests(tests.Modeltests): +class PagureFlaskPluginPagureCItests(tests.SimplePagureTest): """ Tests for flask plugins controller of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_pagure_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_hook.py index 66191c8..5d22a77 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_hook.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginPagureHooktests(tests.Modeltests): +class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest): """ Tests for pagure_hook plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py index 742629a..eaaacc3 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginPagureRequestHooktests(tests.Modeltests): +class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest): """ Tests for pagure_hook plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py index 0f223bf..4b3788b 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginPagureTicketHooktests(tests.Modeltests): +class PagureFlaskPluginPagureTicketHooktests(tests.SimplePagureTest): """ Tests for pagure_hook plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_rtd_hook.py b/tests/test_pagure_flask_ui_plugins_rtd_hook.py index 03258b2..bfa37a6 100644 --- a/tests/test_pagure_flask_ui_plugins_rtd_hook.py +++ b/tests/test_pagure_flask_ui_plugins_rtd_hook.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginRtdHooktests(tests.Modeltests): +class PagureFlaskPluginRtdHooktests(tests.SimplePagureTest): """ Tests for rtd_hook plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_plugins_unsigned.py b/tests/test_pagure_flask_ui_plugins_unsigned.py index 9303225..25733e3 100644 --- a/tests/test_pagure_flask_ui_plugins_unsigned.py +++ b/tests/test_pagure_flask_ui_plugins_unsigned.py @@ -27,7 +27,7 @@ import pagure.lib import tests -class PagureFlaskPluginUnsignedtests(tests.Modeltests): +class PagureFlaskPluginUnsignedtests(tests.SimplePagureTest): """ Tests for Block pushes with unsigned commit plugin of pagure """ def setUp(self): diff --git a/tests/test_pagure_flask_ui_repo_slash_name.py b/tests/test_pagure_flask_ui_repo_slash_name.py index 9d8c055..e24f167 100644 --- a/tests/test_pagure_flask_ui_repo_slash_name.py +++ b/tests/test_pagure_flask_ui_repo_slash_name.py @@ -29,7 +29,7 @@ import tests from pagure.lib.repo import PagureRepo -class PagureFlaskSlashInNametests(tests.Modeltests): +class PagureFlaskSlashInNametests(tests.SimplePagureTest): """ Tests for flask application when the project contains a '/'. """ diff --git a/tests/test_pagure_flask_ui_slash_branch_name.py b/tests/test_pagure_flask_ui_slash_branch_name.py index b8463f9..08da657 100644 --- a/tests/test_pagure_flask_ui_slash_branch_name.py +++ b/tests/test_pagure_flask_ui_slash_branch_name.py @@ -29,7 +29,7 @@ import tests from pagure.lib.repo import PagureRepo -class PagureFlaskSlashInBranchtests(tests.Modeltests): +class PagureFlaskSlashInBranchtests(tests.SimplePagureTest): """ Tests for flask application when the branch name contains a '/'. """