devicehub-django/device/tests/test_mock_device.py

50 lines
1.4 KiB
Python
Raw Permalink Normal View History

2024-10-29 07:30:33 +00:00
from device.models import Device
from unittest.mock import MagicMock
class TestDevice(Device):
2024-11-05 09:26:21 +00:00
def __init__(self, id):
super().__init__(id=id)
self.shortid = id[:6].upper()
self.uuids = []
self.hids = ['hid1', 'hid2']
self._setup_evidence()
def _setup_evidence(self):
self._evidence = MagicMock()
self._evidence.doc = {
'type': 'Computer',
'manufacturer': 'Test Manufacturer',
'model': 'Test Model',
'device': {
'serialNumber': 'SN123456',
'type': 'Computer'
2024-10-29 07:30:33 +00:00
}
2024-11-05 09:26:21 +00:00
}
self._evidence.get_manufacturer = lambda: 'Test Manufacturer'
self._evidence.get_model = lambda: 'Test Model'
self._evidence.get_chassis = lambda: 'Computer'
self._evidence.get_components = lambda: [
{
'type': 'CPU',
'model': 'Intel i7',
'manufacturer': 'Intel',
'serialNumber': 'SN12345678'
2024-11-05 09:26:21 +00:00
},
{
'type': 'RAM',
'size': '8GB',
'manufacturer': 'Kingston',
'serialNumber': 'SN87654321'
2024-11-05 09:26:21 +00:00
}
]
2024-10-29 07:30:33 +00:00
self.last_evidence = self._evidence
2024-11-05 09:26:21 +00:00
@property
def components(self):
return self.last_evidence.get_components()
2024-10-29 07:30:33 +00:00
2024-11-05 09:26:21 +00:00
@property
def serial_number(self):
return self.last_evidence.doc['device']['serialNumber']