From f19d489fc61971d990905095e5a5e97e88b5b9f9 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 1 Aug 2022 17:04:36 +0200 Subject: [PATCH] UT: Use HTTPStatus in test_island_mode --- .../monkey_island/cc/resources/test_island_mode.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index 8635784a4..642c5c936 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -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