From 9919baad27f46bc1ea59f761c5bad4a7c765df1d Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Sat, 16 Feb 2019 02:54:39 -0500 Subject: [PATCH] more tests --- sucks/__init__.py | 2 +- tests/test_commands.py | 5 +++++ tests/test_ecovacs_mqtt.py | 11 ++++++++++- tests/test_ecovacs_xmpp.py | 3 +-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sucks/__init__.py b/sucks/__init__.py index 3f37169..7c17979 100644 --- a/sucks/__init__.py +++ b/sucks/__init__.py @@ -1018,7 +1018,7 @@ class VacBotCommand: class Clean(VacBotCommand): def __init__(self, mode='auto', speed='normal', iot=False, action='start',terminal=False, **kwargs): - if kwargs is None: + if kwargs == {}: if not iot: super().__init__('Clean', {'clean': {'type': CLEAN_MODE_TO_ECOVACS[mode], 'speed': FAN_SPEED_TO_ECOVACS[speed]}}) else: diff --git a/tests/test_commands.py b/tests/test_commands.py index d0ffd7b..63f4ae2 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -44,9 +44,14 @@ def test_clean_command(): c = Clean() assert_equals(ElementTree.tostring(c.to_xml()), b'') # protocol has attribs in other order + c = Clean('edge', 'high') assert_equals(ElementTree.tostring(c.to_xml()), b'') # protocol has attribs in other order + + c = Clean(iot=True) + assert_equals(ElementTree.tostring(c.to_xml()), + b'') # test for iot act is added def test_spotarea_command(): diff --git a/tests/test_ecovacs_mqtt.py b/tests/test_ecovacs_mqtt.py index 8c567a4..e750118 100644 --- a/tests/test_ecovacs_mqtt.py +++ b/tests/test_ecovacs_mqtt.py @@ -71,15 +71,24 @@ def test_xml_to_dict(): x._ctl_to_dict(test_topic, ""), {'event': 'map_st', 'ts':'1547823592934', 'st':'reloc_go_chg_start', 'method':'', 'info':''}) + # #TODO: Find a way to check if string is b64 encoded # test_topic = 'iot/atr/trace/%s/%s/%s/x'.format(x.vacuum['did'], x.vacuum['class'], x.vacuum['resource']) # assert_dict_equal( # x._ctl_to_dict(test_topic, ""), # {'event': 'trace', 'trid':'227975', 'tf':'4', 'tr':'XQAABAAKAAAAAB4AMGAQCdAAAAA='}) +def test_bad_port(): + bot = {"did": "E0000000001234567890", "class": "126","resource":"test_resource", "nick": "bob", "iot": True} + mqtt = EcoVacsMQTT('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na', bot, server_address='test.com:f123') + assert_equal(8883, mqtt.port) +def test_good_port(): + bot = {"did": "E0000000001234567890", "class": "126","resource":"test_resource", "nick": "bob", "iot": True} + mqtt = EcoVacsMQTT('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na', bot, server_address='test.com:8000') + assert_equal(8000, mqtt.port) def make_ecovacs_mqtt(bot=None): if bot is None: - bot = bot = {"did": "E0000000001234567890", "class": "126","resource":"test_resource", "nick": "bob", "iot": True} + bot = {"did": "E0000000001234567890", "class": "126","resource":"test_resource", "nick": "bob", "iot": True} return EcoVacsMQTT('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na', bot) diff --git a/tests/test_ecovacs_xmpp.py b/tests/test_ecovacs_xmpp.py index cdfc3c7..b76aebf 100644 --- a/tests/test_ecovacs_xmpp.py +++ b/tests/test_ecovacs_xmpp.py @@ -14,7 +14,6 @@ def test_wrap_command(): assert_true(search(r'from="20170101abcdefabcdefa@ecouser.net/abcdef12"', c)) assert_true(search(r'to="E0000000001234567890@126.ecorobot.net/atom"', c)) - def test_subscribe_to_ctls(): response = None @@ -58,7 +57,7 @@ def test_xml_to_dict(): def make_ecovacs_xmpp(bot=None): if bot is None: - bot = bot = {"did": "E0000000001234567890", "class": "126", "nick": "bob", "iot": False} + bot = {"did": "E0000000001234567890", "class": "126", "nick": "bob", "iot": False} return EcoVacsXMPP('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na', bot)