diff --git a/src/api/tests/__init__.py b/src/api/tests/__init__.py index 9161f74f3278e686ea39cf18c5f12694bc9828ea..fdd831ce88e9040198f0513992310f0b68a5beab 100644 --- a/src/api/tests/__init__.py +++ b/src/api/tests/__init__.py @@ -1,5 +1,6 @@ from .bbb import * # noqa: F401, F403 from .engelsystem import * # noqa: F401, F403 +from .map import * # noqa: F401, F403 from .metrics import * # noqa: F401, F403 from .schedule import * # noqa: F401, F403 from .workadventure import * # noqa: F401, F403 diff --git a/src/api/tests/map.py b/src/api/tests/map.py new file mode 100644 index 0000000000000000000000000000000000000000..29667843bdeb420092648460851659006c93627c --- /dev/null +++ b/src/api/tests/map.py @@ -0,0 +1,79 @@ +from datetime import datetime +import json +from zoneinfo import ZoneInfo + +from django.contrib.gis.geos import Point +from django.test import TestCase +from django.urls import reverse + +from core.models import Assembly, ConferenceExportCache, Conference, PlatformUser + + +class MapTest(TestCase): + def setUp(self): + tz = ZoneInfo('CET') + self.conf = Conference( + slug='conf', name='TestConf', is_public=True, + start=datetime(2020, 12, 27, 1, 23, 45, tzinfo=tz), + end=datetime(2020, 12, 30, 23, 45, 00, tzinfo=tz), + ) + self.conf.save() + self.conf.tracks.create(slug='community', name='Community').save() + self.conf.tracks.create(slug='security', name='Security').save() + self.assembly = Assembly(name='TestAssembly', slug='asmbly', conference=self.conf) + self.assembly.save() + + self.user = PlatformUser(username='bernd', is_active=True) + self.user.save() + + def test_map_poi(self): + url = reverse('api:map-assemblies-poi', kwargs={'conference': self.conf.slug}) + resp = self.client.get(url) + self.assertEqual(200, resp.status_code) + self.assertEqual(resp['Content-Type'], 'application/geo+json') + + # decode JSON + content = json.loads(resp.content.decode('utf-8')) + + # check that there are no POIs yet + self.assertEqual('FeatureCollection', content.get('type')) + self.assertIsInstance(content.get('features'), list) + self.assertEqual(0, len(content['features'])) + + # set POI on assembly and accept it + self.assembly.location_point = Point(8.9, 52.9) + self.assembly.state_assembly = Assembly.State.ACCEPTED + self.assembly.save() + ConferenceExportCache.objects.all().delete() + + # check again, there should be no POI exported as the assembly is not placed yet + resp = self.client.get(url) + self.assertEqual(200, resp.status_code) + content = json.loads(resp.content.decode('utf-8')) + self.assertEqual(0, len(content['features'])) + + # change state to 'placed', now there should be a POI + self.assembly.state_assembly = Assembly.State.PLACED + self.assembly.save() + ConferenceExportCache.objects.all().delete() + resp = self.client.get(url) + self.assertEqual(200, resp.status_code) + content = json.loads(resp.content.decode('utf-8')) + self.assertEqual(1, len(content['features'])) + + # check the POI + feature = content['features'][0] + self.assertEqual('Feature', feature.get('type')) + self.assertEqual('Point', feature.get('geometry', {}).get('type')) + self.assertListEqual([8.9, 52.9], feature.get('geometry', {}).get('coordinates')) + self.assertEqual(self.assembly.name, feature.get('properties', {}).get('name')) + self.assertEqual(self.assembly.is_cluster, feature.get('properties', {}).get('cluster')) + + # change assembly to 'hidden', POI should still be there + self.assembly.state_assembly = Assembly.State.HIDDEN + self.assembly.save() + ConferenceExportCache.objects.all().delete() + resp = self.client.get(url) + self.assertEqual(200, resp.status_code) + content = json.loads(resp.content.decode('utf-8')) + self.assertEqual(1, len(content['features'])) diff --git a/src/api/views/maps.py b/src/api/views/maps.py index 0ec3153cffce8a79039ba392097e87ef71edb410..078157d6717a50683f424f47f1dda667474c61e6 100644 --- a/src/api/views/maps.py +++ b/src/api/views/maps.py @@ -14,7 +14,8 @@ class AssembliesExportView(ConferenceSlugMixin, APIView, metaclass=abc.ABCMeta): _cts = {} # cache of CoordTransforms (if needed) def get_queryset(self): - return Assembly.objects.filter(conference=self.conference, state_assembly__in=Assembly.PLACED_STATES) + exportable_states = Assembly.PLACED_STATES + [Assembly.State.HIDDEN] + return Assembly.objects.filter(conference=self.conference, state_assembly__in=exportable_states) @staticmethod def get_field_geojson(value, srid: int, ct_cache: dict = None):