Fix unmocked https in the test suite (#42316)

This commit is contained in:
J. Nick Koston 2020-10-25 07:16:23 -05:00 committed by GitHub
parent 3846639744
commit 6822190772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 10 deletions

View File

@ -482,18 +482,19 @@ class HistoryPeriodView(HomeAssistantView):
if start_time > now: if start_time > now:
return self.json([]) return self.json([])
end_time = request.query.get("end_time") end_time_str = request.query.get("end_time")
if end_time: if end_time_str:
end_time = dt_util.parse_datetime(end_time) end_time = dt_util.parse_datetime(end_time_str)
if end_time: if end_time:
end_time = dt_util.as_utc(end_time) end_time = dt_util.as_utc(end_time)
else: else:
return self.json_message("Invalid end_time", HTTP_BAD_REQUEST) return self.json_message("Invalid end_time", HTTP_BAD_REQUEST)
else: else:
end_time = start_time + one_day end_time = start_time + one_day
entity_ids = request.query.get("filter_entity_id") entity_ids_str = request.query.get("filter_entity_id")
if entity_ids: entity_ids = None
entity_ids = entity_ids.lower().split(",") if entity_ids_str:
entity_ids = entity_ids_str.lower().split(",")
include_start_time_state = "skip_initial_state" not in request.query include_start_time_state = "skip_initial_state" not in request.query
significant_changes_only = ( significant_changes_only = (
request.query.get("significant_changes_only", "1") != "0" request.query.get("significant_changes_only", "1") != "0"

View File

@ -118,13 +118,14 @@ async def async_aiohttp_proxy_stream(
hass: HomeAssistantType, hass: HomeAssistantType,
request: web.BaseRequest, request: web.BaseRequest,
stream: aiohttp.StreamReader, stream: aiohttp.StreamReader,
content_type: str, content_type: Optional[str],
buffer_size: int = 102400, buffer_size: int = 102400,
timeout: int = 10, timeout: int = 10,
) -> web.StreamResponse: ) -> web.StreamResponse:
"""Stream a stream to aiohttp web response.""" """Stream a stream to aiohttp web response."""
response = web.StreamResponse() response = web.StreamResponse()
response.content_type = content_type if content_type is not None:
response.content_type = content_type
await response.prepare(request) await response.prepare(request)
try: try:

View File

@ -159,6 +159,8 @@ async def test_options_flow(hass):
return_value=json.loads( return_value=json.loads(
load_fixture("accuweather/current_conditions_data.json") load_fixture("accuweather/current_conditions_data.json")
), ),
), patch(
"accuweather.AccuWeather.async_get_forecast"
): ):
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -174,3 +176,7 @@ async def test_options_flow(hass):
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == {CONF_FORECAST: True} 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()

View File

@ -69,7 +69,7 @@ async def test_invalid_identifier(hass):
} }
with patch( with patch(
"pyairvisual.air_quality.AirQuality", "pyairvisual.air_quality.AirQuality.nearest_city",
side_effect=InvalidKeyError, side_effect=InvalidKeyError,
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(

View File

@ -86,6 +86,8 @@ async def test_onboarding_progress(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": ["hello"]}) mock_storage(hass_storage, {"done": ["hello"]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
with patch.object(views, "STEPS", ["hello", "world"]): with patch.object(views, "STEPS", ["hello", "world"]):
@ -104,6 +106,7 @@ async def test_onboarding_user_already_done(hass, hass_storage, aiohttp_client):
with patch.object(onboarding, "STEPS", ["hello", "world"]): with patch.object(onboarding, "STEPS", ["hello", "world"]):
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
@ -125,6 +128,7 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
"""Test creating a new user.""" """Test creating a new user."""
assert await async_setup_component(hass, "person", {}) assert await async_setup_component(hass, "person", {})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
@ -185,6 +189,7 @@ async def test_onboarding_user_invalid_name(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": []}) mock_storage(hass_storage, {"done": []})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
@ -206,6 +211,7 @@ async def test_onboarding_user_race(hass, hass_storage, aiohttp_client):
mock_storage(hass_storage, {"done": ["hello"]}) mock_storage(hass_storage, {"done": ["hello"]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
@ -240,6 +246,7 @@ async def test_onboarding_integration(hass, hass_storage, hass_client):
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
@ -282,6 +289,7 @@ async def test_onboarding_integration_invalid_redirect_uri(
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
@ -305,6 +313,7 @@ async def test_onboarding_integration_requires_auth(hass, hass_storage, aiohttp_
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await aiohttp_client(hass.http.app) client = await aiohttp_client(hass.http.app)
@ -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]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
@ -339,6 +349,7 @@ async def test_onboarding_core_sets_up_rpi_power(
await async_setup_component(hass, "persistent_notification", {}) await async_setup_component(hass, "persistent_notification", {})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
@ -363,6 +374,7 @@ async def test_onboarding_core_no_rpi_power(
await async_setup_component(hass, "persistent_notification", {}) await async_setup_component(hass, "persistent_notification", {})
assert await async_setup_component(hass, "onboarding", {}) assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client() client = await hass_client()

View File

@ -79,6 +79,12 @@ async def test_full_flow_implementation(hass: HomeAssistant) -> None:
with patch( with patch(
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate", "homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
return_value=True, 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( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],

View File

@ -220,6 +220,7 @@ async def test_locate(hass):
(RuntimeError, False), (RuntimeError, False),
], ],
) )
@patch("sharkiqpy.ayla_api.AylaApi", MockAyla)
async def test_coordinator_updates( async def test_coordinator_updates(
hass: HomeAssistant, side_effect: Optional[Exception], success: bool hass: HomeAssistant, side_effect: Optional[Exception], success: bool
) -> None: ) -> None:

View File

@ -19,7 +19,7 @@ RETYPE = type(re.compile(""))
def mock_stream(data): def mock_stream(data):
"""Mock a stream with data.""" """Mock a stream with data."""
protocol = mock.Mock(_reading_paused=False) protocol = mock.Mock(_reading_paused=False)
stream = StreamReader(protocol) stream = StreamReader(protocol, limit=2 ** 16)
stream.feed_data(data) stream.feed_data(data)
stream.feed_eof() stream.feed_eof()
return stream return stream