|
| 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) |
0 commit comments