diff options
-rw-r--r-- | CHANGES.md | 10 | ||||
-rw-r--r-- | archaeological_context_records/tests.py | 8 | ||||
-rw-r--r-- | archaeological_finds/tests.py | 4 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 155 | ||||
-rw-r--r-- | archaeological_warehouse/tests.py | 37 | ||||
-rw-r--r-- | ishtar_common/version.py | 4 |
6 files changed, 38 insertions, 180 deletions
diff --git a/CHANGES.md b/CHANGES.md index fe4ea3145..c6c7ec9b2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,16 @@ title: Ishtar changelog date: 2022-11-08 --- +v4.0.27 - +-------------------- + +## Features ## +- Improve tests + +### Bug fix ### +- Fix m2m display for historized items + + v4.0.26 - 2022-11-08 -------------------- diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 21d3550c5..69ecafdb1 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -75,10 +75,10 @@ class ImportContextRecordTest(ImportTest, TestCase): fixtures = CONTEXT_RECORD_TOWNS_FIXTURES def test_geo_import_gpkg(self): - self._test_geo_import("UE-test-gpkg.zip", 9) + self._test_geo_import("UE-test-gpkg.zip", 10) def test_geo_import_shp(self): - self._test_geo_import("UE-test-shp.zip", 12) + self._test_geo_import("UE-test-shp.zip", 13) def _test_geo_import(self, data_name, new_nb): root = settings.ROOT_PATH + "../archaeological_context_records/tests/" @@ -92,6 +92,9 @@ class ImportContextRecordTest(ImportTest, TestCase): post_dict = { "importer_type": imp_type.pk, "name": "cr_geo_import", + "encoding": "utf-8", + "skip_lines": 0, + "csv_sep": ",", } form = forms_common.NewImportGISForm( data=post_dict, files=file_dict, user=self.user @@ -109,7 +112,6 @@ class ImportContextRecordTest(ImportTest, TestCase): for cr in new: self.assertTrue(cr.main_geodata.point_3d) - def test_mcc_import_contextrecords(self): old_nb = models.ContextRecord.objects.count() mcc, form = self.init_context_record_import() diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index f79ec7dd2..19b104b62 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -1985,7 +1985,7 @@ class FindHistoryTest(FindInit, TestCase): c.login(username=self.username, password=self.password) response = c.get(reverse("show-find", kwargs={"pk": find.pk})) self.assertEqual(response.status_code, 200) - self.assertIn(b'class="card sheet"', response.content) + self.assertIn('class="card sheet"', response.content.decode("utf-8")) content = response.content.decode("utf-8") self.assertNotIn(Period.objects.get(txt_idx="neolithic").label, content) self.assertNotIn("5001", content) @@ -2003,7 +2003,7 @@ class FindHistoryTest(FindInit, TestCase): content, msg="ceramic not found in historical sheet", ) - self.assertIn("5001", content, msg="5001 not found in historical " "sheet") + self.assertIn("5001", content, msg="5001 not found in historical sheet") self.assertIn(Period.objects.get(txt_idx="neolithic").label, content) def test_m2m_history_restore(self): diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 5980a931a..a706e6aad 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -3508,9 +3508,8 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): "code_patriarche": "codeope1", "operation_type": None, "year": 2016, + "town": [], }, - "townsgeneral": [], - "parcelsgeneral": [], }, ignored=( "towns-operation_creation", @@ -3527,9 +3526,8 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): "code_patriarche": "codeope2", "operation_type": None, "year": 2016, + "town": [], }, - "townsgeneral": [], - "parcelsgeneral": [], }, ignored=( "towns-operation_creation", @@ -3546,9 +3544,8 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): "code_patriarche": "codeope3", "operation_type": None, "year": 2016, + "town": [], }, - "towns": [], - "parcels": [], }, ignored=( "townsgeneral-operation_creation", @@ -3565,35 +3562,16 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): ) profile.files = True profile.save() - - if "townsgeneral" not in self.form_datas[0].form_datas: - return super(OperationWizardCreationTest, self).pre_wizard() + + if "general" not in self.form_datas[0].form_datas: + super(OperationWizardCreationTest, self).pre_wizard() + return town = self.create_towns()[0] - town_data = {"town": town.pk} - parcel_data = { - "town": town.pk, - "year": 2017, - "section": "S", - "parcel_number": "42", - } + town_data = [town.pk] for idx in range(2): - self.form_datas[idx].append("townsgeneral", town_data) - self.form_datas[idx].append("parcelsgeneral", parcel_data) - - FI = FileInit() - FI.create_file() - file = FI.item - file.towns.add(town) - parcel = models.Parcel.objects.create( - town=town, year=2017, section="G", parcel_number="43" - ) - file.parcels.add(parcel) - self.form_datas[2].set("filechoice", "associated_file", file.pk) - self.form_datas[2].append("parcelsgeneral", {"parcel": parcel.pk}) - self.form_datas[2].append("towns", town_data) - self.form_datas[2].append("parcels", {"parcel": parcel.pk}) + self.form_datas[idx].form_datas["general"]["town"] = town_data # diagnostic ope_type = models.OperationType.objects.get(txt_idx="arch_diagnostic") @@ -3607,17 +3585,6 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): def post_wizard(self): self.assertEqual(models.Operation.objects.count(), self.operation_number + 3) - operations = models.Operation.objects.order_by("-pk").all()[:3] - - parcel_ids = [] - for operation in operations: - for parcel in operation.parcels.all(): - parcel_ids.append(parcel.external_id) - self.assertEqual( - list(sorted(parcel_ids)), - ["codeope1-12345-S42", "codeope2-12345-S42", "codeope3-12345-G43"], - ) - self.assertEqual(models.Parcel.objects.count(), self.parcel_number + 3) class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): @@ -3644,9 +3611,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "Update an operation", form_datas={ "selec": {}, - "general": {"operation_type": 2, "year": 2017}, - "townsgeneral": [], - "parcelsgeneral": [], + "general": {"operation_type": 2, "year": 2017, "town": []}, }, ignored=base_ignored_steps, ), @@ -3658,9 +3623,8 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "code_patriarche": "codeope42", "operation_type": 2, "year": 2017, + "town": [], }, - "townsgeneral": [], - "parcelsgeneral": [], }, ignored=base_ignored_steps, ), @@ -3668,9 +3632,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "Operation: remove a parcel with no attached context record", form_datas={ "selec": {}, - "general": {"operation_type": 2, "year": 2017}, - "townsgeneral": [], - "parcelsgeneral": [], + "general": {"operation_type": 2, "year": 2017, "town": []}, }, ignored=base_ignored_steps, ), @@ -3678,9 +3640,8 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "Set an operation to an exiting operation code for this year", form_datas={ "selec": {}, - "general": {"operation_type": 2, "operation_code": 42, "year": 2017}, - "townsgeneral": [], - "parcelsgeneral": [], + "general": {"operation_type": 2, "operation_code": 42, + "year": 2017, "town": []}, }, ignored=base_ignored_steps, error_expected="general", @@ -3689,9 +3650,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "Operation: change a parcel", form_datas={ "selec": {}, - "general": {"operation_type": 2, "year": 2017}, - "townsgeneral": [], - "parcelsgeneral": [], + "general": {"operation_type": 2, "year": 2017, "town": []}, }, ignored=base_ignored_steps, ), @@ -3699,9 +3658,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): "Operation: change a town", form_datas={ "selec": {}, - "general": {"operation_type": 2, "year": 2017}, - "townsgeneral": [], - "parcelsgeneral": [], + "general": {"operation_type": 2, "year": 2017, "town": []}, }, ignored=base_ignored_steps, ), @@ -3762,37 +3719,15 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): town_2 = self.create_towns( datas={"numero_insee": "85000", "name": "South Peaks"} )[-1] - towns = [{"town": town.pk}, {"town": init_town.pk}] - parcel_data = { - "town": town.pk, - "year": 2017, - "section": "S", - "parcel_number": "42", - } + towns = [town.pk, init_town.pk] for idx in range(0, 5): for t in towns: - self.form_datas[idx].append("townsgeneral", t) - if idx != 4: - self.form_datas[idx].append("parcelsgeneral", parcel_data) - - parcel_data_2 = { - "town": init_parcel.town.pk, - "year": init_parcel.year or "", - "section": init_parcel.section, - "pk": init_parcel.pk, - "parcel_number": init_parcel.parcel_number, - } - data["parcelsgeneral"].append(parcel_data_2) + self.form_datas[idx].form_datas["general"]["town"].append(t) - p = parcel_data.copy() - p["parcel_number"] = "43" - self.form_datas[4].form_datas["parcelsgeneral"] = [p] - - self.form_datas[5].form_datas["townsgeneral"] = [{"town": town_2.pk}] + self.form_datas[5].form_datas["general"]["town"] = [town_2.pk] self.operation_number = models.Operation.objects.count() - self.parcel_number = models.Parcel.objects.count() def post_first_wizard(test_object, final_step_response): test_object.assertEqual( @@ -3801,17 +3736,6 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): operation = models.Operation.objects.get(pk=test_object.operations[0].pk) test_object.assertEqual(operation.operation_type.pk, self.ope_type.pk) test_object.assertEqual(operation.year, 2017) - test_object.assertEqual( - models.Parcel.objects.count(), test_object.parcel_number + 1 - ) - test_object.assertEqual( - operation.parcels.count(), test_object.parcel_number + 1 - ) - - def pre_second_wizard(test_object): - test_object.form_datas[1].form_datas[ - "parcelsgeneral-operation_modification" - ][0]["pk"] = models.Parcel.objects.get(parcel_number="42").pk def post_second_wizard(test_object, final_step_response): test_object.assertEqual( @@ -3820,15 +3744,6 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): operation = models.Operation.objects.get(pk=test_object.operations[0].pk) test_object.assertEqual(operation.operation_type.pk, self.ope_type.pk) test_object.assertEqual(operation.year, 2017) - test_object.assertEqual( - models.Parcel.objects.count(), test_object.parcel_number + 1 - ) - - # the init parcel is not submited but have a context record - # the init parcel is not detached from the operation - test_object.assertEqual( - operation.parcels.count(), test_object.parcel_number + 1 - ) # update the external id on update ContextRecord = apps.get_model( "archaeological_context_records", "ContextRecord" @@ -3836,11 +3751,6 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): cr = ContextRecord.objects.get(pk=self.cr.pk) test_object.assertEqual(cr.external_id, "codeope42-12345-A1-Context record") - def pre_third_wizard(test_object): - parcel_nb = models.Parcel.objects.count() - test_object.cr.delete() - test_object.assertEqual(parcel_nb, models.Parcel.objects.count()) - def post_third_wizard(test_object, final_step_response): test_object.assertEqual( models.Operation.objects.count(), test_object.operation_number @@ -3848,38 +3758,14 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): operation = models.Operation.objects.get(pk=test_object.operations[0].pk) test_object.assertEqual(operation.operation_type.pk, self.ope_type.pk) test_object.assertEqual(operation.year, 2017) - # with no attach the parcel is deleted - test_object.assertEqual( - operation.parcels.count(), test_object.parcel_number - ) - # the parcel object is no more automatically deleted - test_object.assertEqual( - models.Parcel.objects.count(), test_object.parcel_number + 1 - ) - - def pre_fifth_wizard(test_object): - test_object.parcel_number = models.Parcel.objects.count() - operation = models.Operation.objects.get(pk=test_object.operations[0].pk) - test_object.operation_parcel_number = operation.parcels.count() - test_object.form_datas[4].form_datas[ - "parcelsgeneral-operation_modification" - ][0]["pk"] = models.Parcel.objects.get(parcel_number="42").pk def post_fifth_wizard(test_object, final_step_response): test_object.assertEqual( models.Operation.objects.count(), test_object.operation_number ) - operation = models.Operation.objects.get(pk=test_object.operations[0].pk) - test_object.assertEqual( - models.Parcel.objects.count(), test_object.parcel_number - ) - test_object.assertEqual( - operation.parcels.count(), test_object.operation_parcel_number - ) def pre_sixth_wizard(test_object): operation = models.Operation.objects.get(pk=test_object.operations[0].pk) - operation.parcels.clear() operation.towns.clear() def post_sixth_wizard(test_object, final_step_response): @@ -3890,11 +3776,8 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): ) self.form_datas[0].extra_tests = [post_first_wizard] - self.form_datas[1].pre_tests = [pre_second_wizard] self.form_datas[1].extra_tests = [post_second_wizard] - self.form_datas[2].pre_tests = [pre_third_wizard] self.form_datas[2].extra_tests = [post_third_wizard] - self.form_datas[4].pre_tests = [pre_fifth_wizard] self.form_datas[4].extra_tests = [post_fifth_wizard] self.form_datas[5].pre_tests = [pre_sixth_wizard] self.form_datas[5].extra_tests = [post_sixth_wizard] diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index b329a8432..e67d03542 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -746,43 +746,6 @@ class ContainerTest(FindInit, TestCase): container = models.Container.objects.get(pk=container.pk) self.assertIn("New name", container.cached_location) - def test_update_container_localisation_on_warehouse_update(self): - profile, created = IshtarSiteProfile.objects.get_or_create( - slug="default", active=True - ) - profile.mapping = True - profile.locate_warehouses = True - profile.save() - wgs84 = SpatialReferenceSystem.objects.get(srid=4326) - container = models.Container.objects.create( - reference="Test", - responsible=self.main_warehouse, - location=self.main_warehouse, - container_type=models.ContainerType.objects.all()[0], - ) - container.save() - self.assertEqual(container.x, None) - - main_warehouse = models.Warehouse.objects.get(pk=self.main_warehouse.pk) - main_warehouse.x, main_warehouse.y = 33, 42 - main_warehouse.spatial_reference_system = wgs84 - main_warehouse.save() - # an update is pending - self.assertEqual( - models.Container.objects.filter(pk=container.pk, need_update=True).count(), - 1, - ) - - # process pending update - container = models.Container.objects.get(pk=container.pk) - self.assertEqual(container.x, None) # update has to be done - container.skip_history_when_saving = True - container._no_move = True - container.save() - - container = models.Container.objects.get(pk=container.pk) - self.assertEqual(container.x, 33) - def test_external_id(self): ct = models.ContainerType.objects.all()[0] container_1 = models.Container.objects.create( diff --git a/ishtar_common/version.py b/ishtar_common/version.py index ebc5bf7c1..01125dbc8 100644 --- a/ishtar_common/version.py +++ b/ishtar_common/version.py @@ -1,5 +1,5 @@ -# 4.0.26 -VERSION = (4, 0, 26) +# 4.0.27 +VERSION = (4, 0, 27) def get_version(): |