This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+21 -26
View File
@@ -12,23 +12,20 @@ from tests.common import load_fixture, get_test_home_assistant
def mock_responses(mock, single=False):
"""Mock responses for SleepIQ."""
base_url = 'https://prod-api.sleepiq.sleepnumber.com/rest/'
base_url = "https://prod-api.sleepiq.sleepnumber.com/rest/"
if single:
suffix = '-single'
suffix = "-single"
else:
suffix = ''
mock.put(
base_url + 'login',
text=load_fixture('sleepiq-login.json'))
suffix = ""
mock.put(base_url + "login", text=load_fixture("sleepiq-login.json"))
mock.get(
base_url + 'bed?_k=0987',
text=load_fixture('sleepiq-bed{}.json'.format(suffix)))
base_url + "bed?_k=0987", text=load_fixture("sleepiq-bed{}.json".format(suffix))
)
mock.get(base_url + "sleeper?_k=0987", text=load_fixture("sleepiq-sleeper.json"))
mock.get(
base_url + 'sleeper?_k=0987',
text=load_fixture('sleepiq-sleeper.json'))
mock.get(
base_url + 'bed/familyStatus?_k=0987',
text=load_fixture('sleepiq-familystatus{}.json'.format(suffix)))
base_url + "bed/familyStatus?_k=0987",
text=load_fixture("sleepiq-familystatus{}.json".format(suffix)),
)
class TestSleepIQ(unittest.TestCase):
@@ -37,13 +34,10 @@ class TestSleepIQ(unittest.TestCase):
def setUp(self):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.username = 'foo'
self.password = 'bar'
self.username = "foo"
self.password = "bar"
self.config = {
'sleepiq': {
'username': self.username,
'password': self.password,
}
"sleepiq": {"username": self.username, "password": self.password}
}
def tearDown(self): # pylint: disable=invalid-name
@@ -58,16 +52,17 @@ class TestSleepIQ(unittest.TestCase):
# We're mocking the load_platform discoveries or else the platforms
# will be setup during tear down when blocking till done, but the mocks
# are no longer active.
with patch(
'homeassistant.helpers.discovery.load_platform', MagicMock()):
with patch("homeassistant.helpers.discovery.load_platform", MagicMock()):
assert sleepiq.setup(self.hass, self.config)
@requests_mock.Mocker()
def test_setup_login_failed(self, mock):
"""Test the setup if a bad username or password is given."""
mock.put('https://prod-api.sleepiq.sleepnumber.com/rest/login',
status_code=401,
json=load_fixture('sleepiq-login-failed.json'))
mock.put(
"https://prod-api.sleepiq.sleepnumber.com/rest/login",
status_code=401,
json=load_fixture("sleepiq-login-failed.json"),
)
response = sleepiq.setup(self.hass, self.config)
assert not response
@@ -75,12 +70,12 @@ class TestSleepIQ(unittest.TestCase):
def test_setup_component_no_login(self):
"""Test the setup when no login is configured."""
conf = self.config.copy()
del conf['sleepiq']['username']
del conf["sleepiq"]["username"]
assert not setup.setup_component(self.hass, sleepiq.DOMAIN, conf)
def test_setup_component_no_password(self):
"""Test the setup when no password is configured."""
conf = self.config.copy()
del conf['sleepiq']['password']
del conf["sleepiq"]["password"]
assert not setup.setup_component(self.hass, sleepiq.DOMAIN, conf)