33import uuid
44
55from django .contrib .auth import get_user_model
6+ from django .contrib .contenttypes .models import ContentType
67from django .contrib .gis .geos import Point
78from django .test import TestCase
89from django .test .client import BOUNDARY , MULTIPART_CONTENT , encode_multipart
@@ -300,6 +301,7 @@ class TestGeoApi(
300301 def setUp (self ):
301302 admin = self ._create_admin ()
302303 self .client .force_login (admin )
304+ ContentType .objects .clear_cache ()
303305
304306 def _create_device_location (self , ** kwargs ):
305307 options = dict ()
@@ -494,7 +496,7 @@ def test_post_location_list(self):
494496 'address' : 'Via del Corso, Roma, Italia' ,
495497 'geometry' : coords ,
496498 }
497- with self .assertNumQueries (9 ):
499+ with self .assertNumQueries (13 ):
498500 response = self .client .post (path , data , content_type = 'application/json' )
499501 self .assertEqual (response .status_code , 201 )
500502
@@ -525,7 +527,7 @@ def test_put_location_detail(self):
525527 'address' : 'Via del Corso, Roma, Italia' ,
526528 'geometry' : coords ,
527529 }
528- with self .assertNumQueries (6 ):
530+ with self .assertNumQueries (10 ):
529531 response = self .client .put (path , data , content_type = 'application/json' )
530532 self .assertEqual (response .status_code , 200 )
531533 self .assertEqual (response .data ['organization' ], org1 .pk )
@@ -536,7 +538,7 @@ def test_patch_location_detail(self):
536538 self .assertEqual (l1 .name , 'test-location' )
537539 path = reverse ('geo_api:detail_location' , args = [l1 .pk ])
538540 data = {'name' : 'change-test-location' }
539- with self .assertNumQueries (5 ):
541+ with self .assertNumQueries (9 ):
540542 response = self .client .patch (path , data , content_type = 'application/json' )
541543 self .assertEqual (response .status_code , 200 )
542544 self .assertEqual (response .data ['name' ], 'change-test-location' )
@@ -566,7 +568,7 @@ def test_patch_floorplan_detail_api(self):
566568 fl = self ._create_floorplan (location = l1 )
567569 path = reverse ('geo_api:detail_location' , args = [l1 .pk ])
568570 data = {'floorplan' : {'floor' : 13 }}
569- with self .assertNumQueries (13 ):
571+ with self .assertNumQueries (17 ):
570572 response = self .client .patch (path , data , content_type = 'application/json' )
571573 self .assertEqual (response .status_code , 200 )
572574 fl .refresh_from_db ()
@@ -577,7 +579,7 @@ def test_change_location_type_to_outdoor_api(self):
577579 self ._create_floorplan (location = l1 )
578580 path = reverse ('geo_api:detail_location' , args = [l1 .pk ])
579581 data = {'type' : 'outdoor' }
580- with self .assertNumQueries (9 ):
582+ with self .assertNumQueries (13 ):
581583 response = self .client .patch (path , data , content_type = 'application/json' )
582584 self .assertEqual (response .status_code , 200 )
583585 self .assertEqual (response .data ['floorplan' ], [])
@@ -603,7 +605,7 @@ def test_create_location_with_floorplan(self):
603605 'floorplan.floor' : ['23' ],
604606 'floorplan.image' : [fl_image ],
605607 }
606- with self .assertNumQueries (16 ):
608+ with self .assertNumQueries (20 ):
607609 response = self .client .post (path , data , format = 'multipart' )
608610 self .assertEqual (response .status_code , 201 )
609611 self .assertEqual (Location .objects .count (), 1 )
@@ -627,7 +629,7 @@ def test_create_new_floorplan_with_put_location_api(self):
627629 'floorplan.floor' : '23' ,
628630 'floorplan.image' : fl_image ,
629631 }
630- with self .assertNumQueries (16 ):
632+ with self .assertNumQueries (20 ):
631633 response = self .client .put (
632634 path , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
633635 )
@@ -695,7 +697,7 @@ def test_create_devicelocation_using_related_ids(self):
695697 floorplan = self ._create_floorplan ()
696698 location = floorplan .location
697699 url = reverse ('geo_api:device_location' , args = [device .id ])
698- with self .assertNumQueries (15 ):
700+ with self .assertNumQueries (26 ):
699701 response = self .client .put (
700702 url ,
701703 data = {
@@ -733,7 +735,7 @@ def test_create_devicelocation_location_floorplan(self):
733735 'floorplan.image' : self ._get_simpleuploadedfile (),
734736 'indoor' : ['12.342,23.541' ],
735737 }
736- with self .assertNumQueries (29 ):
738+ with self .assertNumQueries (40 ):
737739 response = self .client .put (
738740 url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
739741 )
@@ -800,7 +802,7 @@ def test_create_devicelocation_only_location(self):
800802 'type' : 'indoor' ,
801803 }
802804 }
803- with self .assertNumQueries (18 ):
805+ with self .assertNumQueries (29 ):
804806 response = self .client .put (url , data = data , content_type = 'application/json' )
805807 self .assertEqual (response .status_code , 201 )
806808 self .assertEqual (self .location_model .objects .count (), 1 )
@@ -840,7 +842,7 @@ def test_create_devicelocation_existing_location_new_floorplan(self):
840842 'floorplan.image' : self ._get_simpleuploadedfile (),
841843 'indoor' : ['12.342,23.541' ],
842844 }
843- with self .assertNumQueries (23 ):
845+ with self .assertNumQueries (34 ):
844846 response = self .client .put (
845847 url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
846848 )
@@ -863,7 +865,7 @@ def test_update_devicelocation_change_location_outdoor_to_indoor(self):
863865 }
864866 self .assertEqual (device_location .location .type , 'outdoor' )
865867 self .assertEqual (device_location .floorplan , None )
866- with self .assertNumQueries (21 ):
868+ with self .assertNumQueries (31 ):
867869 response = self .client .put (
868870 path , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
869871 )
@@ -882,7 +884,7 @@ def test_update_devicelocation_patch_indoor(self):
882884 'indoor' : '0,0' ,
883885 }
884886 self .assertEqual (device_location .indoor , '-140.38620,40.369227' )
885- with self .assertNumQueries (10 ):
887+ with self .assertNumQueries (18 ):
886888 response = self .client .patch (path , data , content_type = 'application/json' )
887889 self .assertEqual (response .status_code , 200 )
888890 device_location .refresh_from_db ()
@@ -899,7 +901,7 @@ def test_update_devicelocation_floorplan_related_id(self):
899901 data = {
900902 'floorplan' : str (floor2 .id ),
901903 }
902- with self .assertNumQueries (12 ):
904+ with self .assertNumQueries (20 ):
903905 response = self .client .patch (path , data , content_type = 'application/json' )
904906 self .assertEqual (response .status_code , 200 )
905907 device_location .refresh_from_db ()
@@ -913,7 +915,7 @@ def test_update_devicelocation_location_related_id(self):
913915 data = {
914916 'location' : str (location2 .id ),
915917 }
916- with self .assertNumQueries (9 ):
918+ with self .assertNumQueries (19 ):
917919 response = self .client .patch (path , data , content_type = 'application/json' )
918920 self .assertEqual (response .status_code , 200 )
919921 device_location .refresh_from_db ()
0 commit comments