From 5868ef73116bb7f7f629cc58e29501296bcfc296 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Wed, 22 Nov 2023 10:04:07 +0100 Subject: [PATCH] fix tests --- _BACKUP_57025.gitignore | 27 ++++ _BASE_57025.gitignore | 22 +++ _LOCAL_57025.gitignore | 23 +++ _REMOTE_57025.gitignore | 23 +++ test/test_reordering.py | 29 ++-- test/test_view_sign_symbol.py | 295 ---------------------------------- test/utils.py | 14 +- 7 files changed, 118 insertions(+), 315 deletions(-) create mode 100644 _BACKUP_57025.gitignore create mode 100644 _BASE_57025.gitignore create mode 100644 _LOCAL_57025.gitignore create mode 100644 _REMOTE_57025.gitignore delete mode 100644 test/test_view_sign_symbol.py diff --git a/_BACKUP_57025.gitignore b/_BACKUP_57025.gitignore new file mode 100644 index 00000000..9749378d --- /dev/null +++ b/_BACKUP_57025.gitignore @@ -0,0 +1,27 @@ +.idea +.DS_Store +*.orig +.schemalintrc.js +__pycache__ +*.qgs~ +local_test.sh +*.backup +.ghtoken +official-signs.json +postgresql.jar +schemaspy*.jar +schemaspy/ +website/local.html +project/this-is-the-way.jpg +project/signalo.ts +<<<<<<< HEAD +projet/signalo_attachments.zip +======= +project/signalo_attachments.zip +>>>>>>> c3363eb ([FEATURE] add anchor point (left/center/right) + sign hanging mode (recto/verso)) +website/tx +Pipfile +Pipfile.lock +.env +Pipfile +project/images/_* diff --git a/_BASE_57025.gitignore b/_BASE_57025.gitignore new file mode 100644 index 00000000..15a790f1 --- /dev/null +++ b/_BASE_57025.gitignore @@ -0,0 +1,22 @@ +.idea +.DS_Store +*.orig +.schemalintrc.js +__pycache__ +*.qgs~ +local_test.sh +*.backup +.ghtoken +official-signs.json +postgresql.jar +schemaspy*.jar +schemaspy/ +website/local.html +project/this-is-the-way.jpg +project/signalo.ts +website/tx +Pipfile +Pipfile.lock +.env +Pipfile +project/images/_* diff --git a/_LOCAL_57025.gitignore b/_LOCAL_57025.gitignore new file mode 100644 index 00000000..9d6e0129 --- /dev/null +++ b/_LOCAL_57025.gitignore @@ -0,0 +1,23 @@ +.idea +.DS_Store +*.orig +.schemalintrc.js +__pycache__ +*.qgs~ +local_test.sh +*.backup +.ghtoken +official-signs.json +postgresql.jar +schemaspy*.jar +schemaspy/ +website/local.html +project/this-is-the-way.jpg +project/signalo.ts +projet/signalo_attachments.zip +website/tx +Pipfile +Pipfile.lock +.env +Pipfile +project/images/_* diff --git a/_REMOTE_57025.gitignore b/_REMOTE_57025.gitignore new file mode 100644 index 00000000..98eeb5be --- /dev/null +++ b/_REMOTE_57025.gitignore @@ -0,0 +1,23 @@ +.idea +.DS_Store +*.orig +.schemalintrc.js +__pycache__ +*.qgs~ +local_test.sh +*.backup +.ghtoken +official-signs.json +postgresql.jar +schemaspy*.jar +schemaspy/ +website/local.html +project/this-is-the-way.jpg +project/signalo.ts +project/signalo_attachments.zip +website/tx +Pipfile +Pipfile.lock +.env +Pipfile +project/images/_* diff --git a/test/test_reordering.py b/test/test_reordering.py index 9f4d9d19..03e1cdb3 100644 --- a/test/test_reordering.py +++ b/test/test_reordering.py @@ -38,32 +38,35 @@ def test_reorder_signs_in_rank(self): ) row = { - "frame_fk_azimut": azimut_id, - "frame_rank": 1, - "frame_fk_frame_type": 1, - "frame_fk_frame_fixing_type": 1, - "frame_fk_status": 1, - "sign_rank": 1, + "fk_azimut": azimut_id, + "fk_frame_type": 1, + "fk_frame_fixing_type": 1, + "fk_status": 1, + } + + frame_id = self.insert("frame", row) + + row = { + "fk_frame": frame_id, "fk_sign_type": 1, "fk_official_sign": "1.01", "fk_durability": 1, "fk_status": 1, "comment": "1", } - sign_ids = [self.insert("vw_sign_symbol", row, schema="signalo_app")] - frame_id = self.select("sign", sign_ids[0])["fk_frame"] - row["frame_id"] = frame_id + row["fk_frame"] = frame_id + sign_ids = [] - for i in range(2, 6): - row["sign_rank"] = i + for i in range(1, 6): + row["rank"] = i row["comment"] = str(i) - sign_ids.append(self.insert("vw_sign_symbol", row, schema="signalo_app")) + sign_ids.append(self.insert("sign", row)) self.assertEqual(self.count("sign"), sign_count + 5) self.assertEqual(self.count("frame"), frame_count + 1) - self.delete("vw_sign_symbol", sign_ids[1], schema="signalo_app") + self.delete("sign", sign_ids[1]) self.check({"rank": 1, "comment": "1"}, "sign", sign_ids[0]) self.check({"rank": 2, "comment": "3"}, "sign", sign_ids[2]) diff --git a/test/test_view_sign_symbol.py b/test/test_view_sign_symbol.py deleted file mode 100644 index 87a4d95a..00000000 --- a/test/test_view_sign_symbol.py +++ /dev/null @@ -1,295 +0,0 @@ -import os -import unittest - -import psycopg2 -import psycopg2.extras - -from .utils import DbTestBase - - -class TestViews(unittest.TestCase, DbTestBase): - @classmethod - def tearDownClass(cls) -> None: - cls.conn.close() - - @classmethod - def tearDown(cls) -> None: - cls.conn.rollback() - - @classmethod - def setUpClass(cls): - pg_service = os.environ.get("PGSERVICE") or "signalo" - cls.conn = psycopg2.connect(f"service={pg_service}") - - def test_view_values(self): - self.execute(open("test/test_data.sql").read()) - - data = [ - { - "id": "00000000-0000-0000-eeee-000001010101", - "row": { - "azimut": 15, - "_final_rank": 1, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": "00000000-0000-0000-eeee-000001010102", - "_previous_frame": None, - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000001010102", - "row": { - "azimut": 15, - "_final_rank": 2, - "_previous_sign_in_frame": "00000000-0000-0000-eeee-000001010101", - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": "00000000-0000-0000-ffff-000000010102", - }, - }, - { - "id": "00000000-0000-0000-eeee-000001010201", - "row": { - "azimut": 15, - "_final_rank": 3, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000010101", - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000001020101", - "row": { - "azimut": 175, - "_final_rank": 1, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": "00000000-0000-0000-ffff-000000010202", - }, - }, - { - "id": "00000000-0000-0000-eeee-000001020201", - "row": { - "azimut": 175, - "_final_rank": 2, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000010201", - "_next_frame": "00000000-0000-0000-ffff-000000010203", - }, - }, - { - "id": "00000000-0000-0000-eeee-000001020301", - "row": { - "azimut": 175, - "_final_rank": 3, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000010202", - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000001030101", - "row": { - "azimut": 235, - "_final_rank": 1, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": "00000000-0000-0000-ffff-000000010302", - }, - }, - { - "id": "00000000-0000-0000-eeee-000001030201", - "row": { - "azimut": 235, - "_final_rank": 2, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000010301", - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000002010101", - "row": { - "azimut": 47, - "_final_rank": 1, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020101", - "row": { - "azimut": 165, - "_final_rank": 1, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": "00000000-0000-0000-ffff-000000020202", - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020201", - "row": { - "azimut": 165, - "_final_rank": 2, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": "00000000-0000-0000-eeee-000002020202", - "_previous_frame": "00000000-0000-0000-ffff-000000020201", - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020202", - "row": { - "azimut": 165, - "_final_rank": 3, - "_previous_sign_in_frame": "00000000-0000-0000-eeee-000002020201", - "_next_sign_in_frame": "00000000-0000-0000-eeee-000002020203", - "_previous_frame": None, - "_next_frame": None, - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020203", - "row": { - "azimut": 165, - "_final_rank": 4, - "_previous_sign_in_frame": "00000000-0000-0000-eeee-000002020202", - "_next_sign_in_frame": None, - "_previous_frame": None, - "_next_frame": "00000000-0000-0000-ffff-000000020203", - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020301", - "row": { - "azimut": 165, - "_final_rank": 5, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000020202", - "_next_frame": "00000000-0000-0000-ffff-000000020204", - }, - }, - { - "id": "00000000-0000-0000-eeee-000002020401", - "row": { - "azimut": 165, - "_final_rank": 6, - "_previous_sign_in_frame": None, - "_next_sign_in_frame": None, - "_previous_frame": "00000000-0000-0000-ffff-000000020203", - "_next_frame": None, - }, - }, - ] - for row in data: - self.check(row["row"], "vw_sign_symbol", row["id"], schema="signalo_app") - - def test_insert(self): - support_id = self.insert_check( - "support", - { - "geometry": self.execute_select( - "ST_SetSRID(ST_MakePoint(2600000, 1200000), 2056)" - ) - }, - ) - azimut_id = self.insert_check( - "azimut", {"azimut": 100, "fk_support": support_id} - ) - - row = { - "frame_fk_azimut": azimut_id, - "frame_rank": 1, - "frame_fk_frame_type": 1, - "frame_fk_frame_fixing_type": 1, - "frame_fk_status": 1, - "sign_rank": 1, - "fk_sign_type": 1, - "fk_official_sign": "1.01", - "fk_durability": 1, - "fk_status": 1, - } - - sign_id = self.insert("vw_sign_symbol", row, schema="signalo_app") - frame_id = self.select("sign", sign_id)["fk_frame"] - - row = {"fk_azimut": azimut_id} - self.update_check("frame", row, frame_id) - - def test_update(self): - self.execute(open("test/test_data.sql").read()) - - row = { - "fk_sign_type": 2, - "frame_fk_frame_type": 2, - } - - self.update_check( - "vw_sign_symbol", - row, - "00000000-0000-0000-eeee-000002010101", - schema="signalo_app", - ) - - def test_delete(self): - frame_count = self.count("frame") - sign_count = self.count("sign") - - support_id = self.insert_check( - "support", - { - "geometry": self.execute_select( - "ST_SetSRID(ST_MakePoint(2600000, 1200000), 2056)" - ) - }, - ) - azimut_id = self.insert_check( - "azimut", {"azimut": 100, "fk_support": support_id} - ) - - row = { - "frame_fk_azimut": azimut_id, - "frame_rank": 1, - "frame_fk_frame_type": 1, - "frame_fk_frame_fixing_type": 1, - "frame_fk_status": 1, - "sign_rank": 1, - "fk_sign_type": 1, - "fk_official_sign": "1.01", - "fk_durability": 1, - "fk_status": 1, - } - sign_id_1 = self.insert("vw_sign_symbol", row, schema="signalo_app") - frame_id = self.select("sign", sign_id_1)["fk_frame"] - - row["sign_rank"] = 2 - row["frame_id"] = frame_id - - sign_id_2 = self.insert("vw_sign_symbol", row, schema="signalo_app") - - self.assertEqual(self.count("sign"), sign_count + 2) - self.assertEqual(self.count("frame"), frame_count + 1) - - self.delete("vw_sign_symbol", sign_id_2, schema="signalo_app") - - self.assertEqual(self.count("sign"), sign_count + 1) - self.assertEqual(self.count("frame"), frame_count + 1) - - self.delete("vw_sign_symbol", sign_id_1, schema="signalo_app") - - self.assertEqual(self.count("sign"), sign_count) - self.assertEqual(self.count("frame"), frame_count) - - -if __name__ == "__main__": - unittest.main() diff --git a/test/utils.py b/test/utils.py index 884d39d6..c7ce0b71 100644 --- a/test/utils.py +++ b/test/utils.py @@ -54,27 +54,27 @@ def update(self, table, row, id, schema="signalo_db"): row, ) - def delete(self, table, id, schema="signalo_db"): + def delete(self, table, fid, schema="signalo_db"): cur = self.conn.cursor() cur.execute( "DELETE FROM {schema}.{table} WHERE id=%s".format( table=table, schema=schema ), - [id], + [fid], ) - def insert_check(self, table, row, expected_row=None, schema="signalo_db"): - id = self.insert(table, row, schema) - result = self.select(table, id, schema) + def insert_check(self, table, row, expected_row=None, schema="signalo_db") -> str: + fid = self.insert(table, row, schema) + result = self.select(table, fid, schema) - assert result, id + assert result, fid if expected_row: row = expected_row self.check_result(row, result, table, "insert", schema) - return id + return fid def update_check(self, table, row, id, schema="signalo_db"): self.update(table, row, id, schema)