forked from p15670423/monkey
UT: Change IEventRepository -> IAgentEventRepository
This commit is contained in:
parent
0dccbd32b6
commit
be612abb23
|
@ -12,7 +12,7 @@ from common.agent_event_serializers import (
|
|||
)
|
||||
from common.events import AbstractAgentEvent
|
||||
from monkey_island.cc.repository import (
|
||||
IEventRepository,
|
||||
IAgentEventRepository,
|
||||
MongoEventRepository,
|
||||
RemovalError,
|
||||
RetrievalError,
|
||||
|
@ -54,7 +54,7 @@ def mongo_client(event_serializer_registry):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mongo_repository(mongo_client, event_serializer_registry) -> IEventRepository:
|
||||
def mongo_repository(mongo_client, event_serializer_registry) -> IAgentEventRepository:
|
||||
return MongoEventRepository(mongo_client, event_serializer_registry)
|
||||
|
||||
|
||||
|
@ -76,7 +76,7 @@ def error_raising_mongo_client(mongo_client) -> mongomock.MongoClient:
|
|||
@pytest.fixture
|
||||
def error_raising_mongo_repository(
|
||||
error_raising_mongo_client, event_serializer_registry
|
||||
) -> IEventRepository:
|
||||
) -> IAgentEventRepository:
|
||||
return MongoEventRepository(error_raising_mongo_client, event_serializer_registry)
|
||||
|
||||
|
||||
|
@ -86,7 +86,7 @@ def assert_same_contents(a, b):
|
|||
assert item in b
|
||||
|
||||
|
||||
def test_mongo_event_repository__save_event(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__save_event(mongo_repository: IAgentEventRepository):
|
||||
event = FakeAgentEvent(source=uuid.uuid4())
|
||||
mongo_repository.save_event(event)
|
||||
events = mongo_repository.get_events()
|
||||
|
@ -95,7 +95,7 @@ def test_mongo_event_repository__save_event(mongo_repository: IEventRepository):
|
|||
|
||||
|
||||
def test_mongo_event_repository__save_event_raises(
|
||||
error_raising_mongo_repository: IEventRepository,
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
event = FakeAgentEvent(source=uuid.uuid4())
|
||||
|
||||
|
@ -103,20 +103,20 @@ def test_mongo_event_repository__save_event_raises(
|
|||
error_raising_mongo_repository.save_event(event)
|
||||
|
||||
|
||||
def test_mongo_event_repository__get_events(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__get_events(mongo_repository: IAgentEventRepository):
|
||||
events = mongo_repository.get_events()
|
||||
|
||||
assert_same_contents(events, EVENTS)
|
||||
|
||||
|
||||
def test_mongo_event_repository__get_events_raises(
|
||||
error_raising_mongo_repository: IEventRepository,
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
with pytest.raises(RetrievalError):
|
||||
error_raising_mongo_repository.get_events()
|
||||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_type(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__get_events_by_type(mongo_repository: IAgentEventRepository):
|
||||
events = mongo_repository.get_events_by_type(FakeAgentItemEvent)
|
||||
|
||||
expected_events = [EVENTS[3]]
|
||||
|
@ -124,13 +124,13 @@ def test_mongo_event_repository__get_events_by_type(mongo_repository: IEventRepo
|
|||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_type_raises(
|
||||
error_raising_mongo_repository: IEventRepository,
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
with pytest.raises(RetrievalError):
|
||||
error_raising_mongo_repository.get_events_by_type(FakeAgentItemEvent)
|
||||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_tag(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__get_events_by_tag(mongo_repository: IAgentEventRepository):
|
||||
events = mongo_repository.get_events_by_tag("bar")
|
||||
|
||||
expected_events = [EVENTS[1], EVENTS[2]]
|
||||
|
@ -138,13 +138,13 @@ def test_mongo_event_repository__get_events_by_tag(mongo_repository: IEventRepos
|
|||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_tag_raises(
|
||||
error_raising_mongo_repository: IEventRepository,
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
with pytest.raises(RetrievalError):
|
||||
error_raising_mongo_repository.get_events_by_tag("bar")
|
||||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_source(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__get_events_by_source(mongo_repository: IAgentEventRepository):
|
||||
source_event = EVENTS[2]
|
||||
events = mongo_repository.get_events_by_source(source_event.source)
|
||||
|
||||
|
@ -153,14 +153,14 @@ def test_mongo_event_repository__get_events_by_source(mongo_repository: IEventRe
|
|||
|
||||
|
||||
def test_mongo_event_repository__get_events_by_source_raises(
|
||||
error_raising_mongo_repository: IEventRepository,
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
with pytest.raises(RetrievalError):
|
||||
source_event = EVENTS[2]
|
||||
error_raising_mongo_repository.get_events_by_source(source_event.source)
|
||||
|
||||
|
||||
def test_mongo_event_repository__reset(mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__reset(mongo_repository: IAgentEventRepository):
|
||||
initial_events = mongo_repository.get_events()
|
||||
assert initial_events
|
||||
|
||||
|
@ -170,6 +170,8 @@ def test_mongo_event_repository__reset(mongo_repository: IEventRepository):
|
|||
assert not events
|
||||
|
||||
|
||||
def test_mongo_event_repository__reset_raises(error_raising_mongo_repository: IEventRepository):
|
||||
def test_mongo_event_repository__reset_raises(
|
||||
error_raising_mongo_repository: IAgentEventRepository,
|
||||
):
|
||||
with pytest.raises(RemovalError):
|
||||
error_raising_mongo_repository.reset()
|
||||
|
|
Loading…
Reference in New Issue