2 Test an OPC-UA server with freeopcua python client 7 from concurrent.futures
import Future
8 from datetime
import datetime
9 from datetime
import timedelta
13 from opcua
import Client
19 More advanced subscription client using Future, so we can wait for events in tests 29 self.future.set_result((node, val, data))
32 self.future.set_result(event)
40 self.results.append((node, val))
43 self.results.append(event)
66 c.set_security_string(
"basic256,sign,XXXX")
72 res = c.connect_and_find_servers()
73 self.assertTrue(len(res) > 0)
77 res = c.connect_and_get_server_endpoints()
78 self.assertTrue(len(res) > 0)
82 root = client.get_root_node()
83 self.assertEqual(root.get_browse_name(), ua.QualifiedName(
"Root", 0))
87 root = client.get_root_node()
88 childs = root.get_children()
89 self.assertTrue(len(childs) > 2)
93 array = client.get_namespace_array()
94 self.assertTrue(len(array) > 0)
98 srv = client.get_server_node()
99 self.assertEqual(srv.get_browse_name(), ua.QualifiedName(
"Server", 0))
105 root = client.get_root_node()
106 node = root.get_child([
"0:Objects",
"0:Server" ,
"0:ServerArray"])
107 self.assertEqual(node.get_browse_name(), ua.QualifiedName(
"ServerArray", 0))
113 server_time_node = client.get_node(ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
114 sub = client.create_subscription(200, msclt)
115 handle = sub.subscribe_data_change(server_time_node)
117 node, val, data = msclt.future.result()
118 self.assertEqual(node, server_time_node)
119 delta = datetime.utcnow() - val
120 print(
"Timedelta is ", delta)
123 sub.unsubscribe(handle)
127 if __name__ ==
"__main__":
129 logging.basicConfig(level=logging.WARN)
132 if len(sys.argv) < 2:
133 print(
"This script is meant to test compatibilty to a server with freeopcua python client library")
134 print(
"Usage: test_server.py url")
139 unittest.main(verbosity=30, argv=sys.argv[:1])
def test_get_root(self, client)
def test_subscribe_server_time(self, client)
def test_find_endpoints(self)
def test_get_namespace_array(self, client)
def test_get_server_node(self, client)
def test_get_root_children(self, client)
def test_browsepathtonodeid(self, client)
def datachange_notification(self, node, val, data)
def event_notification(self, event)
def test_connect_anonymous(self)
def test_find_servers(self)
def func(parent, variant)
def event_notification(self, event)
def datachange_notification(self, node, val, data)
def FINISH_test_connect_basic256(self)