Skip to content

Commit

Permalink
fix(asset_location): fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Nov 17, 2023
1 parent ec32f1b commit 397a085
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Generated by Django 4.2.5 on 2023-11-17 06:36
# Generated by Django 4.2.5 on 2023-11-17 13:25

import uuid

import django.db.models.deletion
from django.conf import settings
Expand All @@ -24,7 +26,19 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("deleted", models.BooleanField(default=False)),
(
"external_id",
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
(
"created_date",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
(
"modified_date",
models.DateTimeField(auto_now=True, db_index=True, null=True),
),
("deleted", models.BooleanField(db_index=True, default=False)),
(
"asset_location",
models.ForeignKey(
Expand All @@ -48,6 +62,9 @@ class Migration(migrations.Migration):
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="assetlocation",
Expand Down
14 changes: 9 additions & 5 deletions care/facility/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ class RoomType(enum.Enum):
)


class AssetLocationDutyStaff(models.Model):
class AssetLocationDutyStaff(BaseModel):
asset_location = models.ForeignKey(
AssetLocation, on_delete=models.CASCADE, null=False, blank=False
)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False)

deleted = models.BooleanField(default=False)

created_by = models.ForeignKey(
User,
on_delete=models.PROTECT,
Expand Down Expand Up @@ -113,7 +111,11 @@ class Asset(BaseModel):
choices=AssetTypeChoices, default=AssetType.INTERNAL.value
)
asset_class = models.CharField(
choices=AssetClassChoices, default=None, null=True, blank=True, max_length=20
choices=AssetClassChoices,
default=None,
null=True,
blank=True,
max_length=20,
)
status = models.IntegerField(choices=StatusChoices, default=Status.ACTIVE.value)
current_location = models.ForeignKey(
Expand All @@ -124,7 +126,9 @@ class Asset(BaseModel):
serial_number = models.CharField(max_length=1024, blank=True, null=True)
warranty_details = models.TextField(null=True, blank=True, default="") # Deprecated
meta = JSONField(
default=dict, blank=True, validators=[JSONFieldSchemaValidator(ASSET_META)]
default=dict,
blank=True,
validators=[JSONFieldSchemaValidator(ASSET_META)],
)
# Vendor Details
vendor_name = models.CharField(max_length=1024, blank=True, null=True)
Expand Down
12 changes: 7 additions & 5 deletions care/facility/tests/test_asset_location_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def test_retrieve_asset_location(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["id"], str(self.asset_location.external_id))
self.assertEqual(
response.data["middleware_address"], self.asset_location.middleware_address
response.data["middleware_address"],
self.asset_location.middleware_address,
)

def test_create_asset_location(self):
Expand All @@ -44,7 +45,8 @@ def test_create_asset_location(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.data["name"], sample_data["name"])
self.assertEqual(
response.data["middleware_address"], sample_data["middleware_address"]
response.data["middleware_address"],
sample_data["middleware_address"],
)

def test_update_asset_location(self):
Expand All @@ -59,7 +61,8 @@ def test_update_asset_location(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["name"], sample_data["name"])
self.assertEqual(
response.data["middleware_address"], sample_data["middleware_address"]
response.data["middleware_address"],
sample_data["middleware_address"],
)

def test_create_asset_location_invalid_middleware(self):
Expand Down Expand Up @@ -101,5 +104,4 @@ def test_assign_duty_staff(self):
data,
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()["duty_staff_objects"]), 2)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

0 comments on commit 397a085

Please sign in to comment.