Browse Source

test _send_command

Fabian Peter Hammerle 4 years ago
parent
commit
0f3501e50d
1 changed files with 25 additions and 0 deletions
  1. 25 0
      switchbot_mqtt/test_switchbot.py

+ 25 - 0
switchbot_mqtt/test_switchbot.py

@@ -0,0 +1,25 @@
+import unittest.mock
+
+import pytest
+
+import switchbot_mqtt
+
+# pylint: disable=protected-access
+
+
+@pytest.mark.parametrize("mac_address", ["aa:bb:cc:dd:ee:ff"])
+@pytest.mark.parametrize(
+    "action", [switchbot_mqtt._SwitchbotAction.ON, switchbot_mqtt._SwitchbotAction.OFF]
+)
+def test__send_command(mac_address, action):
+    with unittest.mock.patch("switchbot.Switchbot") as switchbot_device_mock:
+        switchbot_device_mock.turn_on = unittest.mock.MagicMock(return_value=True)
+        switchbot_device_mock.turn_off = unittest.mock.MagicMock(return_value=True)
+        switchbot_mqtt._send_command(mac_address, action)
+    switchbot_device_mock.assert_called_once_with(mac=mac_address)
+    if action == switchbot_mqtt._SwitchbotAction.ON:
+        switchbot_device_mock().turn_on.assert_called_once_with()
+        assert not switchbot_device_mock().turn_off.called
+    else:
+        switchbot_device_mock().turn_off.assert_called_once_with()
+        assert not switchbot_device_mock().turn_on.called