diff --git a/tests/backend_tests.py b/tests/backend_tests.py index de2a505..e4dacb6 100644 --- a/tests/backend_tests.py +++ b/tests/backend_tests.py @@ -1,5 +1,6 @@ import os import unittest +from pprint import pprint from pdc_config import TestConfig from app import create_app, db_mgr @@ -40,6 +41,22 @@ class DbMgrTestCase(BaseTestCase): all_projects = db_mgr.projects() self.assertEqual(5, len(all_projects[0])) + def test_projects_all_columns(self): + all_projects = db_mgr.projects() + for p in all_projects: + with self.subTest(p): + self.assertEqual(5, len(p), f"Failed on {p[1]}") + + def test_projects_labels(self): + self.assertEqual(0, 0) + all_projects = db_mgr.projects() + # test all projects but skip headers first row + for p in all_projects[1:]: + with self.subTest(p): + # the number of labels for each category and any project should be less than 2 + self.assertTrue(len(p[2]) <= 2, f"Failed on {p[1]}: " + ", ".join(p[2])) + self.assertTrue(len(p[3]) <= 2, f"Failed on {p[1]}: " + ", ".join(p[3])) + def test_agents(self): all_agents = db_mgr.agents() self.assertEqual(548, len(all_agents)) diff --git a/tests/common_db_feed.py b/tests/common_db_feed.py index 09c658d..f7ed6b5 100644 --- a/tests/common_db_feed.py +++ b/tests/common_db_feed.py @@ -14,41 +14,42 @@ def resources_to_instancedb(app): copyfile(sqlite_file_name, db_path) return db_path - -categorized_labels = {'pole': ['Spatial', 'Sol'], 'domaine': ['soleil-terre', 'atmosphere', 'r&t', 'géologie']} -projects_categories = {'ChemCam': {'pole': 'Spatial', 'domaine': 'géologie'}, - 'Pilot': {'pole': 'Spatial', 'domaine': 'atmosphere'}, - 'Ambre': {'pole': 'Spatial', 'domaine': 'soleil-terre'}} - - -def feed_projects(): - for c_name, labels in categorized_labels.items(): - n_c = Category(name=c_name) - db.session.add(n_c) - for l_name in labels: - n_l = Label(name=l_name, category=n_c) - db.session.add(n_l) - - db.session.commit() - - project_names = projects_categories.keys() - - for p_name in set(project_names): - n_p = Project(name=p_name) - db.session.add(n_p) - db.session.commit() - - for p, categories in projects_categories.items(): - n_p = db.session.query(Project).filter(Project.name == p).one() - for c_name, l_name in categories.items(): - n_c = db.session.query(Category).filter(Category.name == c_name).one() - n_l = db.session.query(Label).filter(Label.name == l_name).one() - n_pc = ProjectLabel(project=n_p, category=n_c, label=n_l) - db.session.add(n_pc) - - db.session.commit() - - -def show_categories(): - for c in db.session.query(Category).all(): - print(c.name + ": ", ",".join([l.name for l in c.categorized_labels])) +# TODO: rewrite for new category/label model +# +# categorized_labels = {'pole': ['Spatial', 'Sol'], 'domaine': ['soleil-terre', 'atmosphere', 'r&t', 'géologie']} +# projects_categories = {'ChemCam': {'pole': 'Spatial', 'domaine': 'géologie'}, +# 'Pilot': {'pole': 'Spatial', 'domaine': 'atmosphere'}, +# 'Ambre': {'pole': 'Spatial', 'domaine': 'soleil-terre'}} +# +# +# def feed_projects(): +# for c_name, labels in categorized_labels.items(): +# n_c = Category(name=c_name) +# db.session.add(n_c) +# for l_name in labels: +# n_l = Label(name=l_name, category=n_c) +# db.session.add(n_l) +# +# db.session.commit() +# +# project_names = projects_categories.keys() +# +# for p_name in set(project_names): +# n_p = Project(name=p_name) +# db.session.add(n_p) +# db.session.commit() +# +# for p, categories in projects_categories.items(): +# n_p = db.session.query(Project).filter(Project.name == p).one() +# for c_name, l_name in categories.items(): +# n_c = db.session.query(Category).filter(Category.name == c_name).one() +# n_l = db.session.query(Label).filter(Label.name == l_name).one() +# n_pc = ProjectLabel(project=n_p, category=n_c, label=n_l) +# db.session.add(n_pc) +# +# db.session.commit() +# +# +# def show_categories(): +# for c in db.session.query(Category).all(): +# print(c.name + ": ", ",".join([l.name for l in c.categorized_labels])) diff --git a/tests/db_tests.py b/tests/db_tests.py index a9ad1d1..30c0f59 100644 --- a/tests/db_tests.py +++ b/tests/db_tests.py @@ -1,10 +1,11 @@ import os import unittest +from pprint import pprint from app import create_app, db, User from app.models import Project from pdc_config import TestConfig -from tests.common_db_feed import feed_projects, resources_to_instancedb +from tests.common_db_feed import resources_to_instancedb class DbBaseTestCase(unittest.TestCase): @@ -36,7 +37,8 @@ class DbBaseTestCase(unittest.TestCase): # if self.mode == 'memory': db.create_all() - feed_projects() + # TODO: to be rewriten for new category/label model + # feed_projects() def tearDown(self): if self.mode == 'memory': @@ -48,6 +50,21 @@ class DbBaseTestCase(unittest.TestCase): self.app_context.pop() +class AnyModelTestCase(DbBaseTestCase): + def setUp(self): + DbBaseTestCase.setUp(self, 'btp') + + def tearDown(self): + DbBaseTestCase.tearDown(self) + + def test_projects_struct(self): + for project in Project.query.all(): + with self.subTest(project): + categories = list(project.to_struct()['labels'].keys()) + self.assertEqual(['Domaine', 'Pôle'], categories, + f"Failed on {project.name} categories: {categories}") + + class ChargeModelTestCase(DbBaseTestCase): def setUp(self): DbBaseTestCase.setUp(self, 'btp') diff --git a/tests/frontend_tests.py b/tests/frontend_tests.py index 66cd337..b8093b9 100644 --- a/tests/frontend_tests.py +++ b/tests/frontend_tests.py @@ -112,6 +112,20 @@ class AccessTestCase(BaseFrontTestCase): self.driver.get(target_url) self.assertEqual(self.driver.current_url, 'http://localhost:8943/projects') + def test_projects_trs(self): + target_url = self.get_server_url() + url_for('main.projects') + self.driver.get(target_url) + td_elmts = self.driver.find_elements_by_xpath("//table/tbody/tr") + self.assertEqual(101, len(td_elmts)) + + def test_projects_tds(self): + target_url = self.get_server_url() + url_for('main.projects') + self.driver.get(target_url) + for tr in self.driver.find_elements_by_xpath("//table/tbody/tr"): + with self.subTest(tr): + tds = tr.find_elements_by_tag_name('td') + self.assertEqual(4, len(tds), tds[0].text + " has wrong number of columns") + def test_project_page(self): project_id = 8 target_url = self.get_server_url() + url_for('main.project', project_id=project_id) @@ -120,6 +134,17 @@ class AccessTestCase(BaseFrontTestCase): td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td") self.assertEqual(1085, len(td_elmts)) + def test_project_page_categories(self): + project_id = 84 + target_url = self.get_server_url() + url_for('main.project', project_id=project_id) + self.driver.get(target_url) + self.assertEqual(self.driver.current_url, f'http://localhost:8943/project/{project_id}') + # pole_dt_db = self.driver.find_element_by_xpath("//dt[text()='Pôle']/following-sibling::dd") + pole_dt_db = self.driver.find_element_by_xpath("//dt[contains(text(),'Pôle')]/following-sibling::dd") + self.assertEqual('Solaire', pole_dt_db.text) + domaine_dt_db = self.driver.find_element_by_xpath("//dt[contains(text(),'Domaine')]/following-sibling::dd") + self.assertTrue('LESIA' in domaine_dt_db.text) + class FormsTestCase(BaseFrontTestCase): -- libgit2 0.21.2