From 01c66c37f2489c84328422faffacda045dc07983 Mon Sep 17 00:00:00 2001 From: Prafful Sharma <115104695+DraKen0009@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:07:07 +0530 Subject: [PATCH] changes from main repo for list api fix (#4) * added workflows and tests * added workflows and tests2 * fix workflows * fix workflows 2 * fix workflows 3 * fix workflows 4 * fixed tests and fixed migrations * fixing workflows 5 * fixing workflows 6 * fixing workflows 7 * fixing workflows 8 * fixing workflows 9 * fixing workflows 10 * fixing workflows 11 * fixing workflows 12 * fixing workflows 13 * fixing workflows 14 * fixing workflows 15 * fixing workflows 16 * fixing workflows 17 * fixing workflows 18 * fixing workflows 19 * fixing workflows 20 * fixing workflows 21 * fixed changes from main repo for list api fix --- camera/api/viewsets/position_preset.py | 8 ++++-- camera/tests/test_camera_preset_apis.py | 37 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/camera/api/viewsets/position_preset.py b/camera/api/viewsets/position_preset.py index aa3fb4f..a899a45 100644 --- a/camera/api/viewsets/position_preset.py +++ b/camera/api/viewsets/position_preset.py @@ -98,10 +98,14 @@ def get_queryset(self): ) if asset_external_id: return queryset.filter( - asset_bed__asset=self.get_asset_obj(asset_external_id) + asset_bed__asset=self.get_asset_obj(asset_external_id), + asset_bed__deleted=False ) if bed_external_id: - return queryset.filter(asset_bed__bed=self.get_bed_obj(bed_external_id)) + return queryset.filter( + asset_bed__bed=self.get_bed_obj(bed_external_id), + asset_bed__deleted=False + ) if self.kwargs.get("external_id"): return queryset.filter(external_id=self.kwargs.get("external_id")) diff --git a/camera/tests/test_camera_preset_apis.py b/camera/tests/test_camera_preset_apis.py index 832c5ef..abfd5c2 100644 --- a/camera/tests/test_camera_preset_apis.py +++ b/camera/tests/test_camera_preset_apis.py @@ -143,7 +143,42 @@ def test_create_camera_preset_with_same_name_in_same_bed(self): ) self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) - + def test_list_bed_with_deleted_assetbed(self): + res = self.client.post( + self.get_base_url(self.asset_bed1.external_id), + { + "name": "Preset with proper position", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + res = self.client.post( + self.get_base_url(self.asset_bed2.external_id), + { + "name": "Preset with proper position 2", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + + res = self.client.get(f"/api/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 2) + + self.asset_bed1.delete() + self.asset_bed1.refresh_from_db() + res = self.client.get(f"/api/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 1) + def test_meta_validations_for_onvif_asset(self): valid_meta = { "local_ip_address": "192.168.0.1",