diff --git a/loko/inspections/tests.py b/loko/inspections/tests.py index 940b629..90c2f5f 100644 --- a/loko/inspections/tests.py +++ b/loko/inspections/tests.py @@ -42,11 +42,28 @@ class InspectionModelAndViewsTestCase(TestCase): code='parking', defaults={'name_fr': 'Stationnement'} ) + UserThematics.objects.create( + user_config=config, + thematic=self.thematic, + can_view_assets=True, + can_edit_assets=True + ) + from assets.models import AssetCategory + self.parking_cat, _ = AssetCategory.objects.get_or_create( + code='parking_spot', + thematic=self.thematic, + defaults={ + 'name_fr': 'Emplacements de stationnement', + 'name_nl': 'Parkeerplaatsen' + } + ) self.spot = ParkingSpot.objects.create( - name_fr='Emplacement Vélo Test' + name_fr='Emplacement Vélo Test', + category=self.parking_cat ) self.spot_ct = ContentType.objects.get_for_model(ParkingSpot) + self.parking_cat.allowed_models.add(self.spot_ct) self.rwiz = NatureRWIZ.objects.create( name_fr='Zone GIEP Test' @@ -327,8 +344,38 @@ class InspectionModelAndViewsTestCase(TestCase): self.client.login(username='inspector_user', password='password123') url = reverse('inspections:delete_inspection_document_api', kwargs={'document_id': doc.id}) response = self.client.post(url) - self.assertEqual(response.status_code, 200) - self.assertTrue(response.json()['success']) - self.assertFalse(InspectionDocument.objects.filter(id=doc.id).exists()) + def test_inspections_list_thematic_filter(self): + self.client.login(username='inspector_user', password='password123') + + # Create inspections on both water and parking + insp_water = Inspection.objects.create( + asset_content_type=self.rwiz_ct, + asset_object_id=self.rwiz.id, + inspector=self.user, + result_status='compliant' + ) + insp_parking = Inspection.objects.create( + asset_content_type=self.spot_ct, + asset_object_id=self.spot.id, + inspector=self.user, + result_status='compliant' + ) + + url = reverse('inspections:inspections_list') + + # Filter water thematic + resp_water = self.client.get(url, {'thematic': 'water', 'tab': 'all'}) + self.assertEqual(resp_water.status_code, 200) + inspections_water = list(resp_water.context['inspections']) + self.assertIn(insp_water, inspections_water) + self.assertNotIn(insp_parking, inspections_water) + + # Filter parking thematic + resp_parking = self.client.get(url, {'thematic': 'parking', 'tab': 'all'}) + self.assertEqual(resp_parking.status_code, 200) + inspections_parking = list(resp_parking.context['inspections']) + self.assertIn(insp_parking, inspections_parking) + self.assertNotIn(insp_water, inspections_parking) + diff --git a/loko/inspections/views.py b/loko/inspections/views.py index a6793ea..38e00e2 100644 --- a/loko/inspections/views.py +++ b/loko/inspections/views.py @@ -60,7 +60,11 @@ def inspections_list(request): try: thematic = Thematic.objects.get(code=thematic_code) categories = AssetCategory.objects.filter(thematic=thematic) - cts = ContentType.objects.filter(assetcategory__in=categories).distinct() + cts = set(ContentType.objects.filter(asset_categories__in=categories).distinct()) + if thematic_code == 'water': + from assets.models.nature import NatureRWIZ, NatureRWIAsset + cts.add(ContentType.objects.get_for_model(NatureRWIZ)) + cts.add(ContentType.objects.get_for_model(NatureRWIAsset)) qs = qs.filter(asset_content_type__in=cts) except Thematic.DoesNotExist: pass