Add config message items selector to imap option flow (#115108)
* Update const.py * Update config_flow.py * Update coordinator.py * Update coordinator.py * Update strings.json * Update config_flow.py * Update const.py * Update coordinator.py * Update config_flow.py * Update config_flow.py * Update test_diagnostics.py * Update const.py * Update test_init.py * Update test_diagnostics.py * Update test_diagnostics.py * Update test_diagnostics.py * Update test_init.py * Update test_diagnostics.py * Update test_init.py * Update test_diagnostics.py * Update test_diagnostics.py * Update test_diagnostics.py * Update test_config_flow.py * Update config_flow.py * Update test_config_flow.py * Update test_init.py * Update const.py * Only make text and headers optional * Add message data tests * Add message data test * Update test_config_flow.py * Update test message data * Fix ruff * Fix ruff * Update test_init.py * Update strings.json --------- Co-authored-by: jbouwh <jan@jbsoft.nl> Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
parent
f23e48f373
commit
fc1ebdaaa3
7 changed files with 112 additions and 10 deletions
|
@ -29,11 +29,13 @@ MOCK_CONFIG = {
|
|||
"charset": "utf-8",
|
||||
"folder": "INBOX",
|
||||
"search": "UnSeen UnDeleted",
|
||||
"event_message_data": ["text", "headers"],
|
||||
}
|
||||
|
||||
MOCK_OPTIONS = {
|
||||
"folder": "INBOX",
|
||||
"search": "UnSeen UnDeleted",
|
||||
"event_message_data": ["text", "headers"],
|
||||
}
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
@ -504,6 +506,38 @@ async def test_config_flow_with_cipherlist_and_ssl_verify(
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_message_data", [[], ["headers"], ["text", "headers"]])
|
||||
async def test_config_flow_with_event_message_data(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, event_message_data: list
|
||||
) -> None:
|
||||
"""Test with different message data."""
|
||||
config = MOCK_CONFIG.copy()
|
||||
config["event_message_data"] = event_message_data
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": False},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.imap.config_flow.connect_to_server"
|
||||
) as mock_client:
|
||||
mock_client.return_value.search.return_value = (
|
||||
"OK",
|
||||
[b""],
|
||||
)
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "email@email.com"
|
||||
assert result2["data"] == config
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_config_flow_from_with_advanced_settings(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
|
|
|
@ -66,6 +66,10 @@ async def test_entry_diagnostics(
|
|||
"port": 993,
|
||||
"charset": "utf-8",
|
||||
"folder": "INBOX",
|
||||
"event_message_data": [
|
||||
"text",
|
||||
"headers",
|
||||
],
|
||||
"search": "UnSeen UnDeleted",
|
||||
"custom_event_data_template": "{{ 4 * 4 }}",
|
||||
}
|
||||
|
|
|
@ -674,6 +674,41 @@ async def test_message_is_truncated(
|
|||
assert len(event_data["text"]) == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize("imap_search", [TEST_SEARCH_RESPONSE])
|
||||
@pytest.mark.parametrize(
|
||||
"imap_fetch", [(TEST_FETCH_RESPONSE_TEXT_PLAIN)], ids=["plain"]
|
||||
)
|
||||
@pytest.mark.parametrize("imap_has_capability", [True, False], ids=["push", "poll"])
|
||||
@pytest.mark.parametrize("event_message_data", [[], ["text"], ["text", "headers"]])
|
||||
async def test_message_data(
|
||||
hass: HomeAssistant,
|
||||
mock_imap_protocol: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
event_message_data: list,
|
||||
) -> None:
|
||||
"""Test with different message data."""
|
||||
event_called = async_capture_events(hass, "imap_content")
|
||||
|
||||
config = MOCK_CONFIG.copy()
|
||||
# Mock different message data
|
||||
config["event_message_data"] = event_message_data
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data=config)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
# Make sure we have had one update (when polling)
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=5))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.imap_email_email_com")
|
||||
# We should have received one message
|
||||
assert state is not None
|
||||
assert state.state == "1"
|
||||
assert len(event_called) == 1
|
||||
|
||||
event_data = event_called[0].data
|
||||
assert set(event_message_data).issubset(set(event_data))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("imap_search", "imap_fetch"),
|
||||
[(TEST_SEARCH_RESPONSE, TEST_FETCH_RESPONSE_TEXT_PLAIN)],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue