Commit a84fcae0f55280e6856a5fc8994b486948906dbc
1 parent
61bd8b00
Exists in
master
and in
4 other branches
Extract code to common test lib
Showing
2 changed files
with
18 additions
and
10 deletions
Show diff stats
tests/backend_tests.py
... | ... | @@ -6,20 +6,14 @@ from shutil import copyfile |
6 | 6 | from pdc_config import TestConfig |
7 | 7 | from app import create_app, db_mgr, db |
8 | 8 | from app.auth.models import User |
9 | +from tests.common_db_feed import resources_to_instancedb | |
9 | 10 | |
10 | 11 | |
11 | 12 | class BaseTestCase(unittest.TestCase): |
12 | 13 | def setUp(self): |
13 | 14 | # initialise app |
14 | 15 | self.app = create_app(TestConfig) |
15 | - | |
16 | - # copy resource demo db to test file | |
17 | - appdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir) | |
18 | - sqlite_file_name = os.path.abspath(os.path.join(appdir, 'resources', 'lesia-btp.sqlite')) | |
19 | - if not os.path.isdir(self.app.instance_path): | |
20 | - os.mkdir(self.app.instance_path) | |
21 | - self.db_path = os.path.join(self.app.instance_path, 'test.db') | |
22 | - copyfile(sqlite_file_name, self.db_path) | |
16 | + self.db_path = resources_to_instancedb(self.app) | |
23 | 17 | |
24 | 18 | # force db path to newly create file |
25 | 19 | self.app.config.update( |
... | ... | @@ -59,4 +53,3 @@ class DbMgrTestCase(BaseTestCase): |
59 | 53 | stacked_charges = db_mgr.charges_by_project_stacked(60) |
60 | 54 | # Waiting for 17 periods + headers line |
61 | 55 | self.assertEqual(18, len(stacked_charges)) |
62 | - | ... | ... |
tests/common_db_feed.py
1 | +import os | |
2 | +from shutil import copyfile | |
3 | + | |
1 | 4 | from app.models import Category, db, Label, Project, ProjectLabel |
2 | 5 | |
6 | + | |
7 | +def resources_to_instancedb(app): | |
8 | + # copy resource demo db to test file | |
9 | + appdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir) | |
10 | + sqlite_file_name = os.path.abspath(os.path.join(appdir, 'resources', 'lesia-btp.sqlite')) | |
11 | + if not os.path.isdir(app.instance_path): | |
12 | + os.mkdir(app.instance_path) | |
13 | + db_path = os.path.join(app.instance_path, 'test.db') | |
14 | + copyfile(sqlite_file_name, db_path) | |
15 | + return db_path | |
16 | + | |
17 | + | |
3 | 18 | categorized_labels = {'pole': ['Spatial', 'Sol'], 'domaine': ['soleil-terre', 'atmosphere', 'r&t', 'géologie']} |
4 | 19 | projects_categories = {'ChemCam': {'pole': 'Spatial', 'domaine': 'géologie'}, |
5 | 20 | 'Pilot': {'pole': 'Spatial', 'domaine': 'atmosphere'}, |
... | ... | @@ -30,7 +45,7 @@ def feed_projects(): |
30 | 45 | n_l = db.session.query(Label).filter(Label.name == l_name).one() |
31 | 46 | n_pc = ProjectLabel(project=n_p, category=n_c, label=n_l) |
32 | 47 | db.session.add(n_pc) |
33 | - | |
48 | + | |
34 | 49 | db.session.commit() |
35 | 50 | |
36 | 51 | ... | ... |