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 )
@@ -722,7 +724,7 @@ def test_create_devicelocation_using_related_ids(self):
722724 floorplan = self ._create_floorplan ()
723725 location = floorplan .location
724726 url = reverse ("geo_api:device_location" , args = [device .id ])
725- with self .assertNumQueries (18 ):
727+ with self .assertNumQueries (26 ):
726728 response = self .client .put (
727729 url ,
728730 data = {
@@ -760,7 +762,7 @@ def test_create_devicelocation_location_floorplan(self):
760762 "floorplan.image" : self ._get_simpleuploadedfile (),
761763 "indoor" : ["12.342,23.541" ],
762764 }
763- with self .assertNumQueries (32 ):
765+ with self .assertNumQueries (40 ):
764766 response = self .client .put (
765767 url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
766768 )
@@ -827,8 +829,8 @@ def test_create_devicelocation_only_location(self):
827829 "type" : "indoor" ,
828830 }
829831 }
830- with self .assertNumQueries (21 ):
831- response = self .client .put (url , data = data , content_type = " application/json" )
832+ with self .assertNumQueries (29 ):
833+ response = self .client .put (url , data = data , content_type = ' application/json' )
832834 self .assertEqual (response .status_code , 201 )
833835 self .assertEqual (self .location_model .objects .count (), 1 )
834836 self .assertEqual (self .object_location_model .objects .count (), 1 )
@@ -867,7 +869,7 @@ def test_create_devicelocation_existing_location_new_floorplan(self):
867869 "floorplan.image" : self ._get_simpleuploadedfile (),
868870 "indoor" : ["12.342,23.541" ],
869871 }
870- with self .assertNumQueries (26 ):
872+ with self .assertNumQueries (34 ):
871873 response = self .client .put (
872874 url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
873875 )
@@ -890,7 +892,7 @@ def test_update_devicelocation_change_location_outdoor_to_indoor(self):
890892 }
891893 self .assertEqual (device_location .location .type , "outdoor" )
892894 self .assertEqual (device_location .floorplan , None )
893- with self .assertNumQueries (23 ):
895+ with self .assertNumQueries (31 ):
894896 response = self .client .put (
895897 path , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
896898 )
@@ -909,7 +911,7 @@ def test_update_devicelocation_patch_indoor(self):
909911 "indoor" : "0,0" ,
910912 }
911913 self .assertEqual (device_location .indoor , "-140.38620,40.369227" )
912- with self .assertNumQueries (12 ):
914+ with self .assertNumQueries (18 ):
913915 response = self .client .patch (path , data , content_type = "application/json" )
914916 self .assertEqual (response .status_code , 200 )
915917 device_location .refresh_from_db ()
@@ -926,8 +928,8 @@ def test_update_devicelocation_floorplan_related_id(self):
926928 data = {
927929 "floorplan" : str (floor2 .id ),
928930 }
929- with self .assertNumQueries (14 ):
930- response = self .client .patch (path , data , content_type = " application/json" )
931+ with self .assertNumQueries (20 ):
932+ response = self .client .patch (path , data , content_type = ' application/json' )
931933 self .assertEqual (response .status_code , 200 )
932934 device_location .refresh_from_db ()
933935 self .assertEqual (device_location .floorplan , floor2 )
@@ -940,7 +942,7 @@ def test_update_devicelocation_location_related_id(self):
940942 data = {
941943 "location" : str (location2 .id ),
942944 }
943- with self .assertNumQueries (11 ):
945+ with self .assertNumQueries (19 ):
944946 response = self .client .patch (path , data , content_type = "application/json" )
945947 self .assertEqual (response .status_code , 200 )
946948 device_location .refresh_from_db ()
0 commit comments