hass-core/tests/components/rollershutter/test_command_line.py
Rob Capellini 4891ca1610 Removing calls to mock.assert_called_once_with (#3896)
If a mock's assert_called_once_with method is misspelled (e.g. asert_called_once_with) then the test will appear as passing.  Therefore, this commit removes all instances of assert_called_once_with calls and replaces them with two assertions:

        self.assertEqual(mock.call_count, 1)
        self.assertEqual(mock.call_args, mock.call(call_args))
2016-10-16 16:13:27 -07:00

88 lines
3.3 KiB
Python

"""The tests the Roller shutter command line platform."""
import os
import tempfile
import unittest
from unittest import mock
from homeassistant.bootstrap import setup_component
import homeassistant.components.rollershutter as rollershutter
from homeassistant.components.rollershutter import (
command_line as cmd_rs)
from tests.common import get_test_home_assistant
class TestCommandRollerShutter(unittest.TestCase):
"""Test the Roller shutter command line platform."""
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.rs = cmd_rs.CommandRollershutter(self.hass, 'foo',
'cmd_up', 'cmd_dn',
'cmd_stop', 'cmd_state',
None) # FIXME
def teardown_method(self, method):
"""Stop down everything that was started."""
self.hass.stop()
def test_should_poll(self):
"""Test the setting of polling."""
self.assertTrue(self.rs.should_poll)
self.rs._command_state = None
self.assertFalse(self.rs.should_poll)
def test_query_state_value(self):
"""Test with state value."""
with mock.patch('subprocess.check_output') as mock_run:
mock_run.return_value = b' foo bar '
result = self.rs._query_state_value('runme')
self.assertEqual('foo bar', result)
self.assertEqual(mock_run.call_count, 1)
self.assertEqual(
mock_run.call_args, mock.call('runme', shell=True)
)
def test_state_value(self):
"""Test with state value."""
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'rollershutter_status')
test_rollershutter = {
'statecmd': 'cat {}'.format(path),
'upcmd': 'echo 1 > {}'.format(path),
'downcmd': 'echo 1 > {}'.format(path),
'stopcmd': 'echo 0 > {}'.format(path),
'value_template': '{{ value }}'
}
self.assertTrue(setup_component(self.hass, rollershutter.DOMAIN, {
'rollershutter': {
'platform': 'command_line',
'rollershutters': {
'test': test_rollershutter
}
}
}))
state = self.hass.states.get('rollershutter.test')
self.assertEqual('unknown', state.state)
rollershutter.move_up(self.hass, 'rollershutter.test')
self.hass.block_till_done()
state = self.hass.states.get('rollershutter.test')
self.assertEqual('open', state.state)
rollershutter.move_down(self.hass, 'rollershutter.test')
self.hass.block_till_done()
state = self.hass.states.get('rollershutter.test')
self.assertEqual('open', state.state)
rollershutter.stop(self.hass, 'rollershutter.test')
self.hass.block_till_done()
state = self.hass.states.get('rollershutter.test')
self.assertEqual('closed', state.state)