From c85ac0f6109b7bc1fe28391d1f08c51d46965551 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 19 May 2021 09:30:20 +0300 Subject: [PATCH] Moved unit test files and profiling test decorator into test directory away from production code --- monkey/monkey_island/cc/test_common/__init__.py | 0 monkey/monkey_island/cc/test_common/fixtures/__init__.py | 4 ---- monkey/tests/monkey_island/cc/conftest.py | 2 +- .../fixtures => tests/monkey_island/cc}/fixture_enum.py | 0 monkey/tests/monkey_island/cc/models/test_monkey.py | 2 +- .../cc/models/zero_trust/test_monkey_finding.py | 2 +- .../cc/models/zero_trust/test_scoutsuite_finding.py | 2 +- .../monkey_island/cc}/mongomock_fixtures.py | 0 .../monkey_island/cc/services/edge/test_edge_service.py | 2 +- .../monkey_findings/test_monkey_zt_finding_service.py | 2 +- .../zero_trust/scoutsuite/test_scoutsuite_auth_service.py | 2 +- .../scoutsuite/test_scoutsuite_zt_finding_service.py | 2 +- .../zero_trust/zero_trust_report/test_finding_service.py | 2 +- .../zero_trust/zero_trust_report/test_pillar_service.py | 2 +- .../zero_trust/zero_trust_report/test_principle_service.py | 2 +- .../cc/test_common => tests}/profiling/README.md | 6 +++--- .../test_common => tests}/profiling/profiler_decorator.py | 0 17 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 monkey/monkey_island/cc/test_common/__init__.py delete mode 100644 monkey/monkey_island/cc/test_common/fixtures/__init__.py rename monkey/{monkey_island/cc/test_common/fixtures => tests/monkey_island/cc}/fixture_enum.py (100%) rename monkey/{monkey_island/cc/test_common/fixtures => tests/monkey_island/cc}/mongomock_fixtures.py (100%) rename monkey/{monkey_island/cc/test_common => tests}/profiling/README.md (76%) rename monkey/{monkey_island/cc/test_common => tests}/profiling/profiler_decorator.py (100%) diff --git a/monkey/monkey_island/cc/test_common/__init__.py b/monkey/monkey_island/cc/test_common/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/monkey_island/cc/test_common/fixtures/__init__.py b/monkey/monkey_island/cc/test_common/fixtures/__init__.py deleted file mode 100644 index fd208655a..000000000 --- a/monkey/monkey_island/cc/test_common/fixtures/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# Without these imports pytests can't use fixtures, -# because they are not found -from .fixture_enum import FixtureEnum # noqa: F401 -from .mongomock_fixtures import * # noqa: F401,F403 diff --git a/monkey/tests/monkey_island/cc/conftest.py b/monkey/tests/monkey_island/cc/conftest.py index 0ed1533ab..b9aabe4ef 100644 --- a/monkey/tests/monkey_island/cc/conftest.py +++ b/monkey/tests/monkey_island/cc/conftest.py @@ -1,3 +1,3 @@ # Without these imports pytests can't use fixtures, # because they are not found -from monkey_island.cc.test_common.fixtures import * # noqa: F401,F403 +from tests.monkey_island.cc.mongomock_fixtures import * # noqa: F401,F403 diff --git a/monkey/monkey_island/cc/test_common/fixtures/fixture_enum.py b/monkey/tests/monkey_island/cc/fixture_enum.py similarity index 100% rename from monkey/monkey_island/cc/test_common/fixtures/fixture_enum.py rename to monkey/tests/monkey_island/cc/fixture_enum.py diff --git a/monkey/tests/monkey_island/cc/models/test_monkey.py b/monkey/tests/monkey_island/cc/models/test_monkey.py index 542309ae5..503c2a6f3 100644 --- a/monkey/tests/monkey_island/cc/models/test_monkey.py +++ b/monkey/tests/monkey_island/cc/models/test_monkey.py @@ -3,10 +3,10 @@ import uuid from time import sleep import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from monkey_island.cc.models.monkey import Monkey, MonkeyNotFoundError from monkey_island.cc.models.monkey_ttl import MonkeyTtl -from monkey_island.cc.test_common.fixtures import FixtureEnum logger = logging.getLogger(__name__) diff --git a/monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py b/monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py index f7cf39d22..04482b0de 100644 --- a/monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py +++ b/monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py @@ -1,12 +1,12 @@ import pytest from mongoengine import ValidationError +from tests.monkey_island.cc.fixture_enum import FixtureEnum import common.common_consts.zero_trust_consts as zero_trust_consts from monkey_island.cc.models.zero_trust.event import Event from monkey_island.cc.models.zero_trust.finding import Finding from monkey_island.cc.models.zero_trust.monkey_finding import MonkeyFinding from monkey_island.cc.models.zero_trust.monkey_finding_details import MonkeyFindingDetails -from monkey_island.cc.test_common.fixtures import FixtureEnum MONKEY_FINDING_DETAIL_MOCK = MonkeyFindingDetails() MONKEY_FINDING_DETAIL_MOCK.events = ["mock1", "mock2"] diff --git a/monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py b/monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py index 07809cd90..5c45d773e 100644 --- a/monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py +++ b/monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py @@ -1,5 +1,6 @@ import pytest from mongoengine import ValidationError +from tests.monkey_island.cc.fixture_enum import FixtureEnum import common.common_consts.zero_trust_consts as zero_trust_consts from monkey_island.cc.models.zero_trust.finding import Finding @@ -7,7 +8,6 @@ from monkey_island.cc.models.zero_trust.monkey_finding_details import MonkeyFind from monkey_island.cc.models.zero_trust.scoutsuite_finding import ScoutSuiteFinding from monkey_island.cc.models.zero_trust.scoutsuite_finding_details import ScoutSuiteFindingDetails from monkey_island.cc.services.zero_trust.test_common.scoutsuite_finding_data import RULES -from monkey_island.cc.test_common.fixtures import FixtureEnum MONKEY_FINDING_DETAIL_MOCK = MonkeyFindingDetails() MONKEY_FINDING_DETAIL_MOCK.events = ["mock1", "mock2"] diff --git a/monkey/monkey_island/cc/test_common/fixtures/mongomock_fixtures.py b/monkey/tests/monkey_island/cc/mongomock_fixtures.py similarity index 100% rename from monkey/monkey_island/cc/test_common/fixtures/mongomock_fixtures.py rename to monkey/tests/monkey_island/cc/mongomock_fixtures.py diff --git a/monkey/tests/monkey_island/cc/services/edge/test_edge_service.py b/monkey/tests/monkey_island/cc/services/edge/test_edge_service.py index 99ecf52d7..cc4f7f4a0 100644 --- a/monkey/tests/monkey_island/cc/services/edge/test_edge_service.py +++ b/monkey/tests/monkey_island/cc/services/edge/test_edge_service.py @@ -2,10 +2,10 @@ import logging import pytest from mongomock import ObjectId +from tests.monkey_island.cc.fixture_enum import FixtureEnum from monkey_island.cc.models.edge import Edge from monkey_island.cc.services.edge.edge import EdgeService -from monkey_island.cc.test_common.fixtures import FixtureEnum logger = logging.getLogger(__name__) diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py index b92a52ae1..2d42cdf61 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py @@ -1,6 +1,7 @@ from datetime import datetime import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from common.common_consts import zero_trust_consts from monkey_island.cc.models.zero_trust.event import Event @@ -9,7 +10,6 @@ from monkey_island.cc.models.zero_trust.monkey_finding import MonkeyFinding from monkey_island.cc.services.zero_trust.monkey_findings.monkey_zt_finding_service import ( MonkeyZTFindingService, ) -from monkey_island.cc.test_common.fixtures import FixtureEnum EVENTS = [ Event.create_event( diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py index 00eae32e7..4b61d6396 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock import dpath.util import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from common.config_value_paths import AWS_KEYS_PATH from monkey_island.cc.database import mongo @@ -10,7 +11,6 @@ from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service import ( is_aws_keys_setup, ) -from monkey_island.cc.test_common.fixtures import FixtureEnum class MockObject: diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py index de7b5635e..64febd08c 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py @@ -1,4 +1,5 @@ import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from monkey_island.cc.models.zero_trust.finding import Finding from monkey_island.cc.models.zero_trust.scoutsuite_finding import ScoutSuiteFinding @@ -9,7 +10,6 @@ from monkey_island.cc.services.zero_trust.test_common.scoutsuite_finding_data im RULES, SCOUTSUITE_FINDINGS, ) -from monkey_island.cc.test_common.fixtures import FixtureEnum class TestScoutSuiteZTFindingService: diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py index 37d432bf4..46946c7ba 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from common.common_consts.zero_trust_consts import ( DEVICES, @@ -22,7 +23,6 @@ from monkey_island.cc.services.zero_trust.zero_trust_report.finding_service impo EnrichedFinding, FindingService, ) -from monkey_island.cc.test_common.fixtures.fixture_enum import FixtureEnum @pytest.mark.usefixtures(FixtureEnum.USES_DATABASE) diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py index 3b6da848f..51c94cb32 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py @@ -1,6 +1,7 @@ from typing import List import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from common.common_consts import zero_trust_consts from common.common_consts.zero_trust_consts import ( @@ -16,7 +17,6 @@ from monkey_island.cc.services.zero_trust.zero_trust_report.pillar_service impor from monkey_island.cc.services.zero_trust.zero_trust_report.test_common.example_finding_data import ( # noqa: E501 save_example_findings, ) -from monkey_island.cc.test_common.fixtures import FixtureEnum @pytest.mark.usefixtures(FixtureEnum.USES_DATABASE) diff --git a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py index 7eb6b19cd..be744b3b0 100644 --- a/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py +++ b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py @@ -1,4 +1,5 @@ import pytest +from tests.monkey_island.cc.fixture_enum import FixtureEnum from common.common_consts import zero_trust_consts from monkey_island.cc.services.zero_trust.test_common.finding_data import ( @@ -8,7 +9,6 @@ from monkey_island.cc.services.zero_trust.test_common.finding_data import ( from monkey_island.cc.services.zero_trust.zero_trust_report.principle_service import ( PrincipleService, ) -from monkey_island.cc.test_common.fixtures import FixtureEnum EXPECTED_DICT = { "test_pillar1": [ diff --git a/monkey/monkey_island/cc/test_common/profiling/README.md b/monkey/tests/profiling/README.md similarity index 76% rename from monkey/monkey_island/cc/test_common/profiling/README.md rename to monkey/tests/profiling/README.md index d0cb92bfa..d22d2188c 100644 --- a/monkey/monkey_island/cc/test_common/profiling/README.md +++ b/monkey/tests/profiling/README.md @@ -1,9 +1,9 @@ # Profiling island -To profile specific methods on island a `@profile(sort_args=['cumulative'], print_args=[100])` -decorator can be used. +To profile specific methods on island a `@profile(sort_args=['cumulative'], print_args=[100])` +decorator can be used. Use it as a parameterised decorator(`@profile()`). After decorated method is used, a file will appear in a directory provided in `profiler_decorator.py`. Filename describes the path of the method that was profiled. For example if method `monkey_island/cc/resources/netmap.get` -was profiled, then the results of this profiling will appear in +was profiled, then the results of this profiling will appear in `monkey_island_cc_resources_netmap_get`. diff --git a/monkey/monkey_island/cc/test_common/profiling/profiler_decorator.py b/monkey/tests/profiling/profiler_decorator.py similarity index 100% rename from monkey/monkey_island/cc/test_common/profiling/profiler_decorator.py rename to monkey/tests/profiling/profiler_decorator.py