Skip to content

Commit

Permalink
fix asset class initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Nov 21, 2024
1 parent e901333 commit 5102310
Show file tree
Hide file tree
Showing 3 changed files with 16 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(
{

Check warning on line 402 in care/facility/api/viewsets/asset.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Expected type 'Enum', got 'dict\[str, str \| Any\]' instead
**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(
{

Check warning on line 66 in care/facility/tasks/asset_monitor.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Expected type 'Enum', got 'dict\[str, str \| Any\]' instead
**asset.meta,
"id": asset.external_id,
"id": str(asset.external_id),
"middleware_hostname": resolved_middleware,
}
)
Expand Down
14 changes: 14 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,19 @@ 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
)
asset_class = AssetClasses[asset.asset_class].value(
{

Check warning on line 48 in care/facility/tests/test_asset_api.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Expected type 'Enum', got 'dict\[str, str\]' instead
**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 5102310

Please sign in to comment.