aboutsummaryrefslogtreecommitdiff
path: root/app/tests/utils.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-01-19 15:03:38 +0000
committerrubenwardy <rw@rubenwardy.com>2020-01-19 15:03:38 +0000
commit215839c4234ab65807020b42eb67a76cfa6e8767 (patch)
tree06aea997d63878c4ec9054c6c078d8769bc8e9fd /app/tests/utils.py
parent783bc86aaf086ef4f2e23a247f1e157e27018364 (diff)
downloadcheatdb-215839c4234ab65807020b42eb67a76cfa6e8767.tar.xz
Add end-to-end test framework
Diffstat (limited to 'app/tests/utils.py')
-rw-r--r--app/tests/utils.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/tests/utils.py b/app/tests/utils.py
new file mode 100644
index 0000000..214630e
--- /dev/null
+++ b/app/tests/utils.py
@@ -0,0 +1,29 @@
+import pytest
+from app import app
+from app.models import db, User
+from app.default_data import populate
+
+def clear_data(session):
+ meta = db.metadata
+ for table in reversed(meta.sorted_tables):
+ session.execute(f'ALTER TABLE "{table.name}" DISABLE TRIGGER ALL;')
+ session.execute(table.delete())
+ session.execute(f'ALTER TABLE "{table.name}" ENABLE TRIGGER ALL;')
+ #session.execute(table.delete())
+
+def recreate_db():
+ clear_data(db.session)
+ populate(db.session)
+ db.session.commit()
+
+@pytest.fixture
+def client():
+ app.config["TESTING"] = True
+
+ recreate_db()
+ assert User.query.count() == 1
+
+ with app.test_client() as client:
+ yield client
+
+ app.config["TESTING"] = False