]> git.lizzy.rs Git - cheatdb.git/blob - app/tests/utils.py
Add Gitlab CI support
[cheatdb.git] / app / tests / utils.py
1 import pytest
2 from app import app
3 from app.models import db, User
4 from app.default_data import populate
5
6 def clear_data(session):
7         meta = db.metadata
8         for table in reversed(meta.sorted_tables):
9                 session.execute(f'ALTER TABLE "{table.name}" DISABLE TRIGGER ALL;')
10                 session.execute(table.delete())
11                 session.execute(f'ALTER TABLE "{table.name}" ENABLE TRIGGER ALL;')
12                 #session.execute(table.delete())
13
14 def recreate_db():
15         clear_data(db.session)
16         populate(db.session)
17         db.session.commit()
18
19
20 @pytest.fixture
21 def client():
22         app.config["TESTING"] = True
23
24         recreate_db()
25         assert User.query.count() == 1
26
27         with app.test_client() as client:
28                 yield client
29
30         app.config["TESTING"] = False