UT: Pass headers in PUT requests in test_island_mode.py

This commit is contained in:
Shreya Malviya 2022-08-03 13:35:02 +05:30
parent d56951f152
commit 9c17cf44b1
1 changed files with 19 additions and 4 deletions

View File

@ -38,14 +38,20 @@ def flask_client(build_flask_client):
) )
def test_island_mode_post(flask_client, mode): def test_island_mode_post(flask_client, mode):
resp = flask_client.put( resp = flask_client.put(
IslandModeResource.urls[0], data=json.dumps(mode), follow_redirects=True IslandModeResource.urls[0],
data=json.dumps(mode),
headers={"Content-Type": "application/json"},
follow_redirects=True,
) )
assert resp.status_code == HTTPStatus.NO_CONTENT assert resp.status_code == HTTPStatus.NO_CONTENT
def test_island_mode_post__invalid_mode(flask_client): def test_island_mode_post__invalid_mode(flask_client):
resp = flask_client.put( resp = flask_client.put(
IslandModeResource.urls[0], data=json.dumps("bogus mode"), follow_redirects=True IslandModeResource.urls[0],
data=json.dumps("bogus mode"),
headers={"Content-Type": "application/json"},
follow_redirects=True,
) )
assert resp.status_code == HTTPStatus.UNPROCESSABLE_ENTITY assert resp.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
@ -61,6 +67,7 @@ def test_island_mode_post__internal_server_error(build_flask_client):
resp = flask_client.put( resp = flask_client.put(
IslandModeResource.urls[0], IslandModeResource.urls[0],
data=json.dumps(IslandMode.RANSOMWARE.value), data=json.dumps(IslandMode.RANSOMWARE.value),
headers={"Content-Type": "application/json"},
follow_redirects=True, follow_redirects=True,
) )
@ -69,7 +76,12 @@ def test_island_mode_post__internal_server_error(build_flask_client):
@pytest.mark.parametrize("mode", [IslandMode.RANSOMWARE.value, IslandMode.ADVANCED.value]) @pytest.mark.parametrize("mode", [IslandMode.RANSOMWARE.value, IslandMode.ADVANCED.value])
def test_island_mode_endpoint(flask_client, mode): def test_island_mode_endpoint(flask_client, mode):
flask_client.put(IslandModeResource.urls[0], data=json.dumps(mode), follow_redirects=True) flask_client.put(
IslandModeResource.urls[0],
data=json.dumps(mode),
headers={"Content-Type": "application/json"},
follow_redirects=True,
)
resp = flask_client.get(IslandModeResource.urls[0], follow_redirects=True) resp = flask_client.get(IslandModeResource.urls[0], follow_redirects=True)
assert resp.status_code == HTTPStatus.OK assert resp.status_code == HTTPStatus.OK
assert json.loads(resp.data) == mode assert json.loads(resp.data) == mode
@ -77,7 +89,10 @@ def test_island_mode_endpoint(flask_client, mode):
def test_island_mode_endpoint__invalid_mode(flask_client): def test_island_mode_endpoint__invalid_mode(flask_client):
resp_post = flask_client.put( resp_post = flask_client.put(
IslandModeResource.urls[0], data=json.dumps("bogus_mode"), follow_redirects=True IslandModeResource.urls[0],
data=json.dumps("bogus_mode"),
headers={"Content-Type": "application/json"},
follow_redirects=True,
) )
resp_get = flask_client.get(IslandModeResource.urls[0], follow_redirects=True) resp_get = flask_client.get(IslandModeResource.urls[0], follow_redirects=True)
assert resp_post.status_code == HTTPStatus.UNPROCESSABLE_ENTITY assert resp_post.status_code == HTTPStatus.UNPROCESSABLE_ENTITY