Use http.HTTPStatus in components/f* (#58244)
This commit is contained in:
parent
4369b0b8be
commit
b1360ffafb
11 changed files with 61 additions and 63 deletions
|
@ -1,4 +1,5 @@
|
|||
"""The tests for the facebox component."""
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import Mock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
|
@ -15,9 +16,6 @@ from homeassistant.const import (
|
|||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTP_OK,
|
||||
HTTP_UNAUTHORIZED,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
@ -120,10 +118,10 @@ def test_check_box_health(caplog):
|
|||
"""Test check box health."""
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/healthz"
|
||||
mock_req.get(url, status_code=HTTP_OK, json=MOCK_HEALTH)
|
||||
mock_req.get(url, status_code=HTTPStatus.OK, json=MOCK_HEALTH)
|
||||
assert fb.check_box_health(url, "user", "pass") == MOCK_BOX_ID
|
||||
|
||||
mock_req.get(url, status_code=HTTP_UNAUTHORIZED)
|
||||
mock_req.get(url, status_code=HTTPStatus.UNAUTHORIZED)
|
||||
assert fb.check_box_health(url, None, None) is None
|
||||
assert "AuthenticationError on facebox" in caplog.text
|
||||
|
||||
|
@ -238,7 +236,7 @@ async def test_process_image_errors(hass, mock_healthybox, mock_image, caplog):
|
|||
# Now test with bad auth.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/check"
|
||||
mock_req.register_uri("POST", url, status_code=HTTP_UNAUTHORIZED)
|
||||
mock_req.register_uri("POST", url, status_code=HTTPStatus.UNAUTHORIZED)
|
||||
data = {ATTR_ENTITY_ID: VALID_ENTITY_ID}
|
||||
await hass.services.async_call(ip.DOMAIN, ip.SERVICE_SCAN, service_data=data)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -259,7 +257,7 @@ async def test_teach_service(
|
|||
# Test successful teach.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_OK)
|
||||
mock_req.post(url, status_code=HTTPStatus.OK)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
ATTR_NAME: MOCK_NAME,
|
||||
|
@ -273,7 +271,7 @@ async def test_teach_service(
|
|||
# Now test with bad auth.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_UNAUTHORIZED)
|
||||
mock_req.post(url, status_code=HTTPStatus.UNAUTHORIZED)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
ATTR_NAME: MOCK_NAME,
|
||||
|
@ -288,7 +286,7 @@ async def test_teach_service(
|
|||
# Now test the failed teaching.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_BAD_REQUEST, text=MOCK_ERROR_NO_FACE)
|
||||
mock_req.post(url, status_code=HTTPStatus.BAD_REQUEST, text=MOCK_ERROR_NO_FACE)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
ATTR_NAME: MOCK_NAME,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue