3
3
import uuid
4
4
5
5
from django .contrib .auth import get_user_model
6
+ from django .contrib .contenttypes .models import ContentType
6
7
from django .contrib .gis .geos import Point
7
8
from django .test import TestCase
8
9
from django .test .client import BOUNDARY , MULTIPART_CONTENT , encode_multipart
@@ -300,6 +301,7 @@ class TestGeoApi(
300
301
def setUp (self ):
301
302
admin = self ._create_admin ()
302
303
self .client .force_login (admin )
304
+ ContentType .objects .clear_cache ()
303
305
304
306
def _create_device_location (self , ** kwargs ):
305
307
options = dict ()
@@ -494,7 +496,7 @@ def test_post_location_list(self):
494
496
"address" : "Via del Corso, Roma, Italia" ,
495
497
"geometry" : coords ,
496
498
}
497
- with self .assertNumQueries (9 ):
499
+ with self .assertNumQueries (13 ):
498
500
response = self .client .post (path , data , content_type = "application/json" )
499
501
self .assertEqual (response .status_code , 201 )
500
502
@@ -525,7 +527,7 @@ def test_put_location_detail(self):
525
527
"address" : "Via del Corso, Roma, Italia" ,
526
528
"geometry" : coords ,
527
529
}
528
- with self .assertNumQueries (6 ):
530
+ with self .assertNumQueries (10 ):
529
531
response = self .client .put (path , data , content_type = "application/json" )
530
532
self .assertEqual (response .status_code , 200 )
531
533
self .assertEqual (response .data ["organization" ], org1 .pk )
@@ -536,7 +538,7 @@ def test_patch_location_detail(self):
536
538
self .assertEqual (l1 .name , "test-location" )
537
539
path = reverse ("geo_api:detail_location" , args = [l1 .pk ])
538
540
data = {"name" : "change-test-location" }
539
- with self .assertNumQueries (5 ):
541
+ with self .assertNumQueries (9 ):
540
542
response = self .client .patch (path , data , content_type = "application/json" )
541
543
self .assertEqual (response .status_code , 200 )
542
544
self .assertEqual (response .data ["name" ], "change-test-location" )
@@ -566,7 +568,7 @@ def test_patch_floorplan_detail_api(self):
566
568
fl = self ._create_floorplan (location = l1 )
567
569
path = reverse ("geo_api:detail_location" , args = [l1 .pk ])
568
570
data = {"floorplan" : {"floor" : 13 }}
569
- with self .assertNumQueries (13 ):
571
+ with self .assertNumQueries (17 ):
570
572
response = self .client .patch (path , data , content_type = "application/json" )
571
573
self .assertEqual (response .status_code , 200 )
572
574
fl .refresh_from_db ()
@@ -577,7 +579,7 @@ def test_change_location_type_to_outdoor_api(self):
577
579
self ._create_floorplan (location = l1 )
578
580
path = reverse ("geo_api:detail_location" , args = [l1 .pk ])
579
581
data = {"type" : "outdoor" }
580
- with self .assertNumQueries (9 ):
582
+ with self .assertNumQueries (13 ):
581
583
response = self .client .patch (path , data , content_type = "application/json" )
582
584
self .assertEqual (response .status_code , 200 )
583
585
self .assertEqual (response .data ["floorplan" ], [])
@@ -603,7 +605,7 @@ def test_create_location_with_floorplan(self):
603
605
"floorplan.floor" : ["23" ],
604
606
"floorplan.image" : [fl_image ],
605
607
}
606
- with self .assertNumQueries (16 ):
608
+ with self .assertNumQueries (20 ):
607
609
response = self .client .post (path , data , format = "multipart" )
608
610
self .assertEqual (response .status_code , 201 )
609
611
self .assertEqual (Location .objects .count (), 1 )
@@ -627,7 +629,7 @@ def test_create_new_floorplan_with_put_location_api(self):
627
629
"floorplan.floor" : "23" ,
628
630
"floorplan.image" : fl_image ,
629
631
}
630
- with self .assertNumQueries (16 ):
632
+ with self .assertNumQueries (20 ):
631
633
response = self .client .put (
632
634
path , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
633
635
)
@@ -722,7 +724,7 @@ def test_create_devicelocation_using_related_ids(self):
722
724
floorplan = self ._create_floorplan ()
723
725
location = floorplan .location
724
726
url = reverse ("geo_api:device_location" , args = [device .id ])
725
- with self .assertNumQueries (18 ):
727
+ with self .assertNumQueries (26 ):
726
728
response = self .client .put (
727
729
url ,
728
730
data = {
@@ -760,7 +762,7 @@ def test_create_devicelocation_location_floorplan(self):
760
762
"floorplan.image" : self ._get_simpleuploadedfile (),
761
763
"indoor" : ["12.342,23.541" ],
762
764
}
763
- with self .assertNumQueries (32 ):
765
+ with self .assertNumQueries (40 ):
764
766
response = self .client .put (
765
767
url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
766
768
)
@@ -827,8 +829,8 @@ def test_create_devicelocation_only_location(self):
827
829
"type" : "indoor" ,
828
830
}
829
831
}
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' )
832
834
self .assertEqual (response .status_code , 201 )
833
835
self .assertEqual (self .location_model .objects .count (), 1 )
834
836
self .assertEqual (self .object_location_model .objects .count (), 1 )
@@ -867,7 +869,7 @@ def test_create_devicelocation_existing_location_new_floorplan(self):
867
869
"floorplan.image" : self ._get_simpleuploadedfile (),
868
870
"indoor" : ["12.342,23.541" ],
869
871
}
870
- with self .assertNumQueries (26 ):
872
+ with self .assertNumQueries (34 ):
871
873
response = self .client .put (
872
874
url , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
873
875
)
@@ -890,7 +892,7 @@ def test_update_devicelocation_change_location_outdoor_to_indoor(self):
890
892
}
891
893
self .assertEqual (device_location .location .type , "outdoor" )
892
894
self .assertEqual (device_location .floorplan , None )
893
- with self .assertNumQueries (23 ):
895
+ with self .assertNumQueries (31 ):
894
896
response = self .client .put (
895
897
path , encode_multipart (BOUNDARY , data ), content_type = MULTIPART_CONTENT
896
898
)
@@ -909,7 +911,7 @@ def test_update_devicelocation_patch_indoor(self):
909
911
"indoor" : "0,0" ,
910
912
}
911
913
self .assertEqual (device_location .indoor , "-140.38620,40.369227" )
912
- with self .assertNumQueries (12 ):
914
+ with self .assertNumQueries (18 ):
913
915
response = self .client .patch (path , data , content_type = "application/json" )
914
916
self .assertEqual (response .status_code , 200 )
915
917
device_location .refresh_from_db ()
@@ -926,8 +928,8 @@ def test_update_devicelocation_floorplan_related_id(self):
926
928
data = {
927
929
"floorplan" : str (floor2 .id ),
928
930
}
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' )
931
933
self .assertEqual (response .status_code , 200 )
932
934
device_location .refresh_from_db ()
933
935
self .assertEqual (device_location .floorplan , floor2 )
@@ -940,7 +942,7 @@ def test_update_devicelocation_location_related_id(self):
940
942
data = {
941
943
"location" : str (location2 .id ),
942
944
}
943
- with self .assertNumQueries (11 ):
945
+ with self .assertNumQueries (19 ):
944
946
response = self .client .patch (path , data , content_type = "application/json" )
945
947
self .assertEqual (response .status_code , 200 )
946
948
device_location .refresh_from_db ()
0 commit comments