@@ -1003,6 +1003,65 @@ def _assert_device_list_with_geo_filter(response=None, device=None):
10031003 r2 = self .client .get (f"{ path } ?with_geo=true" )
10041004 _assert_device_list_with_geo_filter (response = r2 , device = device_b )
10051005
1006+ def test_filter_devices_by_location (self ):
1007+ org = self ._create_org ()
1008+ device_1 = self ._create_device (
1009+ name = "device-1" , mac_address = "00:11:22:33:44:55" , organization = org
1010+ )
1011+ device_2 = self ._create_device (
1012+ name = "device-2" , mac_address = "00:11:22:33:44:66" , organization = org
1013+ )
1014+ location_1 = self ._create_location (name = "location-1 findme" , organization = org )
1015+ location_2 = self ._create_location (name = "location-2" , organization = org )
1016+ self ._create_device_location (content_object = device_1 , location = location_1 )
1017+ self ._create_device_location (content_object = device_2 , location = location_2 )
1018+ path = reverse ("config_api:device_list" )
1019+ with self .subTest ("filter by location UUID" ):
1020+ response = self .client .get (f"{ path } ?location={ location_1 .pk } " )
1021+ self .assertEqual (response .status_code , 200 )
1022+ self .assertEqual (response .data ["count" ], 1 )
1023+ self .assertEqual (response .data ["results" ][0 ]["id" ], str (device_1 .pk ))
1024+ with self .subTest ("filter by location name" ):
1025+ response = self .client .get (f"{ path } ?location__name=FIND" )
1026+ self .assertEqual (response .status_code , 200 )
1027+ self .assertEqual (response .data ["count" ], 1 )
1028+ self .assertEqual (response .data ["results" ][0 ]["id" ], str (device_1 .pk ))
1029+ with self .subTest ("filter by wrong location name, expect zero results" ):
1030+ response = self .client .get (f"{ path } ?location__name=WRONG" )
1031+ self .assertEqual (response .status_code , 200 )
1032+ self .assertEqual (response .data ["count" ], 0 )
1033+
1034+ def test_filter_devices_by_floorplan_uuid (self ):
1035+ org = self ._create_org ()
1036+ device_1 = self ._create_device (
1037+ name = "device-1" , mac_address = "00:11:22:33:44:55" , organization = org
1038+ )
1039+ device_2 = self ._create_device (
1040+ name = "device-2" , mac_address = "00:11:22:33:44:66" , organization = org
1041+ )
1042+ location = self ._create_location (
1043+ name = "location" , type = "indoor" , organization = org
1044+ )
1045+ floorplan_1 = self ._create_floorplan (location = location , floor = 1 )
1046+ floorplan_2 = self ._create_floorplan (location = location , floor = 2 )
1047+ self ._create_device_location (
1048+ content_object = device_1 ,
1049+ location = location ,
1050+ floorplan = floorplan_1 ,
1051+ indoor = "-1,-2" ,
1052+ )
1053+ self ._create_device_location (
1054+ content_object = device_2 ,
1055+ location = location ,
1056+ floorplan = floorplan_2 ,
1057+ indoor = "-3,-4" ,
1058+ )
1059+ path = reverse ("config_api:device_list" )
1060+ response = self .client .get (f"{ path } ?floorplan={ floorplan_1 .pk } " )
1061+ self .assertEqual (response .status_code , 200 )
1062+ self .assertEqual (response .data ["count" ], 1 )
1063+ self .assertEqual (response .data ["results" ][0 ]["id" ], str (device_1 .pk ))
1064+
10061065 def test_deactivated_device (self ):
10071066 floorplan = self ._create_floorplan ()
10081067 device_location = self ._create_object_location (
0 commit comments