Skip to content

Commit 1acf61b

Browse files
committed
Merge pull request #50 in PYTHON/python-devicecloud from ming/add-attribute-to-sci-send-message-operation to master
* commit '65eaac5934392c35ad86d513d0e71fcca2ad8212': Added test_sci_update_firmware_attribute test for testing attribute parameter in send_sci function ADded attribute to send sci operaton tag
2 parents 3252968 + 65eaac5 commit 1acf61b

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

devicecloud/sci.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
SCI_TEMPLATE = """\
1414
<sci_request version="1.0">
15-
<{operation}{reply}{synchronous}{cache}{sync_timeout}{allow_offline}{wait_for_reconnect}>
15+
<{operation}{attribute}{reply}{synchronous}{cache}{sync_timeout}{allow_offline}{wait_for_reconnect}>
1616
<targets>
1717
{targets}
1818
</targets>
@@ -131,7 +131,7 @@ def send_sci_async(self, operation, target, payload, **sci_options):
131131
return AsyncRequestProxy(job_id, self._conn)
132132

133133
def send_sci(self, operation, target, payload, reply=None, synchronous=None, sync_timeout=None,
134-
cache=None, allow_offline=None, wait_for_reconnect=None):
134+
cache=None, allow_offline=None, wait_for_reconnect=None, attribute=None):
135135
"""Send SCI request to 1 or more targets
136136
137137
:param str operation: The operation is one of {send_message, update_firmware, disconnect, query_firmware_targets,
@@ -204,6 +204,11 @@ def send_sci(self, operation, target, payload, reply=None, synchronous=None, syn
204204
else:
205205
wait_for_reconnect_xml = ''
206206

207+
if attribute is not None:
208+
operation_attribute = ' ' + attribute
209+
else:
210+
operation_attribute = ''
211+
207212
full_request = SCI_TEMPLATE.format(
208213
operation=operation,
209214
targets=targets_xml,
@@ -213,7 +218,8 @@ def send_sci(self, operation, target, payload, reply=None, synchronous=None, syn
213218
cache=cache_xml,
214219
allow_offline=allow_offline_xml,
215220
wait_for_reconnect=wait_for_reconnect_xml,
216-
payload=payload
221+
payload=payload,
222+
attribute=operation_attribute
217223
)
218224

219225
# TODO: do parsing here?

devicecloud/test/unit/test_sci.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
</sci_reply>
7575
"""
7676

77+
EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_REQUEST_PAYLOAD = """
78+
<data>aHNxcAbAADUct1cAAACAHEBAAAEABEAwAIBAAQAAACOFFzU</data>
79+
"""
80+
81+
EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_RESPONSE = """\
82+
<sci_reply version="1.0"><update_firmware><device id="00000000-00000000-00409dff-ffaabbcc"/>
83+
<error><desc>Default target not availabe, specify a target number of filename</desc></error>
84+
</device></update_firmware>
85+
</sci_reply>
86+
"""
7787

7888
class TestSCI(HttpTestBase):
7989
def _prepare_sci_response(self, response, status=200):
@@ -179,6 +189,27 @@ def test_sci_with_parameters(self):
179189
'</send_message>'
180190
'</sci_request>'))
181191

192+
def test_sci_update_firmware_attribute(self):
193+
194+
self._prepare_sci_response(EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_RESPONSE)
195+
self.dc.get_sci_api().send_sci(
196+
operation="update_firmware",
197+
attribute="filename=\"abcd.bin\"",
198+
target=DeviceTarget('00000000-00000000-00409dff-ffaabbcc'),
199+
payload=EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_REQUEST_PAYLOAD)
200+
201+
request = httpretty.last_request().body.decode('utf8')
202+
request = ''.join([line.strip() for line in request.splitlines()])
203+
self.assertEqual(request,
204+
six.u('<sci_request version="1.0">'
205+
'<update_firmware filename="abcd.bin">'
206+
'<targets>'
207+
'<device id="00000000-00000000-00409dff-ffaabbcc"/>'
208+
'</targets>'
209+
'<data>aHNxcAbAADUct1cAAACAHEBAAAEABEAwAIBAAQAAACOFFzU</data>'
210+
'</update_firmware>'
211+
'</sci_request>'))
212+
182213

183214
class TestGetAsync(HttpTestBase):
184215
def test_sci_get_async(self):

devicecloud/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# Copyright (c) 2015-2018 Digi International Inc.
66

77

8-
__version__ = "0.5.3"
8+
__version__ = "0.5.4"

0 commit comments

Comments
 (0)