diff options
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 91 |
1 files changed, 60 insertions, 31 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 3540f9cfe..38d7c987d 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -2804,30 +2804,40 @@ class BaseImportTest(TestCase): new_file = os.path.join(root, "qfield", "model", "Test.qgs") with open(filename, 'r', encoding ='utf-8') as file: style = file.read() - modifications = style.replace('champ_','test_modif_') + modifications = style.replace('find_','test_modif_') with open(new_file, 'w', encoding ='utf-8') as file: file.write(modifications) with open(new_file, 'r', encoding='utf-8') as file: style = file.read() bool = 'test_modif_' in style self.assertEqual(bool, True) - bool = 'champ_' in style + bool = 'find_' in style self.assertEqual(bool, False) os.remove(new_file) - def export_qfield(self, mode, root, table_cols, col_names, datas): + def export_qfield(self, mode, model, root, table_cols, col_names, datas): """ :function: Core part of the test for the creation of a .gpkg, the modification of the .qgs and creation of a .zip test """ # 2) Creation of the .gpkg - finds, cr, list_ope, list_crea = views_item.gpkg_creation(root, table_cols, col_names, datas) + if str(model._meta) == 'archaeological_operations.archaeologicalsite': + sites, finds, cr, list_ope, list_crea = views_item.gpkg_creation_sites(root, table_cols, col_names, datas) + # Modification of the source to access the desired project depending on source of the data + source = 'specific' + else: + finds, cr, list_ope, list_crea = views_item.gpkg_creation(model, root, table_cols, col_names, datas) + # Modification of the source to access the desired project depending on source of the data + source = 'model' # 3) Preparations for the modification of the style in the .qgs file - qgs_path = os.path.join(root, 'model', 'Prospections.qgs') + qgs_path = os.path.join(root, source, 'Prospections.qgs') new_qgs = os.path.join(root, 'tests', str(mode), 'Prospections.qgs') if os.path.exists(new_qgs): os.remove(new_qgs) - text = views_item.modification_style(qgs_path, table_cols, col_names, list_ope, list_crea) + if source == 'specific': + text = views_item.modification_style_sites(qgs_path, table_cols, col_names, list_ope, list_crea) + else: + text = views_item.modification_style(qgs_path, table_cols, col_names, list_ope, list_crea) with open(new_qgs, 'w', encoding='utf-8') as file: file.write(text) @@ -2841,6 +2851,9 @@ class BaseImportTest(TestCase): # III. Moving the .gpkg in a copy of the Qfield test project with ZipFile(duplicate, 'a') as zip_file: # Adding the .gpkg to the .zip + if source == 'specific': + # Add only if created + zip_file.write(sites, os.path.basename(sites)) zip_file.write(finds, os.path.basename(finds)) zip_file.write(cr, os.path.basename(cr)) zip_file.write(new_qgs, os.path.basename(new_qgs)) @@ -2855,27 +2868,32 @@ class BaseImportTest(TestCase): self.assertEqual(dir_list, ['Prospections_qfield_export.zip', 'Prospections.qgs']) # Verification of the content of the .zip with ZipFile(os.path.join(folder, 'Prospections_qfield_export.zip'), 'r') as zip_file: - self.assertEqual(len(zip_file.namelist()), 4) - list_files = ['Prospections_attachments.zip', 'Finds.gpkg', 'Context_records.gpkg', 'Prospections.qgs'] - self.assertEqual(zip_file.namelist(), list_files) - zip_file.close() + try: + self.assertEqual(len(zip_file.namelist()), 4) + list_files = ['Prospections_attachments.zip', 'Finds.gpkg', 'Context_records.gpkg', 'Prospections.qgs'] + self.assertEqual(zip_file.namelist(), list_files) + except: + self.assertEqual(len(zip_file.namelist()), 5) + list_files = ['Prospections_attachments.zip', 'Sites.gpkg', 'Finds.gpkg', 'Context_records.gpkg', 'Prospections.qgs'] + self.assertEqual(zip_file.namelist(), list_files) + zip_file.close() # List of modified and new values to verify the absence/presence depending on the situation if mode == 1: - old = ['champ_id', 'champ_ue', 'champ_x', 'champ_y', 'champ_z', 'champ_wkt_modif', 'champ_nom', 'champ_ope', - 'champ_insee', 'champ_section', 'champ_parc', 'champ_type', 'champ_occup', 'champ_desc', 'champ_loca', - 'champ_media_cr', 'champ_periode', 'champ_acti', 'champ_geom'] - new = ['Identifiant', 'UE', 'X', 'Y', 'Z', 'WKT_point', 'Unité_Enregistrement', 'Opération', 'INSEE_Commune', - 'Section', 'Parcelle', 'Type', 'Interprétation', 'Description', 'Localisation', 'Media', 'Periode', 'Type_Activité', 'WKT'] + old = ['finds_id', 'finds_cr', 'finds_x', 'finds_y', 'finds_z', 'cr_name', 'cr_operation', 'cr_insee', + 'champ_type', 'cr_occupation', 'cr_description', 'cr_localisation', 'cr_media', 'cr_periode', 'cr_activity'] + new = ['Identifiant', 'UE', 'X', 'Y', 'Z', 'Unité_Enregistrement', 'Opération', 'INSEE_Commune', 'Type', + 'Interprétation', 'Description', 'Localisation', 'Media', 'Periode', 'Type_Activité'] if mode == 2: - old = ['champ_id', 'champ_ue', 'champ_wkt_simple', 'champ_nom', 'champ_ope', 'champ_insee', 'champ_section', - 'champ_parc', 'champ_type', 'champ_occup', 'champ_desc', 'champ_loca', 'champ_media_cr', - 'champ_periode', 'champ_acti', 'champ_geom'] - new = ['Identifiant', 'UE', 'WKT_point', 'Unité_Enregistrement', 'Opération', 'INSEE_Commune', 'Section', 'Parcelle', - 'Type', 'Interprétation', 'Description', 'Localisation', 'Media', 'Periode', 'Type_Activité', 'WKT'] + old = ['finds_id', 'finds_cr', 'finds_x', 'finds_y', 'finds_z', 'cr_name', 'cr_operation', 'cr_insee', + 'cr_section', 'cr_parcel', 'cr_type', 'cr_occupation', 'cr_description', 'cr_localisation', + 'cr_media', 'cr_periode'] + new = ['Identifiant', 'UE', 'X', 'Y', 'Z', 'Unité_Enregistrement', 'Opération', 'INSEE_Commune', + 'Description', 'Localisation', 'Media', 'Periode', 'Type_Activité'] if mode == 3: - old = ['champ_nom', 'champ_ope', 'champ_geom', 'champ_id', 'champ_ue', 'champ_date', 'champ_x', 'champ_y', - 'champ_z', 'champ_matériaux', 'champ_desc', 'champ_media_finds', 'champ_wkt_modif'] - new = ['Nom', 'Opération', 'WKT_polygon', 'Identifiant', 'UE', 'Date', 'X', 'Y', 'Z', 'Description', 'Media', 'WKT_point'] + old = ['cr_name', 'cr_operation', 'cr_wkt', 'finds_id', 'finds_cr', 'finds_date', 'finds_x', 'finds_y', + 'finds_z', 'champ_matériaux', 'cr_description', 'finds_media', 'finds_wkt_modif'] + new = ['Nom', 'Opération', 'WKT_polygon', 'Identifiant', 'UE', 'Date', 'X', 'Y', 'Z', 'Description', + 'Media', 'WKT_point'] with open(new_qgs, 'r', encoding='utf-8') as file: style = file.read() for elem in old: @@ -2906,6 +2924,12 @@ class BaseImportTest(TestCase): ope, __ = Operation.objects.get_or_create( code_patriarche='Ope_Test', operation_type=ope_type) + ArchaeologicalSite = apps.get_model("archaeological_operations", "ArchaeologicalSite") + site = ArchaeologicalSite.objects.create( + reference="1515", + name="Test_Site", + x=14.18, + y=39.45) ContextRecord = apps.get_model('archaeological_context_records', 'ContextRecord') cr, __ = ContextRecord.objects.get_or_create( operation=ope, @@ -2923,20 +2947,25 @@ class BaseImportTest(TestCase): for mode in range(1, 4): if mode == 1: - table_cols = ['label', 'context_record__label', 'geodata__x', 'geodata__y', 'geodata__z', 'geodata__point_3d'] + table_cols = [['reference'], ['name'], ['operations__code_patriarche'], ['geodata__x'], ['geodata__y'], + ['geodata__point_2d']] + col_names = ['Reference', 'Nom', 'Operation', 'X', 'Y', 'WKT_point'] + datas = [['', '1515', 'Test_site', 'Ope_Test', 14.18, 39.45, 'Point (14.1 39.45)']] + model = apps.get_model("archaeological_operations", "ArchaeologicalSite") + self.export_qfield(mode, model, root, table_cols, col_names, datas) + if mode == 2: + table_cols = ['label', 'context_record__label', 'geodata__x', 'geodata__y', 'geodata__z', + 'geodata__point_3d'] col_names = ['Identifiant', 'UE', 'X', 'Y', 'Z', 'WKT_point'] datas = [['', 'Test_Mobilier', 'Test_UE', 7.0, 1.4, 2.1, 'Point Z (0.7 1.4 2.1)']] - self.export_qfield(mode, root, table_cols, col_names, datas) - if mode == 2: - table_cols = ['label', 'context_record__label', 'geodata__point_3d'] - col_names = ['Identifiant', 'UE', 'WKT_point'] - datas = [['', 'Test_Mobilier', 'Test_UE', 'POINT Z (0.7 1.4 0)']] - self.export_qfield(mode, root, table_cols, col_names, datas) + model = apps.get_model('archaeological_finds', 'Find') + self.export_qfield(mode, model, root, table_cols, col_names, datas) if mode == 3: table_cols = [['label'], ['operation__code_patriarche'], ['geodata__multi_polygon']] col_names = ['Nom', 'Opération', 'WKT_polygon'] datas = [['', 'Test_UE', 'Ope_Test', 'MultiPolygon (((0.0 0.0, 1.0 1.0, 2.0 2.0)))']] - self.export_qfield(mode, root, table_cols, col_names, datas) + model = apps.get_model('archaeological_context_records', 'ContextRecord') + self.export_qfield(mode, model, root, table_cols, col_names, datas) |