From 9310463f44886a72c542452c6f10214177892ed0 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Tue, 13 Jul 2021 12:27:00 +0200 Subject: [PATCH] UT: Refactor island mode test for set model --- .../monkey_island/cc/resources/conftest.py | 13 ------------- .../monkey_island/cc/resources/test_island_mode.py | 11 +++++++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py index 2421e00aa..0e82fe163 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py @@ -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() 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 13ded4799..5c4362c64 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 @@ -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 )