Bump PyJWT to 2.6.0 (#90134)

* Bump PyJWT to 2.6.0

* fix time being frozen too late which makes the access token creation time in the future

* revert zha change

* fix repairs test

* fix ical test
This commit is contained in:
J. Nick Koston 2023-03-22 14:00:47 -10:00 committed by GitHub
parent 03aeaba7ef
commit 99b58f157e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 143 additions and 74 deletions

View File

@ -1,4 +1,4 @@
PyJWT==2.5.0 PyJWT==2.6.0
PyNaCl==1.5.0 PyNaCl==1.5.0
aiodiscover==1.4.14 aiodiscover==1.4.14
aiohttp==3.8.4 aiohttp==3.8.4

View File

@ -39,7 +39,7 @@ dependencies = [
"ifaddr==0.1.7", "ifaddr==0.1.7",
"jinja2==3.1.2", "jinja2==3.1.2",
"lru-dict==1.1.8", "lru-dict==1.1.8",
"PyJWT==2.5.0", "PyJWT==2.6.0",
# PyJWT has loose dependency. We want the latest one. # PyJWT has loose dependency. We want the latest one.
"cryptography==39.0.1", "cryptography==39.0.1",
# pyOpenSSL 23.0.0 is required to work with cryptography 39+ # pyOpenSSL 23.0.0 is required to work with cryptography 39+

View File

@ -15,7 +15,7 @@ home-assistant-bluetooth==1.9.3
ifaddr==0.1.7 ifaddr==0.1.7
jinja2==3.1.2 jinja2==3.1.2
lru-dict==1.1.8 lru-dict==1.1.8
PyJWT==2.5.0 PyJWT==2.6.0
cryptography==39.0.1 cryptography==39.0.1
pyOpenSSL==23.0.0 pyOpenSSL==23.0.0
orjson==3.8.7 orjson==3.8.7

View File

@ -1,7 +1,6 @@
"""Test for smart home alexa support.""" """Test for smart home alexa support."""
from unittest.mock import patch from unittest.mock import patch
from freezegun import freeze_time
import pytest import pytest
from homeassistant.components.alexa import messages, smart_home from homeassistant.components.alexa import messages, smart_home
@ -158,7 +157,7 @@ def assert_endpoint_capabilities(endpoint, *interfaces):
return capabilities return capabilities
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_switch(hass: HomeAssistant, events: list[Event]) -> None: async def test_switch(hass: HomeAssistant, events: list[Event]) -> None:
"""Test switch discovery.""" """Test switch discovery."""
device = ("switch.test", "on", {"friendly_name": "Test switch"}) device = ("switch.test", "on", {"friendly_name": "Test switch"})
@ -212,7 +211,7 @@ async def test_outlet(hass: HomeAssistant, events: list[Event]) -> None:
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_light(hass: HomeAssistant) -> None: async def test_light(hass: HomeAssistant) -> None:
"""Test light discovery.""" """Test light discovery."""
device = ("light.test_1", "on", {"friendly_name": "Test light 1"}) device = ("light.test_1", "on", {"friendly_name": "Test light 1"})
@ -308,7 +307,7 @@ async def test_color_light(
# tests # tests
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_script(hass: HomeAssistant) -> None: async def test_script(hass: HomeAssistant) -> None:
"""Test script discovery.""" """Test script discovery."""
device = ("script.test", "off", {"friendly_name": "Test script"}) device = ("script.test", "off", {"friendly_name": "Test script"})
@ -329,7 +328,7 @@ async def test_script(hass: HomeAssistant) -> None:
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_input_boolean(hass: HomeAssistant) -> None: async def test_input_boolean(hass: HomeAssistant) -> None:
"""Test input boolean discovery.""" """Test input boolean discovery."""
device = ("input_boolean.test", "off", {"friendly_name": "Test input boolean"}) device = ("input_boolean.test", "off", {"friendly_name": "Test input boolean"})
@ -366,7 +365,7 @@ async def test_input_boolean(hass: HomeAssistant) -> None:
assert {"name": "detectionState"} in properties["supported"] assert {"name": "detectionState"} in properties["supported"]
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_scene(hass: HomeAssistant) -> None: async def test_scene(hass: HomeAssistant) -> None:
"""Test scene discovery.""" """Test scene discovery."""
device = ("scene.test", "off", {"friendly_name": "Test scene"}) device = ("scene.test", "off", {"friendly_name": "Test scene"})
@ -387,7 +386,7 @@ async def test_scene(hass: HomeAssistant) -> None:
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_fan(hass: HomeAssistant) -> None: async def test_fan(hass: HomeAssistant) -> None:
"""Test fan discovery.""" """Test fan discovery."""
device = ("fan.test_1", "off", {"friendly_name": "Test fan 1"}) device = ("fan.test_1", "off", {"friendly_name": "Test fan 1"})
@ -945,7 +944,7 @@ async def test_single_preset_mode_fan(
caplog.clear() caplog.clear()
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_humidifier( async def test_humidifier(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:
@ -1117,7 +1116,7 @@ async def test_lock(hass: HomeAssistant) -> None:
assert properties["value"] == "UNLOCKED" assert properties["value"] == "UNLOCKED"
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_media_player(hass: HomeAssistant) -> None: async def test_media_player(hass: HomeAssistant) -> None:
"""Test media player discovery.""" """Test media player discovery."""
device = ( device = (
@ -1729,7 +1728,7 @@ async def test_media_player_seek_error(hass: HomeAssistant) -> None:
assert msg["payload"]["type"] == "ACTION_NOT_PERMITTED_FOR_CONTENT" assert msg["payload"]["type"] == "ACTION_NOT_PERMITTED_FOR_CONTENT"
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_alert(hass: HomeAssistant) -> None: async def test_alert(hass: HomeAssistant) -> None:
"""Test alert discovery.""" """Test alert discovery."""
device = ("alert.test", "off", {"friendly_name": "Test alert"}) device = ("alert.test", "off", {"friendly_name": "Test alert"})
@ -1747,7 +1746,7 @@ async def test_alert(hass: HomeAssistant) -> None:
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_automation(hass: HomeAssistant) -> None: async def test_automation(hass: HomeAssistant) -> None:
"""Test automation discovery.""" """Test automation discovery."""
device = ("automation.test", "off", {"friendly_name": "Test automation"}) device = ("automation.test", "off", {"friendly_name": "Test automation"})
@ -1769,7 +1768,7 @@ async def test_automation(hass: HomeAssistant) -> None:
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
async def test_group(hass: HomeAssistant) -> None: async def test_group(hass: HomeAssistant) -> None:
"""Test group discovery.""" """Test group discovery."""
device = ("group.test", "off", {"friendly_name": "Test group"}) device = ("group.test", "off", {"friendly_name": "Test group"})
@ -4183,7 +4182,7 @@ async def test_initialize_camera_stream(
) )
@freeze_time("2022-04-19 07:53:05") @pytest.mark.freeze_time("2022-04-19 07:53:05")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"domain", "domain",
["button", "input_button"], ["button", "input_button"],

View File

@ -4,7 +4,7 @@ import json
import os import os
import time import time
from freezegun import freeze_time import pytest
from homeassistant.components.bmw_connected_drive.const import DOMAIN from homeassistant.components.bmw_connected_drive.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -20,7 +20,7 @@ from tests.components.diagnostics import (
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
@freeze_time(datetime.datetime(2022, 7, 10, 11)) @pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11))
async def test_config_entry_diagnostics( async def test_config_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture
) -> None: ) -> None:
@ -43,7 +43,7 @@ async def test_config_entry_diagnostics(
assert diagnostics == diagnostics_fixture assert diagnostics == diagnostics_fixture
@freeze_time(datetime.datetime(2022, 7, 10, 11)) @pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11))
async def test_device_diagnostics( async def test_device_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture
) -> None: ) -> None:
@ -72,7 +72,7 @@ async def test_device_diagnostics(
assert diagnostics == diagnostics_fixture assert diagnostics == diagnostics_fixture
@freeze_time(datetime.datetime(2022, 7, 10, 11)) @pytest.mark.freeze_time(datetime.datetime(2022, 7, 10, 11))
async def test_device_diagnostics_vehicle_not_found( async def test_device_diagnostics_vehicle_not_found(
hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture hass: HomeAssistant, hass_client: ClientSessionGenerator, bmw_fixture
) -> None: ) -> None:

View File

@ -2,7 +2,7 @@
from datetime import datetime from datetime import datetime
from unittest.mock import patch from unittest.mock import patch
from freezegun import freeze_time import pytest
from homeassistant.components.weather import ( from homeassistant.components.weather import (
ATTR_FORECAST, ATTR_FORECAST,
@ -100,7 +100,7 @@ async def test_daily_forecast(hass: HomeAssistant) -> None:
assert forecast.get(ATTR_FORECAST_WIND_BEARING) == "S" assert forecast.get(ATTR_FORECAST_WIND_BEARING) == "S"
@freeze_time("2020-01-14 23:00:00") @pytest.mark.freeze_time("2020-01-14 23:00:00")
async def test_hourly_forecast(hass: HomeAssistant) -> None: async def test_hourly_forecast(hass: HomeAssistant) -> None:
"""Test for successfully getting daily forecast.""" """Test for successfully getting daily forecast."""
with patch( with patch(

View File

@ -1,19 +1,46 @@
"""Tests for diagnostics platform of local calendar.""" """Tests for diagnostics platform of local calendar."""
from aiohttp.test_utils import TestClient
from freezegun import freeze_time from freezegun import freeze_time
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from homeassistant.auth.models import Credentials
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .conftest import TEST_ENTITY, ClientFixture from .conftest import TEST_ENTITY, Client, ClientFixture
from tests.common import MockConfigEntry from tests.common import CLIENT_ID, MockConfigEntry, MockUser
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
async def generate_new_hass_access_token(
hass: HomeAssistant, hass_admin_user: MockUser, hass_admin_credential: Credentials
) -> str:
"""Return an access token to access Home Assistant."""
await hass.auth.async_link_user(hass_admin_user, hass_admin_credential)
refresh_token = await hass.auth.async_create_refresh_token(
hass_admin_user, CLIENT_ID, credential=hass_admin_credential
)
return hass.auth.async_create_access_token(refresh_token)
def _get_test_client_generator(
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, new_token: str
):
"""Return a test client generator.""."""
async def auth_client() -> TestClient:
return await aiohttp_client(
hass.http.app, headers={"Authorization": f"Bearer {new_token}"}
)
return auth_client
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_diag(hass): async def setup_diag(hass):
"""Set up diagnostics platform.""" """Set up diagnostics platform."""
@ -24,12 +51,27 @@ async def setup_diag(hass):
async def test_empty_calendar( async def test_empty_calendar(
hass: HomeAssistant, hass: HomeAssistant,
setup_integration: None, setup_integration: None,
hass_client: ClientSessionGenerator, hass_admin_user: MockUser,
hass_admin_credential: Credentials,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
aiohttp_client: ClientSessionGenerator,
socket_enabled: None,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test diagnostics against an empty calendar.""" """Test diagnostics against an empty calendar."""
data = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) # Since we are freezing time only when we enter this test, we need to
# manually create a new token and clients since the token created by
# the fixtures would not be valid.
#
# Ideally we would use pytest.mark.freeze_time before the fixtures, but that does not
# work with the ical library and freezegun because
# `TypeError: '<' not supported between instances of 'FakeDatetimeMeta' and 'FakeDateMeta'`
new_token = await generate_new_hass_access_token(
hass, hass_admin_user, hass_admin_credential
)
data = await get_diagnostics_for_config_entry(
hass, _get_test_client_generator(hass, aiohttp_client, new_token), config_entry
)
assert data == snapshot assert data == snapshot
@ -37,14 +79,26 @@ async def test_empty_calendar(
async def test_api_date_time_event( async def test_api_date_time_event(
hass: HomeAssistant, hass: HomeAssistant,
setup_integration: None, setup_integration: None,
hass_admin_user: MockUser,
hass_admin_credential: Credentials,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
hass_client: ClientSessionGenerator, hass_ws_client: ClientFixture,
ws_client: ClientFixture, aiohttp_client: ClientSessionGenerator,
socket_enabled: None,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test an event with a start/end date time.""" """Test an event with a start/end date time."""
# Since we are freezing time only when we enter this test, we need to
client = await ws_client() # manually create a new token and clients since the token created by
# the fixtures would not be valid.
#
# Ideally we would use pytest.mark.freeze_time before the fixtures, but that does not
# work with the ical library and freezegun because
# `TypeError: '<' not supported between instances of 'FakeDatetimeMeta' and 'FakeDateMeta'`
new_token = await generate_new_hass_access_token(
hass, hass_admin_user, hass_admin_credential
)
client = Client(await hass_ws_client(hass, access_token=new_token))
await client.cmd_result( await client.cmd_result(
"create", "create",
{ {
@ -58,5 +112,7 @@ async def test_api_date_time_event(
}, },
) )
data = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) data = await get_diagnostics_for_config_entry(
hass, _get_test_client_generator(hass, aiohttp_client, new_token), config_entry
)
assert data == snapshot assert data == snapshot

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import datetime import datetime
from freezegun import freeze_time
import pytest import pytest
import requests_mock import requests_mock
@ -16,7 +15,9 @@ from .const import DOMAIN, METOFFICE_CONFIG_WAVERTREE, TEST_COORDINATES_WAVERTRE
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
("old_unique_id", "new_unique_id", "migration_needed"), ("old_unique_id", "new_unique_id", "migration_needed"),
[ [

View File

@ -2,7 +2,7 @@
import datetime import datetime
import json import json
from freezegun import freeze_time import pytest
import requests_mock import requests_mock
from homeassistant.components.metoffice.const import ATTRIBUTION, DOMAIN from homeassistant.components.metoffice.const import ATTRIBUTION, DOMAIN
@ -24,7 +24,9 @@ from .const import (
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_one_sensor_site_running( async def test_one_sensor_site_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:
@ -72,7 +74,9 @@ async def test_one_sensor_site_running(
assert sensor.attributes.get("attribution") == ATTRIBUTION assert sensor.attributes.get("attribution") == ATTRIBUTION
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_two_sensor_sites_running( async def test_two_sensor_sites_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:

View File

@ -3,7 +3,7 @@ import datetime
from datetime import timedelta from datetime import timedelta
import json import json
from freezegun import freeze_time import pytest
import requests_mock import requests_mock
from homeassistant.components.metoffice.const import DOMAIN from homeassistant.components.metoffice.const import DOMAIN
@ -23,7 +23,9 @@ from .const import (
from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_site_cannot_connect( async def test_site_cannot_connect(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:
@ -52,7 +54,9 @@ async def test_site_cannot_connect(
assert sensor is None assert sensor is None
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_site_cannot_update( async def test_site_cannot_update(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:
@ -100,7 +104,9 @@ async def test_site_cannot_update(
assert weather.state == STATE_UNAVAILABLE assert weather.state == STATE_UNAVAILABLE
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_one_weather_site_running( async def test_one_weather_site_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:
@ -183,7 +189,9 @@ async def test_one_weather_site_running(
assert weather.attributes.get("forecast")[3]["wind_bearing"] == "SE" assert weather.attributes.get("forecast")[3]["wind_bearing"] == "SE"
@freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.timezone.utc)
)
async def test_two_weather_sites_running( async def test_two_weather_sites_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None: ) -> None:

View File

@ -6,7 +6,6 @@ from pathlib import Path
import sqlite3 import sqlite3
from unittest.mock import MagicMock, Mock, patch from unittest.mock import MagicMock, Mock, patch
from freezegun import freeze_time
import py import py
import pytest import pytest
from sqlalchemy import text from sqlalchemy import text
@ -934,7 +933,7 @@ def test_execute_stmt_lambda_element(
assert rows == ["mock_row"] assert rows == ["mock_row"]
@freeze_time(datetime(2022, 10, 21, 7, 25, tzinfo=timezone.utc)) @pytest.mark.freeze_time(datetime(2022, 10, 21, 7, 25, tzinfo=timezone.utc))
async def test_resolve_period(hass: HomeAssistant) -> None: async def test_resolve_period(hass: HomeAssistant) -> None:
"""Test statistic_during_period.""" """Test statistic_during_period."""

View File

@ -217,7 +217,9 @@ async def test_statistics_during_period(
} }
@freeze_time(datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)
)
@pytest.mark.parametrize("offset", (0, 1, 2)) @pytest.mark.parametrize("offset", (0, 1, 2))
async def test_statistic_during_period( async def test_statistic_during_period(
recorder_mock: Recorder, recorder_mock: Recorder,
@ -632,7 +634,9 @@ async def test_statistic_during_period(
} }
@freeze_time(datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)
)
async def test_statistic_during_period_hole( async def test_statistic_during_period_hole(
recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None: ) -> None:
@ -795,7 +799,9 @@ async def test_statistic_during_period_hole(
} }
@freeze_time(datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)) @pytest.mark.freeze_time(
datetime.datetime(2022, 10, 21, 7, 25, tzinfo=datetime.timezone.utc)
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
("calendar_period", "start_time", "end_time"), ("calendar_period", "start_time", "end_time"),
( (

View File

@ -1,7 +1,6 @@
"""Test the repairs websocket API.""" """Test the repairs websocket API."""
from unittest.mock import AsyncMock, Mock from unittest.mock import AsyncMock, Mock
from freezegun import freeze_time
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
@ -27,7 +26,7 @@ from tests.common import mock_platform
from tests.typing import WebSocketGenerator from tests.typing import WebSocketGenerator
@freeze_time("2022-07-19 07:53:05") @pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_create_update_issue( async def test_create_update_issue(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None: ) -> None:
@ -166,7 +165,7 @@ async def test_create_issue_invalid_version(
assert msg["result"] == {"issues": []} assert msg["result"] == {"issues": []}
@freeze_time("2022-07-19 07:53:05") @pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_ignore_issue( async def test_ignore_issue(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None: ) -> None:
@ -335,6 +334,7 @@ async def test_ignore_issue(
} }
@pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_delete_issue( async def test_delete_issue(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
@ -487,7 +487,7 @@ async def test_non_compliant_platform(
assert list(hass.data[DOMAIN]["platforms"].keys()) == ["fake_integration"] assert list(hass.data[DOMAIN]["platforms"].keys()) == ["fake_integration"]
@freeze_time("2022-07-21 08:22:00") @pytest.mark.freeze_time("2022-07-21 08:22:00")
async def test_sync_methods( async def test_sync_methods(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,

View File

@ -5,7 +5,6 @@ from http import HTTPStatus
from typing import Any from typing import Any
from unittest.mock import ANY, AsyncMock, Mock from unittest.mock import ANY, AsyncMock, Mock
from freezegun import freeze_time
import pytest import pytest
import voluptuous as vol import voluptuous as vol
@ -430,7 +429,7 @@ async def test_step_unauth(
assert resp.status == HTTPStatus.UNAUTHORIZED assert resp.status == HTTPStatus.UNAUTHORIZED
@freeze_time("2022-07-19 07:53:05") @pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_list_issues( async def test_list_issues(
hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client
) -> None: ) -> None:

View File

@ -1,5 +1,4 @@
"""Tests for Shelly utils.""" """Tests for Shelly utils."""
from freezegun import freeze_time
import pytest import pytest
from homeassistant.components.shelly.utils import ( from homeassistant.components.shelly.utils import (
@ -150,7 +149,7 @@ async def test_get_block_device_sleep_period(settings, sleep_period) -> None:
assert get_block_device_sleep_period(settings) == sleep_period assert get_block_device_sleep_period(settings) == sleep_period
@freeze_time("2019-01-10 18:43:00+00:00") @pytest.mark.freeze_time("2019-01-10 18:43:00+00:00")
async def test_get_device_uptime() -> None: async def test_get_device_uptime() -> None:
"""Test block test get device uptime.""" """Test block test get device uptime."""
assert get_device_uptime( assert get_device_uptime(

View File

@ -1,7 +1,6 @@
"""Test Times of the Day Binary Sensor.""" """Test Times of the Day Binary Sensor."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
from freezegun import freeze_time
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
@ -67,7 +66,7 @@ async def test_setup_no_sensors(hass: HomeAssistant) -> None:
) )
@freeze_time("2019-01-10 18:43:00-08:00") @pytest.mark.freeze_time("2019-01-10 18:43:00-08:00")
async def test_in_period_on_start(hass: HomeAssistant) -> None: async def test_in_period_on_start(hass: HomeAssistant) -> None:
"""Test simple setting.""" """Test simple setting."""
config = { config = {
@ -87,7 +86,7 @@ async def test_in_period_on_start(hass: HomeAssistant) -> None:
assert state.state == STATE_ON assert state.state == STATE_ON
@freeze_time("2019-01-10 22:30:00-08:00") @pytest.mark.freeze_time("2019-01-10 22:30:00-08:00")
async def test_midnight_turnover_before_midnight_inside_period( async def test_midnight_turnover_before_midnight_inside_period(
hass: HomeAssistant, hass: HomeAssistant,
) -> None: ) -> None:
@ -131,7 +130,7 @@ async def test_midnight_turnover_after_midnight_inside_period(
assert state.state == STATE_ON assert state.state == STATE_ON
@freeze_time("2019-01-10 20:30:00-08:00") @pytest.mark.freeze_time("2019-01-10 20:30:00-08:00")
async def test_midnight_turnover_before_midnight_outside_period( async def test_midnight_turnover_before_midnight_outside_period(
hass: HomeAssistant, hass: HomeAssistant,
) -> None: ) -> None:
@ -148,7 +147,7 @@ async def test_midnight_turnover_before_midnight_outside_period(
assert state.state == STATE_OFF assert state.state == STATE_OFF
@freeze_time("2019-01-10 10:00:00-08:00") @pytest.mark.freeze_time("2019-01-10 10:00:00-08:00")
async def test_after_happens_tomorrow(hass: HomeAssistant) -> None: async def test_after_happens_tomorrow(hass: HomeAssistant) -> None:
"""Test when both before and after are in the future, and after is later than before.""" """Test when both before and after are in the future, and after is later than before."""
config = { config = {
@ -643,7 +642,7 @@ async def test_dst(
assert state.state == STATE_OFF assert state.state == STATE_OFF
@freeze_time("2019-01-10 18:43:00") @pytest.mark.freeze_time("2019-01-10 18:43:00")
@pytest.mark.parametrize("hass_time_zone", ("UTC",)) @pytest.mark.parametrize("hass_time_zone", ("UTC",))
async def test_simple_before_after_does_not_loop_utc_not_in_range( async def test_simple_before_after_does_not_loop_utc_not_in_range(
hass: HomeAssistant, hass: HomeAssistant,
@ -669,7 +668,7 @@ async def test_simple_before_after_does_not_loop_utc_not_in_range(
assert state.attributes["next_update"] == "2019-01-10T22:00:00+00:00" assert state.attributes["next_update"] == "2019-01-10T22:00:00+00:00"
@freeze_time("2019-01-10 22:43:00") @pytest.mark.freeze_time("2019-01-10 22:43:00")
@pytest.mark.parametrize("hass_time_zone", ("UTC",)) @pytest.mark.parametrize("hass_time_zone", ("UTC",))
async def test_simple_before_after_does_not_loop_utc_in_range( async def test_simple_before_after_does_not_loop_utc_in_range(
hass: HomeAssistant, hass: HomeAssistant,
@ -695,7 +694,7 @@ async def test_simple_before_after_does_not_loop_utc_in_range(
assert state.attributes["next_update"] == "2019-01-11T06:00:00+00:00" assert state.attributes["next_update"] == "2019-01-11T06:00:00+00:00"
@freeze_time("2019-01-11 06:00:00") @pytest.mark.freeze_time("2019-01-11 06:00:00")
@pytest.mark.parametrize("hass_time_zone", ("UTC",)) @pytest.mark.parametrize("hass_time_zone", ("UTC",))
async def test_simple_before_after_does_not_loop_utc_fire_at_before( async def test_simple_before_after_does_not_loop_utc_fire_at_before(
hass: HomeAssistant, hass: HomeAssistant,
@ -721,7 +720,7 @@ async def test_simple_before_after_does_not_loop_utc_fire_at_before(
assert state.attributes["next_update"] == "2019-01-11T22:00:00+00:00" assert state.attributes["next_update"] == "2019-01-11T22:00:00+00:00"
@freeze_time("2019-01-10 22:00:00") @pytest.mark.freeze_time("2019-01-10 22:00:00")
@pytest.mark.parametrize("hass_time_zone", ("UTC",)) @pytest.mark.parametrize("hass_time_zone", ("UTC",))
async def test_simple_before_after_does_not_loop_utc_fire_at_after( async def test_simple_before_after_does_not_loop_utc_fire_at_after(
hass: HomeAssistant, hass: HomeAssistant,
@ -747,7 +746,7 @@ async def test_simple_before_after_does_not_loop_utc_fire_at_after(
assert state.attributes["next_update"] == "2019-01-11T06:00:00+00:00" assert state.attributes["next_update"] == "2019-01-11T06:00:00+00:00"
@freeze_time("2019-01-10 22:00:00") @pytest.mark.freeze_time("2019-01-10 22:00:00")
@pytest.mark.parametrize("hass_time_zone", ("UTC",)) @pytest.mark.parametrize("hass_time_zone", ("UTC",))
async def test_simple_before_after_does_not_loop_utc_both_before_now( async def test_simple_before_after_does_not_loop_utc_both_before_now(
hass: HomeAssistant, hass: HomeAssistant,
@ -773,7 +772,7 @@ async def test_simple_before_after_does_not_loop_utc_both_before_now(
assert state.attributes["next_update"] == "2019-01-11T00:00:00+00:00" assert state.attributes["next_update"] == "2019-01-11T00:00:00+00:00"
@freeze_time("2019-01-10 17:43:00+01:00") @pytest.mark.freeze_time("2019-01-10 17:43:00+01:00")
@pytest.mark.parametrize("hass_time_zone", ("Europe/Berlin",)) @pytest.mark.parametrize("hass_time_zone", ("Europe/Berlin",))
async def test_simple_before_after_does_not_loop_berlin_not_in_range( async def test_simple_before_after_does_not_loop_berlin_not_in_range(
hass: HomeAssistant, hass: HomeAssistant,
@ -799,7 +798,7 @@ async def test_simple_before_after_does_not_loop_berlin_not_in_range(
assert state.attributes["next_update"] == "2019-01-11T00:00:00+01:00" assert state.attributes["next_update"] == "2019-01-11T00:00:00+01:00"
@freeze_time("2019-01-11 00:43:00+01:00") @pytest.mark.freeze_time("2019-01-11 00:43:00+01:00")
@pytest.mark.parametrize("hass_time_zone", ("Europe/Berlin",)) @pytest.mark.parametrize("hass_time_zone", ("Europe/Berlin",))
async def test_simple_before_after_does_not_loop_berlin_in_range( async def test_simple_before_after_does_not_loop_berlin_in_range(
hass: HomeAssistant, hass: HomeAssistant,

View File

@ -1,7 +1,6 @@
"""Test the Times of the Day config flow.""" """Test the Times of the Day config flow."""
from unittest.mock import patch from unittest.mock import patch
from freezegun import freeze_time
import pytest import pytest
from homeassistant import config_entries from homeassistant import config_entries
@ -66,7 +65,7 @@ def get_suggested(schema, key):
raise Exception raise Exception
@freeze_time("2022-03-16 17:37:00", tz_offset=-7) @pytest.mark.freeze_time("2022-03-16 17:37:00", tz_offset=-7)
async def test_options(hass: HomeAssistant) -> None: async def test_options(hass: HomeAssistant) -> None:
"""Test reconfiguring.""" """Test reconfiguring."""
# Setup the config entry # Setup the config entry

View File

@ -1,5 +1,6 @@
"""Test the Times of the Day integration.""" """Test the Times of the Day integration."""
from freezegun import freeze_time
import pytest
from homeassistant.components.tod.const import DOMAIN from homeassistant.components.tod.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -8,7 +9,7 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@freeze_time("2022-03-16 17:37:00", tz_offset=-7) @pytest.mark.freeze_time("2022-03-16 17:37:00", tz_offset=-7)
async def test_setup_and_remove_config_entry(hass: HomeAssistant) -> None: async def test_setup_and_remove_config_entry(hass: HomeAssistant) -> None:
"""Test setting up and removing a config entry.""" """Test setting up and removing a config entry."""
registry = er.async_get(hass) registry = er.async_get(hass)

View File

@ -4,7 +4,6 @@ from datetime import datetime, timedelta
from ipaddress import IPv4Address from ipaddress import IPv4Address
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from freezegun import freeze_time
import pytest import pytest
import pytz import pytz
from pyunifiprotect.data import ( from pyunifiprotect.data import (
@ -465,7 +464,7 @@ TWO_MONTH_SIMPLE = (
("start", "months"), ("start", "months"),
[ONE_MONTH_SIMPLE, TWO_MONTH_SIMPLE], [ONE_MONTH_SIMPLE, TWO_MONTH_SIMPLE],
) )
@freeze_time("2022-09-15 03:00:00-07:00") @pytest.mark.freeze_time("2022-09-15 03:00:00-07:00")
async def test_browse_media_time( async def test_browse_media_time(
hass: HomeAssistant, hass: HomeAssistant,
ufp: MockUFPFixture, ufp: MockUFPFixture,
@ -537,7 +536,7 @@ TWO_MONTH_TIMEZONE = (
("start", "months"), ("start", "months"),
[ONE_MONTH_TIMEZONE, TWO_MONTH_TIMEZONE], [ONE_MONTH_TIMEZONE, TWO_MONTH_TIMEZONE],
) )
@freeze_time("2022-08-31 21:00:00-07:00") @pytest.mark.freeze_time("2022-08-31 21:00:00-07:00")
async def test_browse_media_time_timezone( async def test_browse_media_time_timezone(
hass: HomeAssistant, hass: HomeAssistant,
ufp: MockUFPFixture, ufp: MockUFPFixture,
@ -713,7 +712,7 @@ async def test_browse_media_eventthumb(
assert browse.media_class == MediaClass.IMAGE assert browse.media_class == MediaClass.IMAGE
@freeze_time("2022-09-15 03:00:00-07:00") @pytest.mark.freeze_time("2022-09-15 03:00:00-07:00")
async def test_browse_media_day( async def test_browse_media_day(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera
) -> None: ) -> None: