Added finding db cleaning for the UTs in IslandTestCase
This commit is contained in:
parent
fb893089d9
commit
bfcd469e04
monkey/monkey_island/cc
|
@ -8,7 +8,7 @@ from monkey_island.cc.testing.IslandTestCase import IslandTestCase
|
||||||
class TestEvent(IslandTestCase):
|
class TestEvent(IslandTestCase):
|
||||||
def test_create_event(self):
|
def test_create_event(self):
|
||||||
self.fail_if_not_testing_env()
|
self.fail_if_not_testing_env()
|
||||||
self.clean_monkey_db()
|
self.clean_finding_db()
|
||||||
|
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
Event.create_event(
|
Event.create_event(
|
||||||
|
@ -27,5 +27,5 @@ class TestEvent(IslandTestCase):
|
||||||
_ = Event.create_event(
|
_ = Event.create_event(
|
||||||
title="skjs",
|
title="skjs",
|
||||||
message="bla bla",
|
message="bla bla",
|
||||||
event_type=EVENT_TYPE_ISLAND # Unknown event type
|
event_type=EVENT_TYPE_ISLAND
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from mongoengine import ValidationError
|
from mongoengine import ValidationError
|
||||||
|
|
||||||
from common.data.zero_trust_consts import TEST_SEGMENTATION, STATUS_CONCLUSIVE, NETWORKS, EVENT_TYPE_MONKEY_NETWORK
|
from common.data.zero_trust_consts import *
|
||||||
from finding import Finding, UnknownTest
|
from finding import Finding
|
||||||
from monkey_island.cc.models.event import Event
|
from monkey_island.cc.models.event import Event
|
||||||
|
|
||||||
from monkey_island.cc.testing.IslandTestCase import IslandTestCase
|
from monkey_island.cc.testing.IslandTestCase import IslandTestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,17 +16,17 @@ class TestFinding(IslandTestCase):
|
||||||
"""
|
"""
|
||||||
def test_save_finding_validation(self):
|
def test_save_finding_validation(self):
|
||||||
self.fail_if_not_testing_env()
|
self.fail_if_not_testing_env()
|
||||||
self.clean_monkey_db()
|
self.clean_finding_db()
|
||||||
|
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
_ = Finding.save_finding(test="bla bla", status="Conclusive", events=[])
|
_ = Finding.save_finding(test="bla bla", status=STATUS_CONCLUSIVE, events=[])
|
||||||
|
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
_ = Finding.save_finding(test=TEST_SEGMENTATION, status="bla bla", events=[])
|
_ = Finding.save_finding(test=TEST_SEGMENTATION, status="bla bla", events=[])
|
||||||
|
|
||||||
def test_save_finding_sanity(self):
|
def test_save_finding_sanity(self):
|
||||||
self.fail_if_not_testing_env()
|
self.fail_if_not_testing_env()
|
||||||
self.clean_monkey_db()
|
self.clean_finding_db()
|
||||||
|
|
||||||
self.assertEquals(len(Finding.objects(test=TEST_SEGMENTATION)), 0)
|
self.assertEquals(len(Finding.objects(test=TEST_SEGMENTATION)), 0)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from monkey_island.cc.environment.environment import env
|
from monkey_island.cc.environment.environment import env
|
||||||
from monkey_island.cc.models import Monkey
|
from monkey_island.cc.models import Monkey
|
||||||
|
from monkey_island.cc.models.finding import Finding
|
||||||
|
|
||||||
|
|
||||||
class IslandTestCase(unittest.TestCase):
|
class IslandTestCase(unittest.TestCase):
|
||||||
|
@ -10,3 +11,7 @@ class IslandTestCase(unittest.TestCase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clean_monkey_db():
|
def clean_monkey_db():
|
||||||
Monkey.objects().delete()
|
Monkey.objects().delete()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def clean_finding_db():
|
||||||
|
Finding.objects().delete()
|
||||||
|
|
Loading…
Reference in New Issue