test_switchbot.py 1004 B

12345678910111213141516171819202122232425
  1. import unittest.mock
  2. import pytest
  3. import switchbot_mqtt
  4. # pylint: disable=protected-access
  5. @pytest.mark.parametrize("mac_address", ["aa:bb:cc:dd:ee:ff"])
  6. @pytest.mark.parametrize(
  7. "action", [switchbot_mqtt._SwitchbotAction.ON, switchbot_mqtt._SwitchbotAction.OFF]
  8. )
  9. def test__send_command(mac_address, action):
  10. with unittest.mock.patch("switchbot.Switchbot") as switchbot_device_mock:
  11. switchbot_device_mock.turn_on = unittest.mock.MagicMock(return_value=True)
  12. switchbot_device_mock.turn_off = unittest.mock.MagicMock(return_value=True)
  13. switchbot_mqtt._send_command(mac_address, action)
  14. switchbot_device_mock.assert_called_once_with(mac=mac_address)
  15. if action == switchbot_mqtt._SwitchbotAction.ON:
  16. switchbot_device_mock().turn_on.assert_called_once_with()
  17. assert not switchbot_device_mock().turn_off.called
  18. else:
  19. switchbot_device_mock().turn_off.assert_called_once_with()
  20. assert not switchbot_device_mock().turn_on.called