SIENTIAPDE-988 Implement core functionality for OPC ingestor, including main execution flow, IngestorManager methods, and OPC server management. Add unit tests for IngestorManager and OPCManager.
This commit is contained in:
@@ -51,7 +51,7 @@ def opc_manager(raw_opc_manager):
|
||||
|
||||
@fixture
|
||||
def opc_manager_subscribed(opc_manager):
|
||||
opc_manager.subscription = MagicMock()
|
||||
opc_manager.subscriptions['sub1'] = MagicMock()
|
||||
|
||||
return opc_manager
|
||||
|
||||
@@ -114,7 +114,7 @@ def test_connect_with_security(client, raw_opc_manager):
|
||||
|
||||
def test_create_subscription_no_client(raw_opc_manager):
|
||||
try:
|
||||
raw_opc_manager.create_subscription()
|
||||
raw_opc_manager.create_subscription('sub1')
|
||||
except ValueError as e:
|
||||
assert str(e) == "Client not connected. Call connect first."
|
||||
else:
|
||||
@@ -122,26 +122,24 @@ def test_create_subscription_no_client(raw_opc_manager):
|
||||
|
||||
|
||||
def test_create_subscription_success_has_period(opc_manager):
|
||||
opc_manager.create_subscription(1000)
|
||||
opc_manager.create_subscription('sub1', 1000)
|
||||
|
||||
assert opc_manager.period == 1000
|
||||
opc_manager.client.create_subscription.assert_called_once_with(
|
||||
1000, opc_manager)
|
||||
assert opc_manager.subscription is not None
|
||||
assert opc_manager.subscriptions['sub1'] is not None
|
||||
|
||||
|
||||
def test_create_subscription_success_no_period(opc_manager):
|
||||
opc_manager.create_subscription(None)
|
||||
opc_manager.create_subscription('sub1', None)
|
||||
|
||||
assert opc_manager.period == 500
|
||||
opc_manager.client.create_subscription.assert_called_once_with(
|
||||
500, opc_manager)
|
||||
assert opc_manager.subscription is not None
|
||||
assert opc_manager.subscriptions['sub1'] is not None
|
||||
|
||||
|
||||
def test_subscribe_no_subscription(opc_manager):
|
||||
try:
|
||||
opc_manager.subscribe(tags, 1000)
|
||||
opc_manager.subscribe('sub1', tags, 1000)
|
||||
except ValueError as e:
|
||||
assert str(
|
||||
e) == "Subscription not created. Call create_subscription first."
|
||||
@@ -160,42 +158,45 @@ def test_subscribe_success(opc_manager_subscribed):
|
||||
opc_manager_subscribed.client.get_node(n) for n in tags if n != 'ns=3;i=1001']
|
||||
|
||||
|
||||
def test_unsubscribe_no_subscription(opc_manager):
|
||||
try:
|
||||
opc_manager.unsubscribe('sub1')
|
||||
except ValueError as e:
|
||||
assert str(
|
||||
e) == "Subscription not created. Call create_subscription first."
|
||||
else:
|
||||
assert False, "ValueError not raised"
|
||||
|
||||
|
||||
def test_unsubscribe_success(opc_manager_subscribed):
|
||||
opc_manager_subscribed.unsubscribe('sub1')
|
||||
|
||||
opc_manager_subscribed.subscriptions.get('sub1') is None
|
||||
|
||||
|
||||
def test_disconnect_success(opc_manager_subscribed):
|
||||
opc_manager_subscribed.client = MagicMock()
|
||||
opc_manager_subscribed.subscription = MagicMock()
|
||||
|
||||
opc_manager_subscribed.disconnect()
|
||||
|
||||
opc_manager_subscribed.subscription.delete.assert_called_once()
|
||||
opc_manager_subscribed.subscriptions['sub1'].delete.assert_called_once()
|
||||
opc_manager_subscribed.client.disconnect.assert_called_once()
|
||||
|
||||
|
||||
def test_disconnect_error(opc_manager_subscribed):
|
||||
opc_manager_subscribed.client = MagicMock()
|
||||
opc_manager_subscribed.subscription = MagicMock(
|
||||
opc_manager_subscribed.subscriptions['sub1'] = MagicMock(
|
||||
delete=MagicMock(side_effect=Exception("Test error"))
|
||||
)
|
||||
|
||||
opc_manager_subscribed.disconnect()
|
||||
|
||||
opc_manager_subscribed.subscription.delete.assert_called_once()
|
||||
opc_manager_subscribed.subscriptions['sub1'].delete.assert_called_once()
|
||||
opc_manager_subscribed.client.disconnect.assert_not_called()
|
||||
opc_manager_subscribed.logger.error.assert_called_once_with(
|
||||
"Failed to clean up subscription: Test error")
|
||||
|
||||
|
||||
def test_init_collector(opc_manager_subscribed):
|
||||
opc_manager_subscribed.connect = MagicMock()
|
||||
opc_manager_subscribed.create_subscription = MagicMock()
|
||||
opc_manager_subscribed.subscribe = MagicMock()
|
||||
|
||||
opc_manager_subscribed.init_collector(tags, 1000, 500)
|
||||
|
||||
opc_manager_subscribed.connect.assert_called_once()
|
||||
opc_manager_subscribed.create_subscription.assert_called_once_with(500)
|
||||
opc_manager_subscribed.subscribe.assert_called_once_with(tags, 1000)
|
||||
|
||||
|
||||
def test_datachange_notification(opc_manager_subscribed):
|
||||
data = MagicMock(
|
||||
monitored_item=MagicMock(
|
||||
|
||||
Reference in New Issue
Block a user