Skip to content

Commit 92ffb56

Browse files
gguussJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Fixes b64 types for encoding / JSON decoding (GoogleCloudPlatform#1259)
1 parent 2a35eed commit 92ffb56

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def _update_device_config(self, project_id, region, registry_id, device_id,
110110
# The data is passed as raw bytes, so you encode it as base64.
111111
# Note that the device will receive the decoded string, so you
112112
# do not need to base64 decode the string on the device.
113-
'binary_data': base64.b64encode(config_data_json)
113+
'binary_data': base64.b64encode(
114+
config_data_json.encode('utf-8')).decode('ascii')
114115
}
115116
}
116117

iot/api-client/end_to_end_example/cloudiot_pubsub_example_server_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def test_config_turn_on(capsys):
3232
max_temp = 11
33-
data = {"temperature": max_temp}
33+
data = {'temperature': max_temp}
3434

3535
Server = example_server.Server(service_account_json)
3636
Server._update_device_config(
@@ -42,11 +42,13 @@ def test_config_turn_on(capsys):
4242

4343
stdout, _ = capsys.readouterr()
4444
assert 'on' in stdout
45+
assert '11' in stdout
46+
assert 'test-device-{}' in stdout
4547

4648

4749
def test_config_turn_off(capsys):
4850
min_temp = -1
49-
data = {"temperature": min_temp}
51+
data = {'temperature': min_temp}
5052

5153
Server = example_server.Server(service_account_json)
5254
Server._update_device_config(

0 commit comments

Comments
 (0)