Skip to content

Commit

Permalink
fix asset class initialization (#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Nov 21, 2024
1 parent e901333 commit 2970fe1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def operate_assets(self, request, *args, **kwargs):
asset_class: BaseAssetIntegration = AssetClasses[asset.asset_class].value(
{
**asset.meta,
"id": asset.external_id,
"id": str(asset.external_id),
"middleware_hostname": middleware_hostname,
}
)
Expand Down
2 changes: 1 addition & 1 deletion care/facility/tasks/asset_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def check_asset_status(): # noqa: PLR0912
].value(
{
**asset.meta,
"id": asset.external_id,
"id": str(asset.external_id),
"middleware_hostname": resolved_middleware,
}
)
Expand Down
21 changes: 21 additions & 0 deletions care/facility/tests/test_asset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from care.facility.models import Asset, Bed
from care.users.models import User
from care.utils.assetintegration.asset_classes import AssetClasses
from care.utils.assetintegration.base import BaseAssetIntegration
from care.utils.assetintegration.hl7monitor import HL7MonitorAsset
from care.utils.assetintegration.onvif import OnvifAsset
from care.utils.assetintegration.ventilator import VentilatorAsset
Expand Down Expand Up @@ -39,6 +40,26 @@ def validate_invalid_meta(self, asset_class, meta):
with self.assertRaises(ValidationError):
asset_class(meta)

def test_asset_class_initialization(self):
asset = self.create_asset(
self.asset_location,
asset_class=AssetClasses.ONVIF.name,
meta={
"local_ip_address": "192.168.0.1",
"camera_access_key": "username:password:access_key",
"middleware_hostname": "middleware.local",
"insecure_connection": True,
},
)
asset_class = AssetClasses[asset.asset_class].value(
{
**asset.meta,
"id": str(asset.external_id),
"middleware_hostname": "middleware.local",
}
)
self.assertIsInstance(asset_class, BaseAssetIntegration)

def test_meta_validations_for_onvif_asset(self):
valid_meta = {
"local_ip_address": "192.168.0.1",
Expand Down

0 comments on commit 2970fe1

Please sign in to comment.