diff --git a/tests/python/helpers.py b/tests/python/helpers.py new file mode 100644 index 0000000..dbd700d --- /dev/null +++ b/tests/python/helpers.py @@ -0,0 +1,11 @@ +"""Helpers for Python tests""" +import common.helpers + + +def delete_tables(engine, *table_names): + """Delete all rows from tables in `table_names' in order.""" + with common.helpers.tables(engine, *table_names) as tables: + connection = tables[0] + tables = tables[1:] + for table in tables: + table.delete().execute() diff --git a/tests/python/test_views.py b/tests/python/test_views.py index f20658c..212d007 100644 --- a/tests/python/test_views.py +++ b/tests/python/test_views.py @@ -5,6 +5,7 @@ from cycledash import app, db from common.helpers import tables, find +from helpers import delete_tables import cycledash.views from test_projects_api import create_project_with_name @@ -38,12 +39,7 @@ def setUp(self): self.run = dict(res.fetchone()) def tearDown(self): - with tables(db.engine, 'projects', 'bams', 'vcfs', 'user_comments') \ - as (con, projects, bams, runs, comments): - comments.delete().execute() - runs.delete().execute() - bams.delete().execute() - projects.delete().execute() + delete_tables(db.engine, 'user_comments', 'vcfs', 'bams', 'projects') self.ctx.pop() mocked.reset_mock()