Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init():
"""Test the initialization method."""
# Arrange/Act
sub = Subscription()
# Assert
assert sub.source_type is SourceType.UNKNOWN
assert sub.capability == '*'
assert sub.attribute == '*'
assert sub.value == '*'
assert sub.state_change_only
def test_to_data_capability():
"""Test the to_data method for capabilities."""
# Arrange
sub = Subscription()
sub.source_type = SourceType.CAPABILITY
sub.location_id = '397678e5-9995-4a39-9d9f-ae6ba310236b'
sub.capability = 'switch'
sub.attribute = 'switchLevel'
sub.value = '100'
sub.state_change_only = False
sub.subscription_name = "Test"
# Act
data = sub.to_data()
# Assert
assert data['sourceType'] == SourceType.CAPABILITY.value
assert data['capability']['locationId'] == \
'397678e5-9995-4a39-9d9f-ae6ba310236b'
assert data['capability']['capability'] == 'switch'
assert data['capability']['attribute'] == 'switchLevel'
assert data['capability']['value'] == '100'
assert data['capability']['subscriptionName'] == 'Test'
assert not data['capability']['stateChangeOnly']
def apply_data(self, data: dict):
"""Set the states of the app with the supplied data."""
self._subscription_id = data["id"]
self._installed_app_id = data["installedAppId"]
self._source_type = SourceType(data["sourceType"])
if self._source_type is SourceType.CAPABILITY:
capability = data["capability"]
self._location_id = capability["locationId"]
self._capability = capability["capability"]
self._attribute = capability.get("attribute", "*")
self._value = capability.get("value", "*")
self._state_change_only = capability.get("stateChangeOnly", True)
self._subscription_name = capability.get("subscriptionName", None)
if self._source_type is SourceType.DEVICE:
device = data["device"]
self._device_id = device["deviceId"]
self._component_id = device.get("componentId", "*")
self._capability = device.get("capability", "*")
self._attribute = device.get("attribute", "*")
self._value = device.get("value", "*")
self._state_change_only = device.get("stateChangeOnly", True)
def apply_data(self, data: dict):
"""Set the states of the app with the supplied data."""
self._subscription_id = data["id"]
self._installed_app_id = data["installedAppId"]
self._source_type = SourceType(data["sourceType"])
if self._source_type is SourceType.CAPABILITY:
capability = data["capability"]
self._location_id = capability["locationId"]
self._capability = capability["capability"]
self._attribute = capability.get("attribute", "*")
self._value = capability.get("value", "*")
self._state_change_only = capability.get("stateChangeOnly", True)
self._subscription_name = capability.get("subscriptionName", None)
if self._source_type is SourceType.DEVICE:
device = data["device"]
self._device_id = device["deviceId"]
self._component_id = device.get("componentId", "*")
self._capability = device.get("capability", "*")
self._attribute = device.get("attribute", "*")
self._value = device.get("value", "*")
self._state_change_only = device.get("stateChangeOnly", True)
self._subscription_name = device.get("subscriptionName", None)
def source_type(self, value: Any):
"""Set the typ eof event that is being subscribed to."""
self._source_type = SourceType(value)
def __init__(self):
"""Initialize a new instance of the subscription class."""
self._subscription_id = None
self._installed_app_id = None
self._source_type = SourceType.UNKNOWN
self._capability = "*"
self._attribute = "*"
self._value = "*"
self._state_change_only = True
self._subscription_name = None
# Capability-specific attributes
self._location_id = None
# Device-specific attributes
self._device_id = None
self._component_id = None
def apply_data(self, data: dict):
"""Set the states of the app with the supplied data."""
self._subscription_id = data["id"]
self._installed_app_id = data["installedAppId"]
self._source_type = SourceType(data["sourceType"])
if self._source_type is SourceType.CAPABILITY:
capability = data["capability"]
self._location_id = capability["locationId"]
self._capability = capability["capability"]
self._attribute = capability.get("attribute", "*")
self._value = capability.get("value", "*")
self._state_change_only = capability.get("stateChangeOnly", True)
self._subscription_name = capability.get("subscriptionName", None)
if self._source_type is SourceType.DEVICE:
device = data["device"]
self._device_id = device["deviceId"]
self._component_id = device.get("componentId", "*")
self._capability = device.get("capability", "*")
self._attribute = device.get("attribute", "*")
self._value = device.get("value", "*")
self._state_change_only = device.get("stateChangeOnly", True)
self._subscription_name = device.get("subscriptionName", None)