Skip to content
Snippets Groups Projects
Commit ff238b1d authored by HeJ's avatar HeJ
Browse files

api/map export: include 'hidden' villages' POI (+unittest)

parent 2ce90e33
Branches
No related tags found
No related merge requests found
from .bbb import * # noqa: F401, F403 from .bbb import * # noqa: F401, F403
from .engelsystem import * # noqa: F401, F403 from .engelsystem import * # noqa: F401, F403
from .map import * # noqa: F401, F403
from .metrics import * # noqa: F401, F403 from .metrics import * # noqa: F401, F403
from .schedule import * # noqa: F401, F403 from .schedule import * # noqa: F401, F403
from .workadventure import * # noqa: F401, F403 from .workadventure import * # noqa: F401, F403
......
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']))
...@@ -14,7 +14,8 @@ class AssembliesExportView(ConferenceSlugMixin, APIView, metaclass=abc.ABCMeta): ...@@ -14,7 +14,8 @@ class AssembliesExportView(ConferenceSlugMixin, APIView, metaclass=abc.ABCMeta):
_cts = {} # cache of CoordTransforms (if needed) _cts = {} # cache of CoordTransforms (if needed)
def get_queryset(self): 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 @staticmethod
def get_field_geojson(value, srid: int, ct_cache: dict = None): def get_field_geojson(value, srid: int, ct_cache: dict = None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment