From c010b97abf11d253f0634905aacd720a6625fffc Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Wed, 16 Aug 2023 09:07:14 +0200 Subject: [PATCH] Improve test recovery MQTT certificate files (#98223) * Improve test recovery MQTT certificate files * Spelling --- tests/components/mqtt/test_util.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/components/mqtt/test_util.py b/tests/components/mqtt/test_util.py index 96577bd3fa4..e93a5e376bb 100644 --- a/tests/components/mqtt/test_util.py +++ b/tests/components/mqtt/test_util.py @@ -37,7 +37,7 @@ def mock_temp_dir(): async def test_async_create_certificate_temp_files( hass: HomeAssistant, mock_temp_dir, option, content, file_created ) -> None: - """Test creating and reading certificate files.""" + """Test creating and reading and recovery certificate files.""" config = {option: content} await mqtt.util.async_create_certificate_temp_files(hass, config) @@ -47,6 +47,22 @@ async def test_async_create_certificate_temp_files( mqtt.util.migrate_certificate_file_to_content(file_path or content) == content ) + # Make sure certificate temp files are recovered + if file_path: + # Overwrite content of file (except for auto option) + file = open(file_path, "wb") + file.write(b"invalid") + file.close() + + await mqtt.util.async_create_certificate_temp_files(hass, config) + file_path2 = mqtt.util.get_file_path(option) + assert bool(file_path2) is file_created + assert ( + mqtt.util.migrate_certificate_file_to_content(file_path2 or content) == content + ) + + assert file_path == file_path2 + async def test_reading_non_exitisting_certificate_file() -> None: """Test reading a non existing certificate file."""