From 235186f6fcf6057a6dcf6e5884c2a18573262579 Mon Sep 17 00:00:00 2001 From: Marc-Olivier Arsenault Date: Sun, 29 Oct 2023 18:36:46 +0000 Subject: [PATCH] update testing --- tests/test_binary_sensor.py | 4 ++++ tests/test_button.py | 3 +++ tests/test_camera.py | 12 ++++++++++++ tests/test_init.py | 5 +++++ tests/test_number.py | 1 + tests/test_sensor.py | 11 +++++++++++ tests/test_switch.py | 2 ++ 7 files changed, 38 insertions(+) diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 9f2dc38..3748640 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -28,6 +28,7 @@ async def test_runout_filament_sensor_missing(hass, get_data, get_printer_object ) config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -39,6 +40,7 @@ async def test_runout_filament_sensor_missing(hass, get_data, get_printer_object async def test_runout_filament_sensor(hass): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -48,6 +50,7 @@ async def test_runout_filament_sensor(hass): async def test_multiple_runout_filament_sensor(hass): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -64,6 +67,7 @@ async def test_runout_filament_sensor_off(hass, get_data): ] = False config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() diff --git a/tests/test_button.py b/tests/test_button.py index 84008c4..f600de9 100644 --- a/tests/test_button.py +++ b/tests/test_button.py @@ -35,6 +35,7 @@ def bypass_connect_client_fixture(): ) async def test_buttons(hass, button, method): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -54,6 +55,7 @@ async def test_buttons(hass, button, method): async def test_gcode_macro(hass): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -75,6 +77,7 @@ async def test_gcode_macro(hass): async def test_disabled_buttons(hass): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() diff --git a/tests/test_camera.py b/tests/test_camera.py index c706193..2b68089 100755 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -28,6 +28,7 @@ async def test_camera_services(hass, caplog): """Test camera services""" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -47,6 +48,7 @@ async def test_camera_services_full_path(hass, get_camera_info, caplog): "snapshot_url" ] = "http://1.2.3.4/webcam/?action=2snapshot" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -68,6 +70,7 @@ async def test_two_cameras_services(hass, get_camera_info): ) config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -87,6 +90,7 @@ async def test_two_cameras_same_name_services(hass, get_camera_info): ) config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -100,6 +104,7 @@ async def test_setup_thumbnail_camera(hass, get_data): get_data["status"]["print_stats"]["filename"] = "CE3E3V2_picture_frame_holder.gcode" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -117,6 +122,7 @@ async def test_thumbnail_camera_image( get_data["status"]["print_stats"]["filename"] = "CE3E3V2_picture_frame_holder.gcode" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -134,6 +140,7 @@ async def test_thumbnail_camera_from_img_to_none(hass): """Test thumbnail camera from img to none""" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -146,6 +153,7 @@ async def test_thumbnail_no_thumbnail(hass, get_data): get_data["status"]["print_stats"]["filename"] = "" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -160,6 +168,7 @@ async def test_thumbnail_not_printing(hass, aioclient_mock, get_data): get_data["status"]["print_stats"]["state"] = PRINTSTATES.STANDBY.value config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -183,6 +192,7 @@ async def test_thumbnail_no_thumbnail_after_update( get_data["status"]["print_stats"]["filename"] = "CE3E3V2_picture_frame_holder.gcode" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -218,6 +228,7 @@ async def test_thumbnail_data_failing( return_value={**get_data, **get_printer_info, **get_camera_info}, ): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -235,6 +246,7 @@ async def test_thumbnail_on_subfolder(hass, get_data, aioclient_mock): ] = "subfolder/CE3E3V2_picture_frame_holder.gcode" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() diff --git a/tests/test_init.py b/tests/test_init.py index 47e1f63..3840d1e 100755 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -29,6 +29,7 @@ async def test_setup_unload_and_reload_entry(hass): # Create a mock entry so we don't have to go through config flow config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN] @@ -56,6 +57,7 @@ async def test_setup_unload_and_reload_entry_with_name(hass): config_entry = MockConfigEntry( domain=DOMAIN, data=MOCK_CONFIG_WITH_NAME, entry_id="test" ) + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN] @@ -80,6 +82,7 @@ async def test_async_send_data_exception(hass): """Test async_post_exception""" config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) with patch( @@ -101,6 +104,7 @@ async def test_setup_entry_exception(hass): side_effect=Exception, ): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) with pytest.raises(ConfigEntryNotReady): assert await async_setup_entry(hass, config_entry) @@ -121,6 +125,7 @@ async def test_failed_first_refresh(hass): side_effect=load_data, ): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) with pytest.raises(ConfigEntryNotReady): assert await async_setup_entry(hass, config_entry) diff --git a/tests/test_number.py b/tests/test_number.py index 28694ec..6a4578f 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -28,6 +28,7 @@ def bypass_connect_client_fixture(): ) async def test_number_set_value(hass, number, get_default_api_response): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() diff --git a/tests/test_sensor.py b/tests/test_sensor.py index e2d0b6e..18b20c0 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -44,6 +44,7 @@ async def test_sensor_services_update(hass, get_data): # Create a mock entry so we don't have to go through config flow config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -112,6 +113,7 @@ async def test_sensors( value, ): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -141,6 +143,7 @@ async def test_sensors_not_printing( ): get_data["status"]["print_stats"]["state"] = PRINTSTATES.STANDBY.value config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -152,6 +155,7 @@ async def test_opt_sensor_missing(hass, get_data, get_printer_objects_list): get_printer_objects_list["objects"].remove("temperature_sensor mcu_temp") config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -161,6 +165,7 @@ async def test_opt_sensor_missing(hass, get_data, get_printer_objects_list): async def test_eta(hass): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -176,6 +181,7 @@ async def test_eta(hass): async def test_slicer_time_left(hass, get_data): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -195,6 +201,7 @@ async def test_eta_no_current_data(hass, get_data): get_data["status"]["print_stats"]["print_duration"] = 0 config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -239,6 +246,7 @@ async def test_no_history_data( }, ): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -251,6 +259,7 @@ async def test_double_sensor_data(hass, get_data, get_printer_objects_list): get_data["status"]["heater_fan controller_fan"] = {"speed": 0.1234} config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -274,6 +283,7 @@ async def test_no_fan_sensor(hass, get_data, get_printer_objects_list): get_printer_objects_list["objects"].remove("fan") config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -285,6 +295,7 @@ async def test_rounding_fan(hass, get_data): get_data["status"]["fan"]["speed"] = 0.33333333333 config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() diff --git a/tests/test_switch.py b/tests/test_switch.py index 4c8a182..8755ba0 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -34,6 +34,7 @@ def bypass_connect_client_fixture(): ) async def test_switch_turn_on(hass, switch, switch_type, get_default_api_response): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done() @@ -74,6 +75,7 @@ async def test_switch_turn_on(hass, switch, switch_type, get_default_api_respons ) async def test_switch_turn_off(hass, switch, switch_type, get_default_api_response): config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) assert await async_setup_entry(hass, config_entry) await hass.async_block_till_done()