Skip to content

Commit

Permalink
added test cases for asset bed (#2532)
Browse files Browse the repository at this point in the history
added test cases for asset bed (#2532)
  • Loading branch information
DraKen0009 authored Nov 14, 2024
1 parent d6d069e commit 8f352e8
Show file tree
Hide file tree
Showing 7 changed files with 571 additions and 235 deletions.
9 changes: 6 additions & 3 deletions care/facility/api/serializers/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.timezone import now
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.exceptions import PermissionDenied, ValidationError
from rest_framework.serializers import (
CharField,
JSONField,
Expand Down Expand Up @@ -174,11 +174,14 @@ def validate(self, attrs):

facilities = get_facility_queryset(user)
if not facilities.filter(id=location.facility.id).exists():
raise PermissionError
error_message = (
"You do not have permission to access this facility's asset."
)
raise PermissionDenied(error_message)
del attrs["location"]
attrs["current_location"] = location

# validate that warraty date is not in the past
# validate that warranty date is not in the past
if warranty_amc_end_of_validity := attrs.get("warranty_amc_end_of_validity"):
# pop out warranty date if it is not changed
if (
Expand Down
12 changes: 9 additions & 3 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db.models import Exists, OuterRef, Q
from django.shortcuts import get_object_or_404
from django.utils import timezone
from rest_framework.exceptions import ValidationError
from rest_framework.exceptions import PermissionDenied, ValidationError
from rest_framework.serializers import (
BooleanField,
CharField,
Expand Down Expand Up @@ -74,7 +74,10 @@ def validate(self, attrs):
if (not facilities.filter(id=location.facility.id).exists()) or (
not facilities.filter(id=facility.id).exists()
):
raise PermissionError
error_message = (
"You do not have permission to access this facility's bed."
)
raise PermissionDenied(error_message)
del attrs["location"]
attrs["location"] = location
attrs["facility"] = facility
Expand Down Expand Up @@ -110,7 +113,10 @@ def validate(self, attrs):
if (
not facilities.filter(id=asset.current_location.facility.id).exists()
) or (not facilities.filter(id=bed.facility.id).exists()):
raise PermissionError
error_message = (
"You do not have permission to access this facility's assetbed."
)
raise PermissionDenied(error_message)
if AssetBed.objects.filter(asset=asset, bed=bed).exists():
raise ValidationError(
{"non_field_errors": "Asset is already linked to bed"}
Expand Down
219 changes: 0 additions & 219 deletions care/facility/tests/test_asset_bed_api.py

This file was deleted.

6 changes: 3 additions & 3 deletions care/facility/tests/test_asset_location_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUpTestData(cls) -> None:
asset_class=AssetClasses.HL7MONITOR.name,
)
cls.bed = cls.create_bed(cls.facility, cls.asset_location_with_linked_bed)
cls.asset_bed = cls.create_asset_bed(cls.asset, cls.bed)
cls.asset_bed = cls.create_assetbed(cls.bed, cls.asset)
cls.patient = cls.create_patient(cls.district, cls.facility)
cls.consultation = cls.create_consultation(cls.patient, cls.facility)
cls.consultation_bed = cls.create_consultation_bed(cls.consultation, cls.bed)
Expand All @@ -36,8 +36,8 @@ def setUpTestData(cls) -> None:
cls.asset_second_location, asset_class=AssetClasses.HL7MONITOR.name
)
cls.asset_bed_second = cls.create_bed(cls.facility, cls.asset_second_location)
cls.assetbed_second = cls.create_asset_bed(
cls.asset_second, cls.asset_bed_second
cls.assetbed_second = cls.create_assetbed(
cls.asset_bed_second, cls.asset_second
)

def test_list_asset_locations(self):
Expand Down
Loading

0 comments on commit 8f352e8

Please sign in to comment.