Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
osie
Commits
5d030d5e
Commit
5d030d5e
authored
Aug 30, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add testing adn adjust API.
parent
eac96b40
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
28 deletions
+57
-28
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
...em/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
+28
-24
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.xml
...m/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.xml
+1
-1
bt5/erp5_opcua/TestTemplateItem/portal_components/test.erp5.testOPCUADocument.py
...lateItem/portal_components/test.erp5.testOPCUADocument.py
+28
-3
No files found.
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
View file @
5d030d5e
...
@@ -20,27 +20,29 @@ def convertNodeValue(node_id, node_value):
...
@@ -20,27 +20,29 @@ def convertNodeValue(node_id, node_value):
return
node_value
return
node_value
# XXX: what should be the OPCUA container?
# XXX: what should be the OPCUA container?
default_id
=
"1"
default_opcua_document
=
context
.
opcua_document_module
.
get
(
default_id
,
None
)
if
default_opcua_document
is
None
:
if
default_opcua_document
is
None
:
default_id
=
"1"
default_opcua_document
=
context
.
opcua_document_module
.
get
(
default_id
,
None
)
if
default_opcua_document
is
None
:
context
.
opcua_document_module
.
newContent
(
portal_type
=
"OPCUA Document"
,
context
.
opcua_document_module
.
newContent
(
portal_type
=
"OPCUA Document"
,
id
=
default_id
)
id
=
default_id
)
# do selection of o
ep
ration in a REST fashion based in HTTP method
# do selection of o
pe
ration in a REST fashion based in HTTP method
http_method
=
context
.
REQUEST
.
method
if
http_method
is
None
:
context
.
log
(
http_method
)
http_method
=
context
.
REQUEST
.
method
if
http_method
==
"GET"
:
if
http_method
==
"GET"
:
# assume read request, return what was saved.
# assume read request, return what was saved.
return
json
.
dumps
(
default_opcua_document
.
getNodeDict
())
return
json
.
dumps
(
default_opcua_document
.
getNodeDict
())
elif
http_method
==
"POST"
:
elif
http_method
==
"POST"
:
# assume write request
# assume write request
if
data
is
None
:
try
:
try
:
data
=
context
.
REQUEST
.
data
data
=
context
.
REQUEST
.
data
except
AttributeError
as
e
:
except
AttributeError
as
e
:
log
(
"Warning: 'data' is missing from request."
)
log
(
"Warning: 'data' is missing from request."
)
raise
e
raise
e
else
:
data
=
json
.
loads
(
data
)
data
=
json
.
loads
(
data
)
if
'node'
in
data
.
keys
():
if
'node'
in
data
.
keys
():
# log only set requests for now
# log only set requests for now
...
@@ -53,3 +55,5 @@ elif http_method == "POST":
...
@@ -53,3 +55,5 @@ elif http_method == "POST":
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
default_opcua_document
.
setNodeDict
(
node_dict
)
default_opcua_document
.
setNodeDict
(
node_dict
)
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
return
json
.
dumps
(
default_opcua_document
.
getNodeDict
())
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.xml
View file @
5d030d5e
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
_params
</string>
</key>
<key>
<string>
_params
</string>
</key>
<value>
<string>
*args, **kwargs
</string>
</value>
<value>
<string>
http_method=None, default_opcua_document=None, data=None,
*args, **kwargs
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
id
</string>
</key>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_opcua/TestTemplateItem/portal_components/test.erp5.testOPCUADocument.py
View file @
5d030d5e
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
##############################################################################
##############################################################################
import
json
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
class
TestDataInestOPCUADocumentgestion
(
ERP5TypeTestCase
):
class
TestDataInestOPCUADocumentgestion
(
ERP5TypeTestCase
):
...
@@ -36,10 +36,35 @@ class TestDataInestOPCUADocumentgestion(ERP5TypeTestCase):
...
@@ -36,10 +36,35 @@ class TestDataInestOPCUADocumentgestion(ERP5TypeTestCase):
def
getTitle
(
self
):
def
getTitle
(
self
):
return
"OPC UA Document"
return
"OPC UA Document"
def
test_01_SetAndGet
(
self
):
def
test_01_SetAndGet
(
self
):
"""
"""
XXX: implement accordingly
XXX: implement accordingly
"""
"""
self
.
assertEqual
(
1
,
1
)
# create placeholder
default_id
=
"1"
default_opcua_document
=
self
.
portal
.
opcua_document_module
.
get
(
default_id
,
None
)
if
default_opcua_document
is
None
:
self
.
portal
.
opcua_document_module
.
newContent
(
portal_type
=
"OPCUA Document"
,
id
=
default_id
)
self
.
tic
()
# cleanup
default_opcua_document
.
setNodeDict
({})
self
.
tic
()
# test HTTP GET returns empy dict
result_dict
=
self
.
portal
.
ERP5Site_handleOPCUARequest
(
http_method
=
"GET"
,
default_opcua_document
=
default_opcua_document
)
self
.
assertEqual
(
json
.
dumps
({}),
result_dict
)
# test setting over a client
node_id
=
"n1=1;i=810"
node_val
=
10
opcua_structure
=
{
"node"
:
node_id
,
"val"
:
node_val
}
result_json
=
self
.
portal
.
ERP5Site_handleOPCUARequest
(
http_method
=
"POST"
,
default_opcua_document
=
default_opcua_document
,
data
=
json
.
dumps
(
opcua_structure
))
# convert from JSON string to dict
result_dict
=
json
.
loads
(
result_json
)
self
.
assertEqual
({
node_id
:
node_val
},
result_dict
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment