Skip to content

Commit

Permalink
🐛 Remove none values poi excluded, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim committed Jan 20, 2023
1 parent b9f575d commit 9541916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,16 @@ def setUpTestData(cls):
cls.network = trek_factory.TrekNetworkFactory()
if settings.TREKKING_TOPOLOGY_ENABLED:
cls.poi = trek_factory.POIFactory(paths=[(cls.treks[0].paths.first(), 0.5, 0.5)])
poi_excluded = trek_factory.POIFactory(paths=[(cls.treks[0].paths.first(), 0.5, 0.5)])
else:
cls.poi = trek_factory.POIFactory(geom='SRID=2154;POINT(0 5)')
poi_excluded = trek_factory.POIFactory(geom='SRID=2154;POINT(0 5)')
cls.treks[0].pois_excluded.add(poi_excluded)
cls.source = common_factory.RecordSourceFactory()
cls.reservation_system = common_factory.ReservationSystemFactory()
cls.treks[0].reservation_system = cls.reservation_system
cls.site = outdoor_factory.SiteFactory(managers=[cls.organism])
cls.site.pois_excluded.add(poi_excluded)
cls.label_accessibility = tourism_factory.LabelAccessibilityFactory()
cls.category = tourism_factory.TouristicContentCategoryFactory()
cls.content2.category = cls.category
Expand Down Expand Up @@ -386,6 +390,7 @@ def setUpTestData(cls):
type=cls.coursetype,
points_reference=MultiPoint(Point(12, 12))
)
cls.course.pois_excluded.add(poi_excluded)
cls.course.parent_sites.set([cls.site])
# create a reference point for distance filter (in 4326, Cahors city)
cls.reference_point = Point(x=1.4388656616210938,
Expand Down Expand Up @@ -1584,7 +1589,7 @@ def launch_tests_excluded_pois(self, obj, filter_name):
self.assertEqual(response.status_code, 200)
self.assertEqual(
len(json_response.get('results')),
trek_models.POI.objects.all().count()
trek_models.POI.objects.all().count() - 1 # 1 excluded POI
)
obj.pois_excluded.add(self.poi)
obj.save()
Expand All @@ -1595,7 +1600,7 @@ def launch_tests_excluded_pois(self, obj, filter_name):
self.assertEqual(response.status_code, 200)
self.assertEqual(
len(json_response.get('results')),
trek_models.POI.objects.all().count() - 1
trek_models.POI.objects.all().count() - 2 # 1 excluded POI
)

def test_poi_list_filter_trek(self):
Expand Down
4 changes: 2 additions & 2 deletions geotrek/api/v2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def filter_queryset(self, request, queryset, view):
def get_pois_to_filter_outdoor_objects(self, model, elems):
list_pois = POI.objects.none()
objects_outdoor = model.objects.filter(pk__in=elems.split(','))
pois_excluded = objects_outdoor.values_list('pois_excluded', flat=True)
collected_geom = objects_outdoor.aggregate(geom=Collect('geom'))['geom']
pois_excluded = [poi for poi in objects_outdoor.values_list('pois_excluded', flat=True) if poi is not None]
collected_geom = objects_outdoor.aggregate(collected_geom=Collect('geom'))['collected_geom']
if collected_geom:
list_pois = POI.objects.existing().filter(geom__dwithin=(collected_geom, settings.OUTDOOR_INTERSECTION_MARGIN))\
.exclude(pk__in=pois_excluded)
Expand Down

0 comments on commit 9541916

Please sign in to comment.