Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unmocked https in the test suite #42316

Merged
merged 10 commits into from
Oct 25, 2020
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
13 changes: 7 additions & 6 deletions homeassistant/components/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,19 @@ async def get(
if start_time > now:
return self.json([])

end_time = request.query.get("end_time")
if end_time:
end_time = dt_util.parse_datetime(end_time)
end_time_str = request.query.get("end_time")
if end_time_str:
end_time = dt_util.parse_datetime(end_time_str)
if end_time:
end_time = dt_util.as_utc(end_time)
else:
return self.json_message("Invalid end_time", HTTP_BAD_REQUEST)
else:
end_time = start_time + one_day
entity_ids = request.query.get("filter_entity_id")
if entity_ids:
entity_ids = entity_ids.lower().split(",")
entity_ids_str = request.query.get("filter_entity_id")
entity_ids = None
if entity_ids_str:
entity_ids = entity_ids_str.lower().split(",")
include_start_time_state = "skip_initial_state" not in request.query
significant_changes_only = (
request.query.get("significant_changes_only", "1") != "0"
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/helpers/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ async def async_aiohttp_proxy_stream(
hass: HomeAssistantType,
request: web.BaseRequest,
stream: aiohttp.StreamReader,
content_type: str,
content_type: Optional[str],
buffer_size: int = 102400,
timeout: int = 10,
) -> web.StreamResponse:
"""Stream a stream to aiohttp web response."""
response = web.StreamResponse()
response.content_type = content_type
if content_type is not None:
response.content_type = content_type
await response.prepare(request)

try:
Expand Down
6 changes: 6 additions & 0 deletions tests/components/accuweather/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ async def test_options_flow(hass):
return_value=json.loads(
load_fixture("accuweather/current_conditions_data.json")
),
), patch(
"accuweather.AccuWeather.async_get_forecast"
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
Expand All @@ -174,3 +176,7 @@ async def test_options_flow(hass):

assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == {CONF_FORECAST: True}

await hass.async_block_till_done()
assert await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
2 changes: 1 addition & 1 deletion tests/components/airvisual/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def test_invalid_identifier(hass):
}

with patch(
"pyairvisual.air_quality.AirQuality",
"pyairvisual.air_quality.AirQuality.nearest_city",
side_effect=InvalidKeyError,
):
result = await hass.config_entries.flow.async_init(
Expand Down
12 changes: 12 additions & 0 deletions tests/components/onboarding/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ async def test_onboarding_progress(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": ["hello"]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

with patch.object(views, "STEPS", ["hello", "world"]):
Expand All @@ -104,6 +106,7 @@ async def test_onboarding_user_already_done(hass, hass_storage, aiohttp_client):

with patch.object(onboarding, "STEPS", ["hello", "world"]):
assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

Expand All @@ -125,6 +128,7 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
"""Test creating a new user."""
assert await async_setup_component(hass, "person", {})
assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

Expand Down Expand Up @@ -185,6 +189,7 @@ async def test_onboarding_user_invalid_name(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": []})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

Expand All @@ -206,6 +211,7 @@ async def test_onboarding_user_race(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": ["hello"]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

Expand Down Expand Up @@ -240,6 +246,7 @@ async def test_onboarding_integration(hass, hass_storage, hass_client):
mock_storage(hass_storage, {"done": [const.STEP_USER]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await hass_client()

Expand Down Expand Up @@ -282,6 +289,7 @@ async def test_onboarding_integration_invalid_redirect_uri(
mock_storage(hass_storage, {"done": [const.STEP_USER]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await hass_client()

Expand All @@ -305,6 +313,7 @@ async def test_onboarding_integration_requires_auth(hass, hass_storage, aiohttp_
mock_storage(hass_storage, {"done": [const.STEP_USER]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await aiohttp_client(hass.http.app)

Expand All @@ -320,6 +329,7 @@ async def test_onboarding_core_sets_up_met(hass, hass_storage, hass_client):
mock_storage(hass_storage, {"done": [const.STEP_USER]})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await hass_client()

Expand All @@ -339,6 +349,7 @@ async def test_onboarding_core_sets_up_rpi_power(
await async_setup_component(hass, "persistent_notification", {})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await hass_client()

Expand All @@ -363,6 +374,7 @@ async def test_onboarding_core_no_rpi_power(
await async_setup_component(hass, "persistent_notification", {})

assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()

client = await hass_client()

Expand Down
6 changes: 6 additions & 0 deletions tests/components/ovo_energy/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ async def test_full_flow_implementation(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
return_value=True,
), patch(
"homeassistant.components.ovo_energy.async_setup",
return_value=True,
), patch(
"homeassistant.components.ovo_energy.async_setup_entry",
return_value=True,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand Down
1 change: 1 addition & 0 deletions tests/components/sharkiq/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ async def test_locate(hass):
(RuntimeError, False),
],
)
@patch("sharkiqpy.ayla_api.AylaApi", MockAyla)
async def test_coordinator_updates(
hass: HomeAssistant, side_effect: Optional[Exception], success: bool
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def mock_stream(data):
"""Mock a stream with data."""
protocol = mock.Mock(_reading_paused=False)
stream = StreamReader(protocol)
stream = StreamReader(protocol, limit=2 ** 16)
stream.feed_data(data)
stream.feed_eof()
return stream
Expand Down