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
0
Merge Requests
0
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
Martin Manchev
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
Hide 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,36 +20,40 @@ def convertNodeValue(node_id, node_value):
return
node_value
# 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
:
context
.
opcua_document_module
.
newContent
(
portal_type
=
"OPCUA Document"
,
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"
,
id
=
default_id
)
# do selection of o
ep
ration in a REST fashion based in HTTP method
http_method
=
context
.
REQUEST
.
method
context
.
log
(
http_method
)
# do selection of o
pe
ration in a REST fashion based in HTTP method
if
http_method
is
None
:
http_method
=
context
.
REQUEST
.
method
if
http_method
==
"GET"
:
# assume read request, return what was saved.
return
json
.
dumps
(
default_opcua_document
.
getNodeDict
())
elif
http_method
==
"POST"
:
# assume write request
try
:
data
=
context
.
REQUEST
.
data
except
AttributeError
as
e
:
log
(
"Warning: 'data' is missing from request."
)
raise
e
else
:
data
=
json
.
loads
(
data
)
if
'node'
in
data
.
keys
():
# log only set requests for now
node_id
=
data
[
'node'
]
node_value
=
data
[
'val'
]
# set to "ERP5 OPCUA Document" but only if it's not a None value
if
node_value
is
not
None
and
node_value
!=
"None"
:
log
(
"Set '%s' = '%s' to %s as %s"
%
(
node_id
,
node_value
,
default_opcua_document
,
node_id
))
node_dict
=
default_opcua_document
.
getNodeDict
()
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
default_opcua_document
.
setNodeDict
(
node_dict
)
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
if
data
is
None
:
try
:
data
=
context
.
REQUEST
.
data
except
AttributeError
as
e
:
log
(
"Warning: 'data' is missing from request."
)
raise
e
data
=
json
.
loads
(
data
)
if
'node'
in
data
.
keys
():
# log only set requests for now
node_id
=
data
[
'node'
]
node_value
=
data
[
'val'
]
# set to "ERP5 OPCUA Document" but only if it's not a None value
if
node_value
is
not
None
and
node_value
!=
"None"
:
log
(
"Set '%s' = '%s' to %s as %s"
%
(
node_id
,
node_value
,
default_opcua_document
,
node_id
))
node_dict
=
default_opcua_document
.
getNodeDict
()
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
default_opcua_document
.
setNodeDict
(
node_dict
)
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 @@
</item>
<item>
<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>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_opcua/TestTemplateItem/portal_components/test.erp5.testOPCUADocument.py
View file @
5d030d5e
...
...
@@ -24,7 +24,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
json
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
class
TestDataInestOPCUADocumentgestion
(
ERP5TypeTestCase
):
...
...
@@ -36,10 +36,35 @@ class TestDataInestOPCUADocumentgestion(ERP5TypeTestCase):
def
getTitle
(
self
):
return
"OPC UA Document"
def
test_01_SetAndGet
(
self
):
"""
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