UT: Use HTTPStatus in test_island_mode

This commit is contained in:
Ilija Lazoroski 2022-08-01 17:04:36 +02:00
parent 8e62bef898
commit f19d489fc6
1 changed files with 7 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import json
from http import HTTPStatus
from unittest.mock import MagicMock
import pytest
@ -39,20 +40,20 @@ def test_island_mode_post(flask_client, mode):
resp = flask_client.put(
IslandModeResource.urls[0], data=json.dumps({"mode": mode}), follow_redirects=True
)
assert resp.status_code == 204
assert resp.status_code == HTTPStatus.NO_CONTENT
def test_island_mode_post__invalid_mode(flask_client):
resp = flask_client.put(
IslandModeResource.urls[0], data=json.dumps({"mode": "bogus mode"}), follow_redirects=True
)
assert resp.status_code == 422
assert resp.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
@pytest.mark.parametrize("invalid_json", ["42", "{test"])
def test_island_mode_post__invalid_json(flask_client, invalid_json):
resp = flask_client.put(IslandModeResource.urls[0], data="{test", follow_redirects=True)
assert resp.status_code == 400
assert resp.status_code == HTTPStatus.BAD_REQUEST
def test_island_mode_post__internal_server_error(build_flask_client):
@ -69,7 +70,7 @@ def test_island_mode_post__internal_server_error(build_flask_client):
follow_redirects=True,
)
assert resp.status_code == 500
assert resp.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
@pytest.mark.parametrize("mode", [IslandMode.RANSOMWARE.value, IslandMode.ADVANCED.value])
@ -78,7 +79,7 @@ def test_island_mode_endpoint(flask_client, mode):
IslandModeResource.urls[0], data=json.dumps({"mode": mode}), follow_redirects=True
)
resp = flask_client.get(IslandModeResource.urls[0], follow_redirects=True)
assert resp.status_code == 200
assert resp.status_code == HTTPStatus.OK
assert json.loads(resp.data)["mode"] == mode
@ -87,5 +88,5 @@ def test_island_mode_endpoint__invalid_mode(flask_client):
IslandModeResource.urls[0], data=json.dumps({"mode": "bogus_mode"}), follow_redirects=True
)
resp_get = flask_client.get(IslandModeResource.urls[0], follow_redirects=True)
assert resp_post.status_code == 422
assert resp_post.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
assert json.loads(resp_get.data)["mode"] == IslandMode.UNSET.value