Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes from main repo for list api fix #4

Merged
merged 26 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions camera/api/viewsets/position_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
37 changes: 36 additions & 1 deletion camera/tests/test_camera_preset_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading