Skip to content

Commit

Permalink
Merge pull request #2650 from DraKen0009/fixing-list-viewset-of-camer…
Browse files Browse the repository at this point in the history
…a-preset

Fixing list asset bed preset and list bed preset
  • Loading branch information
vigneshhari authored Dec 13, 2024
2 parents 88de800 + e5f5edb commit e6d4a48
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion care/facility/api/viewsets/camera_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_serializer_context(self):

class CameraPresetViewSet(GenericViewSet, ListModelMixin):
serializer_class = CameraPresetSerializer
queryset = CameraPreset.objects.all().select_related(
queryset = CameraPreset.objects.filter(asset_bed__deleted=False).select_related(
"asset_bed", "created_by", "updated_by"
)
lookup_field = "external_id"
Expand Down
36 changes: 36 additions & 0 deletions care/facility/tests/test_assetbed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,42 @@ def setUpTestData(cls):
def get_base_url(self, asset_bed_id=None):
return f"/api/v1/assetbed/{asset_bed_id or self.asset_bed1.external_id}/camera_presets/"

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/v1/bed/{self.bed.external_id}/camera_presets/")
self.assertEqual(len(res.json()["results"]), 2)

self.asset_bed1.delete()
self.asset_bed1.refresh_from_db()
res = self.client.get(f"/api/v1/bed/{self.bed.external_id}/camera_presets/")
self.assertEqual(len(res.json()["results"]), 1)

def test_create_camera_preset_without_position(self):
res = self.client.post(
self.get_base_url(),
Expand Down

0 comments on commit e6d4a48

Please sign in to comment.