mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Rewrite sigfox unittest tests to pytest (#41302)
This commit is contained in:
parent
e303064f75
commit
3abf30cf42
@ -1,6 +1,5 @@
|
|||||||
"""Tests for the sigfox sensor."""
|
"""Tests for the sigfox sensor."""
|
||||||
import re
|
import re
|
||||||
import unittest
|
|
||||||
|
|
||||||
import requests_mock
|
import requests_mock
|
||||||
|
|
||||||
@ -9,9 +8,7 @@ from homeassistant.components.sigfox.sensor import (
|
|||||||
CONF_API_LOGIN,
|
CONF_API_LOGIN,
|
||||||
CONF_API_PASSWORD,
|
CONF_API_PASSWORD,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
TEST_API_LOGIN = "foo"
|
TEST_API_LOGIN = "foo"
|
||||||
TEST_API_PASSWORD = "ebcd1234"
|
TEST_API_PASSWORD = "ebcd1234"
|
||||||
@ -33,24 +30,17 @@ VALID_MESSAGE = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TestSigfoxSensor(unittest.TestCase):
|
async def test_invalid_credentials(hass):
|
||||||
"""Test the sigfox platform."""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Initialize values for this testcase class."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
self.addCleanup(self.hass.stop)
|
|
||||||
|
|
||||||
def test_invalid_credentials(self):
|
|
||||||
"""Test for invalid credentials."""
|
"""Test for invalid credentials."""
|
||||||
with requests_mock.Mocker() as mock_req:
|
with requests_mock.Mocker() as mock_req:
|
||||||
url = re.compile(API_URL + "devicetypes")
|
url = re.compile(API_URL + "devicetypes")
|
||||||
mock_req.get(url, text="{}", status_code=401)
|
mock_req.get(url, text="{}", status_code=401)
|
||||||
assert setup_component(self.hass, "sensor", VALID_CONFIG)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(self.hass.states.entity_ids()) == 0
|
assert len(hass.states.async_entity_ids()) == 0
|
||||||
|
|
||||||
def test_valid_credentials(self):
|
|
||||||
|
async def test_valid_credentials(hass):
|
||||||
"""Test for valid credentials."""
|
"""Test for valid credentials."""
|
||||||
with requests_mock.Mocker() as mock_req:
|
with requests_mock.Mocker() as mock_req:
|
||||||
url1 = re.compile(API_URL + "devicetypes")
|
url1 = re.compile(API_URL + "devicetypes")
|
||||||
@ -62,10 +52,10 @@ class TestSigfoxSensor(unittest.TestCase):
|
|||||||
url3 = re.compile(API_URL + "devices/fake_id/messages*")
|
url3 = re.compile(API_URL + "devices/fake_id/messages*")
|
||||||
mock_req.get(url3, text=VALID_MESSAGE)
|
mock_req.get(url3, text=VALID_MESSAGE)
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", VALID_CONFIG)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(self.hass.states.entity_ids()) == 1
|
assert len(hass.states.async_entity_ids()) == 1
|
||||||
state = self.hass.states.get("sensor.sigfox_fake_id")
|
state = hass.states.get("sensor.sigfox_fake_id")
|
||||||
assert state.state == "payload"
|
assert state.state == "payload"
|
||||||
assert state.attributes.get("snr") == "50.0"
|
assert state.attributes.get("snr") == "50.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user