Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PyJWT==1.7.1
PyNaCl==1.3.0
aiohttp==3.5.4
aiohttp==3.6.0
aiohttp_cors==0.7.0
astral==1.10.1
async_timeout==3.0.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Home Assistant core
aiohttp==3.5.4
aiohttp==3.6.0
astral==1.10.1
async_timeout==3.0.1
attrs==19.1.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
PACKAGES = find_packages(exclude=["tests", "tests.*"])

REQUIRES = [
"aiohttp==3.5.4",
"aiohttp==3.6.0",
"astral==1.10.1",
"async_timeout==3.0.1",
"attrs==19.1.0",
Expand Down
25 changes: 20 additions & 5 deletions tests/components/smartthings/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ async def test_token_unauthorized(hass, smartthings_mock):
flow = SmartThingsFlowHandler()
flow.hass = hass

smartthings_mock.apps.side_effect = ClientResponseError(None, None, status=401)
request_info = Mock(real_url="http://example.com")
smartthings_mock.apps.side_effect = ClientResponseError(
request_info=request_info, history=None, status=401
)

result = await flow.async_step_user({"access_token": str(uuid4())})

Expand All @@ -98,7 +101,10 @@ async def test_token_forbidden(hass, smartthings_mock):
flow = SmartThingsFlowHandler()
flow.hass = hass

smartthings_mock.apps.side_effect = ClientResponseError(None, None, status=403)
request_info = Mock(real_url="http://example.com")
smartthings_mock.apps.side_effect = ClientResponseError(
request_info=request_info, history=None, status=403
)

result = await flow.async_step_user({"access_token": str(uuid4())})

Expand All @@ -113,7 +119,10 @@ async def test_webhook_error(hass, smartthings_mock):
flow.hass = hass

data = {"error": {}}
error = APIResponseError(None, None, data=data, status=422)
request_info = Mock(real_url="http://example.com")
error = APIResponseError(
request_info=request_info, history=None, data=data, status=422
)
error.is_target_error = Mock(return_value=True)

smartthings_mock.apps.side_effect = error
Expand All @@ -131,7 +140,10 @@ async def test_api_error(hass, smartthings_mock):
flow.hass = hass

data = {"error": {}}
error = APIResponseError(None, None, data=data, status=400)
request_info = Mock(real_url="http://example.com")
error = APIResponseError(
request_info=request_info, history=None, data=data, status=400
)

smartthings_mock.apps.side_effect = error

Expand All @@ -147,7 +159,10 @@ async def test_unknown_api_error(hass, smartthings_mock):
flow = SmartThingsFlowHandler()
flow.hass = hass

smartthings_mock.apps.side_effect = ClientResponseError(None, None, status=404)
request_info = Mock(real_url="http://example.com")
smartthings_mock.apps.side_effect = ClientResponseError(
request_info=request_info, history=None, status=404
)

result = await flow.async_step_user({"access_token": str(uuid4())})

Expand Down
31 changes: 23 additions & 8 deletions tests/components/smartthings/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ async def test_unrecoverable_api_errors_create_new_flow(
"""
assert await async_setup_component(hass, "persistent_notification", {})
config_entry.add_to_hass(hass)
smartthings_mock.app.side_effect = ClientResponseError(None, None, status=401)
request_info = Mock(real_url="http://example.com")
smartthings_mock.app.side_effect = ClientResponseError(
request_info=request_info, history=None, status=401
)

# Assert setup returns false
result = await smartthings.async_setup_entry(hass, config_entry)
Expand All @@ -75,7 +78,10 @@ async def test_recoverable_api_errors_raise_not_ready(
):
"""Test config entry not ready raised for recoverable API errors."""
config_entry.add_to_hass(hass)
smartthings_mock.app.side_effect = ClientResponseError(None, None, status=500)
request_info = Mock(real_url="http://example.com")
smartthings_mock.app.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
)

with pytest.raises(ConfigEntryNotReady):
await smartthings.async_setup_entry(hass, config_entry)
Expand All @@ -86,9 +92,12 @@ async def test_scenes_api_errors_raise_not_ready(
):
"""Test if scenes are unauthorized we continue to load platforms."""
config_entry.add_to_hass(hass)
request_info = Mock(real_url="http://example.com")
smartthings_mock.app.return_value = app
smartthings_mock.installed_app.return_value = installed_app
smartthings_mock.scenes.side_effect = ClientResponseError(None, None, status=500)
smartthings_mock.scenes.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
)
with pytest.raises(ConfigEntryNotReady):
await smartthings.async_setup_entry(hass, config_entry)

Expand Down Expand Up @@ -140,10 +149,13 @@ async def test_scenes_unauthorized_loads_platforms(
):
"""Test if scenes are unauthorized we continue to load platforms."""
config_entry.add_to_hass(hass)
request_info = Mock(real_url="http://example.com")
smartthings_mock.app.return_value = app
smartthings_mock.installed_app.return_value = installed_app
smartthings_mock.devices.return_value = [device]
smartthings_mock.scenes.side_effect = ClientResponseError(None, None, status=403)
smartthings_mock.scenes.side_effect = ClientResponseError(
request_info=request_info, history=None, status=403
)
mock_token = Mock()
mock_token.access_token.return_value = str(uuid4())
mock_token.refresh_token.return_value = str(uuid4())
Expand Down Expand Up @@ -290,12 +302,13 @@ async def test_remove_entry_app_in_use(hass, config_entry, smartthings_mock):

async def test_remove_entry_already_deleted(hass, config_entry, smartthings_mock):
"""Test handles when the apps have already been removed."""
request_info = Mock(real_url="http://example.com")
# Arrange
smartthings_mock.delete_installed_app.side_effect = ClientResponseError(
None, None, status=403
request_info=request_info, history=None, status=403
)
smartthings_mock.delete_app.side_effect = ClientResponseError(
None, None, status=403
request_info=request_info, history=None, status=403
)
# Act
await smartthings.async_remove_entry(hass, config_entry)
Expand All @@ -308,9 +321,10 @@ async def test_remove_entry_installedapp_api_error(
hass, config_entry, smartthings_mock
):
"""Test raises exceptions removing the installed app."""
request_info = Mock(real_url="http://example.com")
# Arrange
smartthings_mock.delete_installed_app.side_effect = ClientResponseError(
None, None, status=500
request_info=request_info, history=None, status=500
)
# Act
with pytest.raises(ClientResponseError):
Expand All @@ -337,8 +351,9 @@ async def test_remove_entry_installedapp_unknown_error(
async def test_remove_entry_app_api_error(hass, config_entry, smartthings_mock):
"""Test raises exceptions removing the app."""
# Arrange
request_info = Mock(real_url="http://example.com")
smartthings_mock.delete_app.side_effect = ClientResponseError(
None, None, status=500
request_info=request_info, history=None, status=500
)
# Act
with pytest.raises(ClientResponseError):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_util/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ def release(self):
def raise_for_status(self):
"""Raise error if status is 400 or higher."""
if self.status >= 400:
request_info = mock.Mock(real_url="http://example.com")
raise ClientResponseError(
None, None, code=self.status, headers=self.headers
request_info=request_info,
history=None,
code=self.status,
headers=self.headers,
)

def close(self):
Expand Down