Make sure context_id is 26 chars and partially conform to ULID standard (#550)

This commit is contained in:
Bas Nijholt 2023-04-06 12:37:02 -07:00 • committed by GitHub
commit 59877a0343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 28 deletions

View file

@ -4,9 +4,7 @@ import asyncio
from copy import deepcopy
import datetime
import logging
from random import choices as random_choices
from random import randint
import string
from unittest.mock import patch
from homeassistant.components.adaptive_lighting.const import (
@ -76,6 +74,7 @@ from homeassistant.setup import async_setup_component
from homeassistant.util.color import color_temperature_mired_to_kelvin
import homeassistant.util.dt as dt_util
import pytest
import ulid_transform
import voluptuous.error
from tests.common import MockConfigEntry, mock_area_registry
@ -118,6 +117,10 @@ GLOBAL_TEST_DEPENDENCIES = [
]
def create_random_context() -> str:
return Context(id=ulid_transform.ulid_now(), parent_id=None)
@pytest.fixture
def reset_time_zone():
"""Reset time zone."""
@ -219,16 +222,6 @@ async def setup_lights_and_switch(hass, extra_conf=None):
return switch, lights_instances
def create_random_context() -> str:
ulid_max_length = 26 # changed from 36->26 in core2023.4.0
return Context(
id="".join(
random_choices(string.ascii_uppercase + string.digits, k=ulid_max_length)
),
parent_id=None,
)
# see https://github.com/home-assistant/core/blob/dev/homeassistant/scripts/benchmark/__init__.py
# basically just search the repo for EVENT_STATE_CHANGED look for how it's fired.
def create_transition_events(