Skip to content

Commit

Permalink
update testing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolivierarsenault committed Oct 29, 2023
1 parent 25610db commit 235186f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down
3 changes: 3 additions & 0 deletions tests/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down
12 changes: 12 additions & 0 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)
1 change: 1 addition & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 11 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 235186f

Please sign in to comment.