8000 Adds Gateways codelab (Python) (#2049) · cseed/python-docs-samples@4c764f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c764f4

Browse files
authored
Adds Gateways codelab (Python) (GoogleCloudPlatform#2049)
* Adds codelab for Gateway
1 parent 695595a commit 4c764f4

File tree

12 files changed

+955
-0
lines changed

12 files changed

+955
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2019 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from colors import bcolors
15+
import gateway
16+
import ledlight
17+
import lightsensor
18+
import thermostat
19+
20+
21+
# Check colors exist
22+
def test_check_colors(capsys):
23+
assert(bcolors.OKBLUE is not None)
24+
assert(bcolors.FAIL is not None)
25+
assert(bcolors.CEND is not None)
26+
27+
28+
# Check error code returns reasonable justifications
29+
def test_gateway_error_string(capsys):
30+
print(gateway.error_str(1))
31+
print(gateway.error_str(2))
32+
print(gateway.error_str(3))
33+
print(gateway.error_str(4))
34+
out, _ = capsys.readouterr()
35+
36+
assert 'memory' in out
37+
assert 'network' in out
38+
assert 'function arguments' in out
39+
assert 'currently connected' in out
40+
41+
42+
# Check gateway state is init to reasonable defaults
43+
def test_gateway_state(capsys):
44+
assert (gateway.GatewayState.mqtt_config_topic == '')
45+
assert (gateway.GatewayState.connected is False)
46+
assert (gateway.GatewayState.pending_responses == {})
47+
assert (gateway.GatewayState.pending_subscribes == {})
48+
assert (gateway.GatewayState.mqtt_bridge_port == 8883 or
49+
gateway.GatewayState.mqtt_bridge_ == 443)
50+
51+
52+
def test_check_ledlight(capsys):
53+
print(ledlight.make_message('test', 'action', data='1234'))
54+
out, _ = capsys.readouterr()
55+
56+
assert ('{ "device" : "test"' in out)
57+
58+
59+
def test_check_lightsensor(capsys):
60+
print(lightsensor.print_sensor_state())
61+
out, _ = capsys.readouterr()
62+
63+
assert ('Sensor is on, reporting lux every 1 seconds.' in out)
64+
65+
66+
def test_check_thermostat(capsys):
67+
print(thermostat.make_message('test', 'action', data='1234'))
68+
out, _ = capsys.readouterr()
69+
70+
assert ('{ "device" : "test"' in out)

iot/api-client/codelabs/colors.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2019 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
class bcolors:
17+
HEADER = '\033[95m'
18+
OKBLUE = '\033[94m'
19+
OKGREEN = '\033[92m'
20+
WARNING = '\033[93m'
21+
FAIL = '\033[91m'
22+
ENDC = '\033[0m'
23+
BOLD = '\033[1m'
24+
UNDERLINE = '\033[4m'
25+
26+
CEND = '\33[0m'
27+
CBOLD = '\33[1m'
28+
CITALIC = '\33[3m'
29+
CURL = '\33[4m'
30+
CBLINK = '\33[5m'
31+
CBLINK2 = '\33[6m'
32+
CSELECTED = '\33[7m'
33+
34+
CBLACK = '\33[30m'
35+
CRED = '\33[31m'
36+
CGREEN = '\33[32m'
37+
CYELLOW = '\33[33m'
38+
CBLUE = '\33[34m'
39+
CVIOLET = '\33[35m'
40+
CBEIGE = '\33[36m'
41+
CWHITE = '\33[37m'
42+
43+
CBLACKBG = '\33[40m'
44+
CREDBG = '\33[41m'
45+
CGREENBG = '\33[42m'
46+
CYELLOWBG = '\33[43m'
47+
CBLUEBG = '\33[44m'
48+
CVIOLETBG = '\33[45m'
49+
CBEIGEBG = '\33[46m'
50+
CWHITEBG = '\33[47m'
51+
52+
CGREY = '\33[90m'
53+
CRED2 = '\33[91m'
54+
CGREEN2 = '\33[92m'
55+
CYELLOW2 = '\33[93m'
56+
CBLUE2 = '\33[94m'
57+
CVIOLET2 = '\33[95m'
58+
CBEIGE2 = '\33[96m'
59+
CWHITE2 = '\33[97m'
60+
61+
CGREYBG = '\33[100m'
62+
CREDBG2 = '\33[101m'
63+
CGREENBG2 = '\33[102m'
64+
CYELLOWBG2 = '\33[103m'
65+
CBLUEBG2 = '\33[104m'
66+
CVIOLETBG2 = '\33[105m'
67+
CBEIGEBG2 = '\33[106m'
68+
CWHITEBG2 = '\33[107m'

0 commit comments

Comments
 (0)
0