Collection of random test improvements (#33742)
This commit is contained in:
parent
c2a90a4f0d
commit
476072927a
11 changed files with 438 additions and 487 deletions
|
@ -1,10 +1,10 @@
|
|||
"""The tests for the Demo lock platform."""
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import lock
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_service
|
||||
from tests.common import async_mock_service
|
||||
from tests.components.lock import common
|
||||
|
||||
FRONT = "lock.front_door"
|
||||
|
@ -12,43 +12,38 @@ KITCHEN = "lock.kitchen_door"
|
|||
OPENABLE_LOCK = "lock.openable_lock"
|
||||
|
||||
|
||||
class TestLockDemo(unittest.TestCase):
|
||||
"""Test the demo lock."""
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_comp(hass):
|
||||
"""Set up demo component."""
|
||||
hass.loop.run_until_complete(
|
||||
async_setup_component(hass, lock.DOMAIN, {lock.DOMAIN: {"platform": "demo"}})
|
||||
)
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
assert setup_component(self.hass, lock.DOMAIN, {"lock": {"platform": "demo"}})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
async def test_is_locked(hass):
|
||||
"""Test if lock is locked."""
|
||||
assert lock.is_locked(hass, FRONT)
|
||||
assert hass.states.is_state(FRONT, "locked")
|
||||
|
||||
def test_is_locked(self):
|
||||
"""Test if lock is locked."""
|
||||
assert lock.is_locked(self.hass, FRONT)
|
||||
self.hass.states.is_state(FRONT, "locked")
|
||||
assert not lock.is_locked(hass, KITCHEN)
|
||||
assert hass.states.is_state(KITCHEN, "unlocked")
|
||||
|
||||
assert not lock.is_locked(self.hass, KITCHEN)
|
||||
self.hass.states.is_state(KITCHEN, "unlocked")
|
||||
|
||||
def test_locking(self):
|
||||
"""Test the locking of a lock."""
|
||||
common.lock(self.hass, KITCHEN)
|
||||
self.hass.block_till_done()
|
||||
async def test_locking(hass):
|
||||
"""Test the locking of a lock."""
|
||||
await common.async_lock(hass, KITCHEN)
|
||||
assert lock.is_locked(hass, KITCHEN)
|
||||
|
||||
assert lock.is_locked(self.hass, KITCHEN)
|
||||
|
||||
def test_unlocking(self):
|
||||
"""Test the unlocking of a lock."""
|
||||
common.unlock(self.hass, FRONT)
|
||||
self.hass.block_till_done()
|
||||
async def test_unlocking(hass):
|
||||
"""Test the unlocking of a lock."""
|
||||
await common.async_unlock(hass, FRONT)
|
||||
assert not lock.is_locked(hass, FRONT)
|
||||
|
||||
assert not lock.is_locked(self.hass, FRONT)
|
||||
|
||||
def test_opening(self):
|
||||
"""Test the opening of a lock."""
|
||||
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
||||
common.open_lock(self.hass, OPENABLE_LOCK)
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(calls)
|
||||
async def test_opening(hass):
|
||||
"""Test the opening of a lock."""
|
||||
calls = async_mock_service(hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
||||
await common.async_open_lock(hass, OPENABLE_LOCK)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue