Fix logbook tests failing because time was not url encoded correctly (#89770)

This commit is contained in:
J. Nick Koston 2023-03-15 15:29:41 -10:00 committed by GitHub
parent e379aa23bd
commit 4080d68489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -417,7 +417,7 @@ async def test_logbook_view_period_entity(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -455,7 +455,7 @@ async def test_logbook_view_period_entity(
# Tomorrow time 00:00:00
start = (dt_util.utcnow() + timedelta(days=1)).date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test tomorrow entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -512,12 +512,13 @@ async def test_logbook_describe_event(
client = await hass_client()
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
results = await response.json()
assert len(results) == 1
@ -586,12 +587,13 @@ async def test_exclude_described_event(
client = await hass_client()
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
results = await response.json()
assert len(results) == 1
@ -619,12 +621,13 @@ async def test_logbook_view_end_time_entity(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
response_json = await response.json()
@ -635,7 +638,8 @@ async def test_logbook_view_end_time_entity(
# Test entries for 3 days with filter by entity_id
end_time = start + timedelta(hours=72)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}&entity=switch.test"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat(), "entity": "switch.test"},
)
assert response.status == HTTPStatus.OK
response_json = await response.json()
@ -644,15 +648,16 @@ async def test_logbook_view_end_time_entity(
# Tomorrow time 00:00:00
start = dt_util.utcnow()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test entries from today to 3 days with filter by entity_id
end_time = start_date + timedelta(hours=72)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}&entity=switch.test"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat(), "entity": "switch.test"},
)
assert response.status == HTTPStatus.OK
response_json = await response.json()
assert response.status == HTTPStatus.OK
assert len(response_json) == 1
assert response_json[0]["entity_id"] == entity_id_test
@ -693,12 +698,13 @@ async def test_logbook_entity_filter_with_automations(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -712,7 +718,11 @@ async def test_logbook_entity_filter_with_automations(
# Test entries for 3 days with filter by entity_id
end_time = start + timedelta(hours=72)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}&entity=alarm_control_panel.area_001"
f"/api/logbook/{start_date.isoformat()}",
params={
"end_time": end_time.isoformat(),
"entity": "alarm_control_panel.area_001",
},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -721,12 +731,16 @@ async def test_logbook_entity_filter_with_automations(
# Tomorrow time 00:00:00
start = dt_util.utcnow()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test entries from today to 3 days with filter by entity_id
end_time = start_date + timedelta(hours=72)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}&entity=alarm_control_panel.area_002"
f"/api/logbook/{start_date.isoformat()}",
params={
"end_time": end_time.isoformat(),
"entity": "alarm_control_panel.area_002",
},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -760,12 +774,13 @@ async def test_logbook_entity_no_longer_in_state_machine(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -804,7 +819,7 @@ async def test_filter_continuous_sensor_values(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -845,7 +860,7 @@ async def test_exclude_new_entities(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -893,7 +908,7 @@ async def test_exclude_removed_entities(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -939,7 +954,7 @@ async def test_exclude_attribute_changes(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
@ -1053,12 +1068,13 @@ async def test_logbook_entity_context_id(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -1159,12 +1175,13 @@ async def test_logbook_context_id_automation_script_started_manually(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -1317,12 +1334,13 @@ async def test_logbook_entity_context_parent_id(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -1435,12 +1453,13 @@ async def test_logbook_context_from_template(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
end_time = start_date + timedelta(hours=24)
response = await client.get(
f"/api/logbook/{start_date.isoformat()}?end_time={end_time}"
f"/api/logbook/{start_date.isoformat()}",
params={"end_time": end_time.isoformat()},
)
assert response.status == HTTPStatus.OK
json_dict = await response.json()
@ -1518,7 +1537,7 @@ async def test_logbook_(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
@ -1561,7 +1580,7 @@ async def test_logbook_many_entities_multiple_calls(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
end_time = start + timedelta(hours=24)
for automation_id in range(5):
@ -1628,7 +1647,7 @@ async def test_custom_log_entry_discoverable_via_(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
@ -1708,7 +1727,7 @@ async def test_logbook_multiple_entities(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
@ -1781,7 +1800,7 @@ async def test_logbook_invalid_entity(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)
@ -2333,11 +2352,14 @@ async def _async_fetch_logbook(client, params=None):
params = {}
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day) - timedelta(hours=24)
now = dt_util.utcnow()
start = datetime(now.year, now.month, now.day, tzinfo=dt_util.UTC)
start_date = datetime(
start.year, start.month, start.day, tzinfo=dt_util.UTC
) - timedelta(hours=24)
if "end_time" not in params:
params["end_time"] = str(start + timedelta(hours=48))
params["end_time"] = (start + timedelta(hours=48)).isoformat()
# Test today entries without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}", params=params)
@ -2825,7 +2847,7 @@ async def test_logbook_select_entities_context_id(
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
start_date = datetime(start.year, start.month, start.day, tzinfo=dt_util.UTC)
# Test today entries with filter by end_time
end_time = start + timedelta(hours=24)