forked from p15670423/monkey
UT: Refactor island mode test for set model
This commit is contained in:
parent
81a8ccf673
commit
9310463f44
|
@ -1,13 +1,11 @@
|
|||
import flask_jwt_extended
|
||||
import flask_restful
|
||||
import mongoengine
|
||||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
import monkey_island.cc.app
|
||||
import monkey_island.cc.resources.auth.auth
|
||||
import monkey_island.cc.resources.island_mode
|
||||
from monkey_island.cc.models.island_mode_model import IslandMode
|
||||
from monkey_island.cc.services.representations import output_json
|
||||
|
||||
|
||||
|
@ -32,14 +30,3 @@ def mock_init_app():
|
|||
monkey_island.cc.app.init_api_resources(api)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def fake_mongo():
|
||||
mongoengine.disconnect()
|
||||
mongoengine.connect("mongoenginetest", host="mongomock://localhost")
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def uses_database():
|
||||
IslandMode.objects().delete()
|
||||
|
|
|
@ -5,6 +5,11 @@ import pytest
|
|||
from monkey_island.cc.models.island_mode_model import IslandMode
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def uses_database():
|
||||
IslandMode.objects().delete()
|
||||
|
||||
|
||||
def test_island_mode_post(flask_client):
|
||||
resp = flask_client.post(
|
||||
"/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True
|
||||
|
@ -19,16 +24,14 @@ def test_island_mode_post__invalid_mode(flask_client):
|
|||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_database")
|
||||
def test_island_mode_post__set_model(flask_client):
|
||||
def test_island_mode_post__set_model(flask_client, uses_database):
|
||||
flask_client.post(
|
||||
"/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True
|
||||
)
|
||||
assert IslandMode.objects[0].mode == "ransomware"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_database")
|
||||
def test_island_mode_post__set_invalid_model(flask_client):
|
||||
def test_island_mode_post__set_invalid_model(flask_client, uses_database):
|
||||
flask_client.post(
|
||||
"/api/island-mode", data=json.dumps({"mode": "bogus mode"}), follow_redirects=True
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue