Skip to content

Commit

Permalink
[tests] Added more ObjectInline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Nov 15, 2017
1 parent 28e2d0c commit 5a50432
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django_loci/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _create_object(self, **kwargs):
def _create_location(self, **kwargs):
options = dict(name='test-location',
address='Via del Corso, Roma',
geometry='SRID=4326;POINT (12.019043 42.277309)')
geometry='SRID=4326;POINT (12.512124 41.898903)')
options.update(kwargs)
location = self.location_model(**options)
location.full_clean()
Expand Down
3 changes: 2 additions & 1 deletion django_loci/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from . import TestAdminMixin, TestLociMixin
from ..models import FloorPlan, Location, ObjectLocation
from .testdeviceapp.models import Device


class TestAdmin(TestAdminMixin, TestLociMixin, TestCase):
object_model = get_user_model()
object_model = Device
location_model = Location
floorplan_model = FloorPlan
object_location_model = ObjectLocation
Expand Down
103 changes: 102 additions & 1 deletion django_loci/tests/test_admin_inline.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
from django.contrib.auth import get_user_model
from django.contrib.gis.geos import GEOSGeometry
from django.test import TestCase
from django.urls import reverse

from . import TestAdminMixin, TestLociMixin
from ..models import FloorPlan, Location, ObjectLocation
from .testdeviceapp.models import Device


class TestAdminInline(TestAdminMixin, TestLociMixin, TestCase):
object_model = get_user_model()
object_model = Device
location_model = Location
floorplan_model = FloorPlan
object_location_model = ObjectLocation
user_model = get_user_model()
app_label = 'django_loci'
inline_field_prefix = 'objectlocation-content_type-object_id'
_p = '{0}-{1}'.format(app_label, inline_field_prefix)
_params = {
'{0}-0-name'.format(_p): 'Centro Piazza Venezia',
'{0}-0-address'.format(_p): 'Piazza Venezia, Roma, Italia',
'{0}-0-geometry'.format(_p): '{"type": "Point", "coordinates": [12.512124, 41.898903]}',
'{0}-TOTAL_FORMS'.format(_p): '1',
'{0}-INITIAL_FORMS'.format(_p): '0',
'{0}-MIN_NUM_FORMS'.format(_p): '0',
'{0}-MAX_NUM_FORMS'.format(_p): '1',
}

def test_json_urls(self):
self._login_as_admin()
Expand All @@ -20,3 +34,90 @@ def test_json_urls(self):
self.assertContains(r, url)
url = reverse('admin:django_loci_location_floorplans_json', args=['0000'])
self.assertContains(r, url)

def test_add_outdoor_new(self):
self._login_as_admin()
p = self._p
params = self._params
params.update({
'name': 'test-outdoor-add-new',
'{0}-0-type'.format(p): 'outdoor',
'{0}-0-location_selection'.format(p): 'new',
'{0}-0-location'.format(p): '',
'{0}-0-floorplan_selection'.format(p): '',
'{0}-0-floorplan'.format(p): '',
'{0}-0-floor'.format(p): '',
'{0}-0-image'.format(p): '',
'{0}-0-indoor'.format(p): '',
'{0}-0-id'.format(p): '',
})
self.client.post(reverse('admin:testdeviceapp_device_add'), params)
loc = self.location_model.objects.get(name=params['{0}-0-name'.format(p)])
self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
self.assertEqual(loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords)
self.assertEqual(loc.objectlocation_set.count(), 1)
self.assertEqual(loc.objectlocation_set.first().content_object.name, params['name'])

def test_add_outdoor_existing(self):
self._login_as_admin()
p = self._p
pre_loc = self._create_location()
params = self._params
params.update({
'name': 'test-outdoor-add-existing',
'{0}-0-type'.format(p): 'outdoor',
'{0}-0-location_selection'.format(p): 'existing',
'{0}-0-location'.format(p): str(pre_loc.id),
'{0}-0-floorplan_selection'.format(p): '',
'{0}-0-floorplan'.format(p): '',
'{0}-0-floor'.format(p): '',
'{0}-0-image'.format(p): '',
'{0}-0-indoor'.format(p): '',
'{0}-0-id'.format(p): '',
})
self.client.post(reverse('admin:testdeviceapp_device_add'), params)
loc = self.location_model.objects.get(name=params['{0}-0-name'.format(p)])
self.assertEqual(pre_loc.id, loc.id)
self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
self.assertEqual(loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords)
self.assertEqual(loc.objectlocation_set.count(), 1)
self.assertEqual(loc.objectlocation_set.first().content_object.name, params['name'])
self.assertEqual(Location.objects.count(), 1)

def test_change_outdoor(self):
self._login_as_admin()
p = self._p
# -- TODO! this should become a method
obj = self._create_object(name='test-change-outdoor')
pre_loc = self._create_location()
ol = self.object_location_model(type='outdoor',
location=pre_loc,
content_object=obj)
ol.full_clean()
ol.save()
# --
r = self.client.get(reverse('admin:testdeviceapp_device_change', args=[obj.pk]))
self.assertContains(r, obj.name)
# -- change
params = self._params
params.update({
'name': 'test-outdoor-change',
'{0}-0-type'.format(p): 'outdoor',
'{0}-0-location_selection'.format(p): 'existing',
'{0}-0-location'.format(p): str(pre_loc.id),
'{0}-0-floorplan_selection'.format(p): '',
'{0}-0-floorplan'.format(p): '',
'{0}-0-floor'.format(p): '',
'{0}-0-image'.format(p): '',
'{0}-0-indoor'.format(p): '',
'{0}-0-id'.format(p): str(ol.id),
'{0}-INITIAL_FORMS'.format(p): '1',
})
self.client.post(reverse('admin:testdeviceapp_device_change', args=[obj.pk]), params)
loc = self.location_model.objects.get(name=params['{0}-0-name'.format(p)])
self.assertEqual(pre_loc.id, loc.id)
self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
self.assertEqual(loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords)
self.assertEqual(loc.objectlocation_set.count(), 1)
self.assertEqual(loc.objectlocation_set.first().content_object.name, params['name'])
self.assertEqual(Location.objects.count(), 1)

0 comments on commit 5a50432

Please sign in to comment.