Commit 8e2f61114bcace20232896f2ce7489b113a55050
1 parent
40126f91
Exists in
master
and in
4 other branches
Update tests with latest models
Showing
4 changed files
with
100 additions
and
40 deletions
Show diff stats
tests/backend_tests.py
1 | 1 | import os |
2 | 2 | import unittest |
3 | +from pprint import pprint | |
3 | 4 | |
4 | 5 | from pdc_config import TestConfig |
5 | 6 | from app import create_app, db_mgr |
... | ... | @@ -40,6 +41,22 @@ class DbMgrTestCase(BaseTestCase): |
40 | 41 | all_projects = db_mgr.projects() |
41 | 42 | self.assertEqual(5, len(all_projects[0])) |
42 | 43 | |
44 | + def test_projects_all_columns(self): | |
45 | + all_projects = db_mgr.projects() | |
46 | + for p in all_projects: | |
47 | + with self.subTest(p): | |
48 | + self.assertEqual(5, len(p), f"Failed on {p[1]}") | |
49 | + | |
50 | + def test_projects_labels(self): | |
51 | + self.assertEqual(0, 0) | |
52 | + all_projects = db_mgr.projects() | |
53 | + # test all projects but skip headers first row | |
54 | + for p in all_projects[1:]: | |
55 | + with self.subTest(p): | |
56 | + # the number of labels for each category and any project should be less than 2 | |
57 | + self.assertTrue(len(p[2]) <= 2, f"Failed on {p[1]}: " + ", ".join(p[2])) | |
58 | + self.assertTrue(len(p[3]) <= 2, f"Failed on {p[1]}: " + ", ".join(p[3])) | |
59 | + | |
43 | 60 | def test_agents(self): |
44 | 61 | all_agents = db_mgr.agents() |
45 | 62 | self.assertEqual(548, len(all_agents)) | ... | ... |
tests/common_db_feed.py
... | ... | @@ -14,41 +14,42 @@ def resources_to_instancedb(app): |
14 | 14 | copyfile(sqlite_file_name, db_path) |
15 | 15 | return db_path |
16 | 16 | |
17 | - | |
18 | -categorized_labels = {'pole': ['Spatial', 'Sol'], 'domaine': ['soleil-terre', 'atmosphere', 'r&t', 'géologie']} | |
19 | -projects_categories = {'ChemCam': {'pole': 'Spatial', 'domaine': 'géologie'}, | |
20 | - 'Pilot': {'pole': 'Spatial', 'domaine': 'atmosphere'}, | |
21 | - 'Ambre': {'pole': 'Spatial', 'domaine': 'soleil-terre'}} | |
22 | - | |
23 | - | |
24 | -def feed_projects(): | |
25 | - for c_name, labels in categorized_labels.items(): | |
26 | - n_c = Category(name=c_name) | |
27 | - db.session.add(n_c) | |
28 | - for l_name in labels: | |
29 | - n_l = Label(name=l_name, category=n_c) | |
30 | - db.session.add(n_l) | |
31 | - | |
32 | - db.session.commit() | |
33 | - | |
34 | - project_names = projects_categories.keys() | |
35 | - | |
36 | - for p_name in set(project_names): | |
37 | - n_p = Project(name=p_name) | |
38 | - db.session.add(n_p) | |
39 | - db.session.commit() | |
40 | - | |
41 | - for p, categories in projects_categories.items(): | |
42 | - n_p = db.session.query(Project).filter(Project.name == p).one() | |
43 | - for c_name, l_name in categories.items(): | |
44 | - n_c = db.session.query(Category).filter(Category.name == c_name).one() | |
45 | - n_l = db.session.query(Label).filter(Label.name == l_name).one() | |
46 | - n_pc = ProjectLabel(project=n_p, category=n_c, label=n_l) | |
47 | - db.session.add(n_pc) | |
48 | - | |
49 | - db.session.commit() | |
50 | - | |
51 | - | |
52 | -def show_categories(): | |
53 | - for c in db.session.query(Category).all(): | |
54 | - print(c.name + ": ", ",".join([l.name for l in c.categorized_labels])) | |
17 | +# TODO: rewrite for new category/label model | |
18 | +# | |
19 | +# categorized_labels = {'pole': ['Spatial', 'Sol'], 'domaine': ['soleil-terre', 'atmosphere', 'r&t', 'géologie']} | |
20 | +# projects_categories = {'ChemCam': {'pole': 'Spatial', 'domaine': 'géologie'}, | |
21 | +# 'Pilot': {'pole': 'Spatial', 'domaine': 'atmosphere'}, | |
22 | +# 'Ambre': {'pole': 'Spatial', 'domaine': 'soleil-terre'}} | |
23 | +# | |
24 | +# | |
25 | +# def feed_projects(): | |
26 | +# for c_name, labels in categorized_labels.items(): | |
27 | +# n_c = Category(name=c_name) | |
28 | +# db.session.add(n_c) | |
29 | +# for l_name in labels: | |
30 | +# n_l = Label(name=l_name, category=n_c) | |
31 | +# db.session.add(n_l) | |
32 | +# | |
33 | +# db.session.commit() | |
34 | +# | |
35 | +# project_names = projects_categories.keys() | |
36 | +# | |
37 | +# for p_name in set(project_names): | |
38 | +# n_p = Project(name=p_name) | |
39 | +# db.session.add(n_p) | |
40 | +# db.session.commit() | |
41 | +# | |
42 | +# for p, categories in projects_categories.items(): | |
43 | +# n_p = db.session.query(Project).filter(Project.name == p).one() | |
44 | +# for c_name, l_name in categories.items(): | |
45 | +# n_c = db.session.query(Category).filter(Category.name == c_name).one() | |
46 | +# n_l = db.session.query(Label).filter(Label.name == l_name).one() | |
47 | +# n_pc = ProjectLabel(project=n_p, category=n_c, label=n_l) | |
48 | +# db.session.add(n_pc) | |
49 | +# | |
50 | +# db.session.commit() | |
51 | +# | |
52 | +# | |
53 | +# def show_categories(): | |
54 | +# for c in db.session.query(Category).all(): | |
55 | +# print(c.name + ": ", ",".join([l.name for l in c.categorized_labels])) | ... | ... |
tests/db_tests.py
1 | 1 | import os |
2 | 2 | import unittest |
3 | +from pprint import pprint | |
3 | 4 | |
4 | 5 | from app import create_app, db, User |
5 | 6 | from app.models import Project |
6 | 7 | from pdc_config import TestConfig |
7 | -from tests.common_db_feed import feed_projects, resources_to_instancedb | |
8 | +from tests.common_db_feed import resources_to_instancedb | |
8 | 9 | |
9 | 10 | |
10 | 11 | class DbBaseTestCase(unittest.TestCase): |
... | ... | @@ -36,7 +37,8 @@ class DbBaseTestCase(unittest.TestCase): |
36 | 37 | # |
37 | 38 | if self.mode == 'memory': |
38 | 39 | db.create_all() |
39 | - feed_projects() | |
40 | + # TODO: to be rewriten for new category/label model | |
41 | + # feed_projects() | |
40 | 42 | |
41 | 43 | def tearDown(self): |
42 | 44 | if self.mode == 'memory': |
... | ... | @@ -48,6 +50,21 @@ class DbBaseTestCase(unittest.TestCase): |
48 | 50 | self.app_context.pop() |
49 | 51 | |
50 | 52 | |
53 | +class AnyModelTestCase(DbBaseTestCase): | |
54 | + def setUp(self): | |
55 | + DbBaseTestCase.setUp(self, 'btp') | |
56 | + | |
57 | + def tearDown(self): | |
58 | + DbBaseTestCase.tearDown(self) | |
59 | + | |
60 | + def test_projects_struct(self): | |
61 | + for project in Project.query.all(): | |
62 | + with self.subTest(project): | |
63 | + categories = list(project.to_struct()['labels'].keys()) | |
64 | + self.assertEqual(['Domaine', 'Pôle'], categories, | |
65 | + f"Failed on {project.name} categories: {categories}") | |
66 | + | |
67 | + | |
51 | 68 | class ChargeModelTestCase(DbBaseTestCase): |
52 | 69 | def setUp(self): |
53 | 70 | DbBaseTestCase.setUp(self, 'btp') | ... | ... |
tests/frontend_tests.py
... | ... | @@ -112,6 +112,20 @@ class AccessTestCase(BaseFrontTestCase): |
112 | 112 | self.driver.get(target_url) |
113 | 113 | self.assertEqual(self.driver.current_url, 'http://localhost:8943/projects') |
114 | 114 | |
115 | + def test_projects_trs(self): | |
116 | + target_url = self.get_server_url() + url_for('main.projects') | |
117 | + self.driver.get(target_url) | |
118 | + td_elmts = self.driver.find_elements_by_xpath("//table/tbody/tr") | |
119 | + self.assertEqual(101, len(td_elmts)) | |
120 | + | |
121 | + def test_projects_tds(self): | |
122 | + target_url = self.get_server_url() + url_for('main.projects') | |
123 | + self.driver.get(target_url) | |
124 | + for tr in self.driver.find_elements_by_xpath("//table/tbody/tr"): | |
125 | + with self.subTest(tr): | |
126 | + tds = tr.find_elements_by_tag_name('td') | |
127 | + self.assertEqual(4, len(tds), tds[0].text + " has wrong number of columns") | |
128 | + | |
115 | 129 | def test_project_page(self): |
116 | 130 | project_id = 8 |
117 | 131 | target_url = self.get_server_url() + url_for('main.project', project_id=project_id) |
... | ... | @@ -120,6 +134,17 @@ class AccessTestCase(BaseFrontTestCase): |
120 | 134 | td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td") |
121 | 135 | self.assertEqual(1085, len(td_elmts)) |
122 | 136 | |
137 | + def test_project_page_categories(self): | |
138 | + project_id = 84 | |
139 | + target_url = self.get_server_url() + url_for('main.project', project_id=project_id) | |
140 | + self.driver.get(target_url) | |
141 | + self.assertEqual(self.driver.current_url, f'http://localhost:8943/project/{project_id}') | |
142 | + # pole_dt_db = self.driver.find_element_by_xpath("//dt[text()='Pôle']/following-sibling::dd") | |
143 | + pole_dt_db = self.driver.find_element_by_xpath("//dt[contains(text(),'Pôle')]/following-sibling::dd") | |
144 | + self.assertEqual('Solaire', pole_dt_db.text) | |
145 | + domaine_dt_db = self.driver.find_element_by_xpath("//dt[contains(text(),'Domaine')]/following-sibling::dd") | |
146 | + self.assertTrue('LESIA' in domaine_dt_db.text) | |
147 | + | |
123 | 148 | |
124 | 149 | class FormsTestCase(BaseFrontTestCase): |
125 | 150 | ... | ... |