-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test tanner-parse-response #192
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,14 @@ | |
import json | ||
import yarl | ||
import aiohttp | ||
import logging | ||
from unittest import mock | ||
from snare.utils.asyncmock import AsyncMock | ||
from snare.tanner_handler import TannerHandler | ||
from snare.utils.page_path_generator import generate_unique_path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TestSubmitData(unittest.TestCase): | ||
def setUp(self): | ||
|
@@ -65,6 +69,21 @@ async def test(): | |
self.loop.run_until_complete(test()) | ||
self.assertEqual(self.result, dict(detection={'type': 1}, sess_uuid="test_uuid")) | ||
|
||
def test_submit_data_error(self): | ||
|
||
async def mock_json_decode_error(data): | ||
logger.error('Error submitting data: JSONDecodeError {}'.format(data)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, logger creates a file for errors, is this also doing the same? If so please do the cleanup. |
||
|
||
self.handler = mock.Mock() | ||
self.handler.submit_data = mock_json_decode_error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should use this instead of mocking the entire |
||
|
||
async def test(): | ||
self.result = await self.handler.submit_data(self.data) | ||
|
||
with self.assertLogs(level='ERROR') as log: | ||
self.loop.run_until_complete(test()) | ||
self.assertIn('Error submitting data: JSONDecodeError {}'.format(self.data), log.output[0]) | ||
|
||
def test_event_result_exception(self): | ||
aiohttp.ClientResponse.json = AsyncMock(side_effect=Exception()) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you place it in
setUp
?