-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified bedCreate API View to support bulk creating beds (#1275)
* Modified BedCreate View to support bulk creating beds * Minor fix * Added test for single and multiple bed creation * Added missing commits, modified tests * Removed hardcoded facility from tests * Fixed tests * minor fix * Modified serializer to allow only 100 beds at once * make requested changes Signed-off-by: Aakash Singh <[email protected]> * add test case for more than allowed beds Signed-off-by: Aakash Singh <[email protected]> * remove unnecessary use of transaction test case Signed-off-by: Aakash Singh <[email protected]> --------- Signed-off-by: Aakash Singh <[email protected]> Co-authored-by: Aakash Singh <[email protected]> Co-authored-by: Vignesh Hari <[email protected]> Co-authored-by: Rithvik Nishad <[email protected]>
- Loading branch information
1 parent
7dfbef0
commit fdfb798
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from rest_framework import status | ||
|
||
from care.facility.models import AssetLocation, Bed | ||
from care.utils.tests.test_base import TestBase | ||
|
||
|
||
class SingleBedTest(TestBase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.asset_location: AssetLocation = AssetLocation.objects.create( | ||
name="asset location", location_type=1, facility=self.facility | ||
) | ||
|
||
def tearDown(self) -> None: | ||
Bed._default_manager.filter(facility=self.facility).delete() | ||
AssetLocation._default_manager.filter(id=self.asset_location.id).delete() | ||
|
||
def test_create(self): | ||
sample_data = { | ||
"bed_type": "REGULAR", | ||
"description": "Testing creation of beds.", | ||
"facility": self.facility.external_id, | ||
"location": self.asset_location.external_id, | ||
"name": "Test Bed", | ||
"number_of_beds": 1, | ||
} | ||
response = self.client.post("/api/v1/bed/", sample_data, format="json") | ||
self.assertIs(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual( | ||
Bed.objects.filter(facility=self.facility).count(), | ||
sample_data["number_of_beds"], | ||
) | ||
|
||
|
||
class MultipleBedTest(TestBase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.asset_location: AssetLocation = AssetLocation.objects.create( | ||
name="asset location", location_type=1, facility=self.facility | ||
) | ||
|
||
def tearDown(self) -> None: | ||
Bed._default_manager.filter(facility=self.facility).delete() | ||
AssetLocation._default_manager.filter(id=self.asset_location.id).delete() | ||
|
||
def test_create(self): | ||
sample_data = { | ||
"bed_type": "REGULAR", | ||
"description": "Testing creation of beds.", | ||
"facility": self.facility.external_id, | ||
"location": self.asset_location.external_id, | ||
"name": "Test Bed", | ||
"number_of_beds": 5, | ||
} | ||
response = self.client.post("/api/v1/bed/", sample_data, format="json") | ||
self.assertIs(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual( | ||
Bed.objects.filter(facility=self.facility).count(), | ||
sample_data["number_of_beds"], | ||
) | ||
|
||
def test_create_with_more_than_allowed_value(self): | ||
sample_data = { | ||
"bed_type": "REGULAR", | ||
"description": "Testing creation of beds.", | ||
"facility": self.facility.external_id, | ||
"location": self.asset_location.external_id, | ||
"name": "Test 2 Bed", | ||
"number_of_beds": 101, | ||
} | ||
response = self.client.post("/api/v1/bed/", sample_data, format="json") | ||
self.assertIs(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(Bed.objects.filter(facility=self.facility).count(), 0) |