Fix for whois - quota exceeded and private registry (#141060)

* Fix for quota exceeded and private registry

* Add tests
This commit is contained in:
Ted van den Brink 2025-03-25 09:24:32 +01:00 committed by GitHub
parent 5fd219fc9e
commit b3e054d5a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 101 additions and 1 deletions

View File

@ -11,6 +11,8 @@ from whois.exceptions import (
UnknownDateFormat,
UnknownTld,
WhoisCommandFailed,
WhoisPrivateRegistry,
WhoisQuotaExceeded,
)
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
@ -48,6 +50,10 @@ class WhoisFlowHandler(ConfigFlow, domain=DOMAIN):
errors["base"] = "unexpected_response"
except UnknownDateFormat:
errors["base"] = "unknown_date_format"
except WhoisPrivateRegistry:
errors["base"] = "private_registry"
except WhoisQuotaExceeded:
errors["base"] = "quota_exceeded"
else:
return self.async_create_entry(
title=self.imported_name or user_input[CONF_DOMAIN],

View File

@ -11,7 +11,9 @@
"unexpected_response": "Unexpected response from whois server",
"unknown_date_format": "Unknown date format in whois server response",
"unknown_tld": "The given TLD is unknown or not available to this integration",
"whois_command_failed": "Whois command failed: could not retrieve whois information"
"whois_command_failed": "Whois command failed: could not retrieve whois information",
"private_registry": "The given domain is registered in a private registry and cannot be monitored",
"quota_exceeded": "Your whois quota has been exceeded for this TLD"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"

View File

@ -175,6 +175,94 @@
'version': 1,
})
# ---
# name: test_full_flow_with_error[WhoisPrivateRegistry-private_registry]
FlowResultSnapshot({
'context': dict({
'source': 'user',
'unique_id': 'example.com',
}),
'data': dict({
'domain': 'example.com',
}),
'description': None,
'description_placeholders': None,
'flow_id': <ANY>,
'handler': 'whois',
'minor_version': 1,
'options': dict({
}),
'result': ConfigEntrySnapshot({
'data': dict({
'domain': 'example.com',
}),
'disabled_by': None,
'discovery_keys': dict({
}),
'domain': 'whois',
'entry_id': <ANY>,
'minor_version': 1,
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'subentries': list([
]),
'title': 'Example.com',
'unique_id': 'example.com',
'version': 1,
}),
'subentries': tuple(
),
'title': 'Example.com',
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
'version': 1,
})
# ---
# name: test_full_flow_with_error[WhoisQuotaExceeded-quota_exceeded]
FlowResultSnapshot({
'context': dict({
'source': 'user',
'unique_id': 'example.com',
}),
'data': dict({
'domain': 'example.com',
}),
'description': None,
'description_placeholders': None,
'flow_id': <ANY>,
'handler': 'whois',
'minor_version': 1,
'options': dict({
}),
'result': ConfigEntrySnapshot({
'data': dict({
'domain': 'example.com',
}),
'disabled_by': None,
'discovery_keys': dict({
}),
'domain': 'whois',
'entry_id': <ANY>,
'minor_version': 1,
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'subentries': list([
]),
'title': 'Example.com',
'unique_id': 'example.com',
'version': 1,
}),
'subentries': tuple(
),
'title': 'Example.com',
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
'version': 1,
})
# ---
# name: test_full_user_flow
FlowResultSnapshot({
'context': dict({

View File

@ -9,6 +9,8 @@ from whois.exceptions import (
UnknownDateFormat,
UnknownTld,
WhoisCommandFailed,
WhoisPrivateRegistry,
WhoisQuotaExceeded,
)
from homeassistant.components.whois.const import DOMAIN
@ -52,6 +54,8 @@ async def test_full_user_flow(
(FailedParsingWhoisOutput, "unexpected_response"),
(UnknownDateFormat, "unknown_date_format"),
(WhoisCommandFailed, "whois_command_failed"),
(WhoisPrivateRegistry, "private_registry"),
(WhoisQuotaExceeded, "quota_exceeded"),
],
)
async def test_full_flow_with_error(