65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
from ingestor.io.slots import parse_slot
|
|
|
|
RAW = {
|
|
'server1': {
|
|
'server_id': '1',
|
|
'url': 'opc.tcp://h:4840',
|
|
'use_security': True,
|
|
'subscription_period_ms': 1000,
|
|
'tags': {
|
|
'ns=2;i=2': {
|
|
'frequency': '15000',
|
|
'active_read': {'enabled': True, 'cycle_multiple': 3},
|
|
'names': [
|
|
{
|
|
'collection': 'raw_x',
|
|
'tag_name': 'Counter',
|
|
'model_name': 'm1',
|
|
'model_id': '1',
|
|
},
|
|
{
|
|
'collection': 'raw_y',
|
|
'tag_name': 'Contador',
|
|
'model_name': 'm2',
|
|
'model_id': '2',
|
|
},
|
|
],
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
def test_parse_slot_multi_name():
|
|
slot = parse_slot(RAW)
|
|
tag = slot['server1']['tags']['ns=2;i=2']
|
|
assert len(tag['names']) == 2
|
|
assert tag['active_read']['cycle_multiple'] == 3
|
|
|
|
|
|
def test_parse_slot_defaults_active_read_disabled():
|
|
raw = {
|
|
's': {
|
|
'server_id': '1',
|
|
'url': 'u',
|
|
'tags': {
|
|
'ns=2;i=1': {
|
|
'frequency': '1000',
|
|
'names': [
|
|
{'collection': 'c', 'tag_name': 't', 'model_name': 'm', 'model_id': '1'}
|
|
],
|
|
}
|
|
},
|
|
}
|
|
}
|
|
tag = parse_slot(raw)['s']['tags']['ns=2;i=1']
|
|
assert tag['active_read'] == {'enabled': False}
|
|
|
|
|
|
def test_parse_slot_rejects_tag_without_names():
|
|
raw = {'s': {'server_id': '1', 'url': 'u', 'tags': {'ns=2;i=1': {'frequency': '1000'}}}}
|
|
import pytest
|
|
|
|
with pytest.raises((KeyError, ValueError)):
|
|
parse_slot(raw)
|