Use http.HTTPStatus in components/m* (#58251)

This commit is contained in:
Ville Skyttä 2021-10-23 00:54:36 +03:00 committed by GitHub
parent b49b975999
commit 77120a5137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 119 additions and 112 deletions

View file

@ -1,4 +1,5 @@
"""Webhook tests for mobile_app."""
from http import HTTPStatus
from unittest.mock import patch
import pytest
@ -76,7 +77,7 @@ async def test_webhook_handle_render_template(create_registrations, webhook_clie
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
json = await resp.json()
assert json == {
@ -97,7 +98,7 @@ async def test_webhook_handle_call_services(hass, create_registrations, webhook_
json=CALL_SERVICE,
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert len(calls) == 1
@ -117,7 +118,7 @@ async def test_webhook_handle_fire_event(hass, create_registrations, webhook_cli
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]), json=FIRE_EVENT
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
json = await resp.json()
assert json == {}
@ -131,7 +132,7 @@ async def test_webhook_update_registration(webhook_client, authed_api_client):
"/api/mobile_app/registrations", json=REGISTER_CLEARTEXT
)
assert register_resp.status == 201
assert register_resp.status == HTTPStatus.CREATED
register_json = await register_resp.json()
webhook_id = register_json[CONF_WEBHOOK_ID]
@ -142,7 +143,7 @@ async def test_webhook_update_registration(webhook_client, authed_api_client):
f"/api/webhook/{webhook_id}", json=update_container
)
assert update_resp.status == 200
assert update_resp.status == HTTPStatus.OK
update_json = await update_resp.json()
assert update_json["app_version"] == "2.0.0"
assert CONF_WEBHOOK_ID not in update_json
@ -180,7 +181,7 @@ async def test_webhook_handle_get_zones(hass, create_registrations, webhook_clie
json={"type": "get_zones"},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
json = await resp.json()
assert len(json) == 3
@ -206,7 +207,7 @@ async def test_webhook_handle_get_config(hass, create_registrations, webhook_cli
json={"type": "get_config"},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
json = await resp.json()
if "components" in json:
@ -239,7 +240,7 @@ async def test_webhook_returns_error_incorrect_json(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]), data="not json"
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
json = await resp.json()
assert json == {}
assert "invalid JSON" in caplog.text
@ -256,7 +257,7 @@ async def test_webhook_handle_decryption(webhook_client, create_registrations):
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
webhook_json = await resp.json()
assert "encrypted_data" in webhook_json
@ -273,7 +274,7 @@ async def test_webhook_requires_encryption(webhook_client, create_registrations)
json=RENDER_TEMPLATE,
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
webhook_json = await resp.json()
assert "error" in webhook_json
@ -291,7 +292,7 @@ async def test_webhook_update_location(hass, webhook_client, create_registration
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
state = hass.states.get("device_tracker.test_1_2")
assert state is not None
@ -310,7 +311,7 @@ async def test_webhook_enable_encryption(hass, webhook_client, create_registrati
json={"type": "enable_encryption"},
)
assert enable_enc_resp.status == 200
assert enable_enc_resp.status == HTTPStatus.OK
enable_enc_json = await enable_enc_resp.json()
assert len(enable_enc_json) == 1
@ -323,7 +324,7 @@ async def test_webhook_enable_encryption(hass, webhook_client, create_registrati
json=RENDER_TEMPLATE,
)
assert enc_required_resp.status == 400
assert enc_required_resp.status == HTTPStatus.BAD_REQUEST
enc_required_json = await enc_required_resp.json()
assert "error" in enc_required_json
@ -340,7 +341,7 @@ async def test_webhook_enable_encryption(hass, webhook_client, create_registrati
enc_resp = await webhook_client.post(f"/api/webhook/{webhook_id}", json=container)
assert enc_resp.status == 200
assert enc_resp.status == HTTPStatus.OK
enc_json = await enc_resp.json()
assert "encrypted_data" in enc_json
@ -364,7 +365,7 @@ async def test_webhook_camera_stream_non_existent(
},
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
webhook_json = await resp.json()
assert webhook_json["success"] is False
@ -385,7 +386,7 @@ async def test_webhook_camera_stream_non_hls(
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
webhook_json = await resp.json()
assert webhook_json["hls_path"] is None
assert (
@ -416,7 +417,7 @@ async def test_webhook_camera_stream_stream_available(
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
webhook_json = await resp.json()
assert webhook_json["hls_path"] == "/api/streams/some_hls_stream"
assert webhook_json["mjpeg_path"] == "/api/camera_proxy_stream/camera.stream_camera"
@ -444,7 +445,7 @@ async def test_webhook_camera_stream_stream_available_but_errors(
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
webhook_json = await resp.json()
assert webhook_json["hls_path"] is None
assert webhook_json["mjpeg_path"] == "/api/camera_proxy_stream/camera.stream_camera"
@ -466,7 +467,7 @@ async def test_webhook_handle_scan_tag(hass, create_registrations, webhook_clien
json={"type": "scan_tag", "data": {"tag_id": "mock-tag-id"}},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
json = await resp.json()
assert json == {}
@ -496,7 +497,7 @@ async def test_register_sensor_limits_state_class(
},
)
assert reg_resp.status == 201
assert reg_resp.status == HTTPStatus.CREATED
reg_resp = await webhook_client.post(
webhook_url,
@ -513,4 +514,4 @@ async def test_register_sensor_limits_state_class(
)
# This means it was ignored.
assert reg_resp.status == 200
assert reg_resp.status == HTTPStatus.OK