def test_output_error_add_message_with_level_error_to_buffer(self): message = "!!!ERROR!!!" output = JSONOutput() output.output_error(message) self.assertEqual(output.buffer, [{"type": "error", "text": message, "time": "12:00:00"}])
def test_output_timeout_add_message_with_level_timeout_to_buffer(self): message = "timeout" output = JSONOutput() output.output_timeout(message) self.assertEqual(output.buffer, [{"type": "timeout", "text": message, "time": "12:00:00"}])
def test_output_info_add_message_with_level_info_to_buffer(self): message = "information..." output = JSONOutput() output.output_info(message) self.assertEqual(output.buffer, [{"type": "info", "text": message, "time": "12:00:00"}])
def test_output_result_add_found_to_buffer(self): url = "http://example.com/y" result = "File x found at " + url data = {"url": url, "severity": "critical", "description": "File x desc", "code": 200} output = JSONOutput() output.output_result(result, data=data) self.assertEqual(output.buffer, [{"type": "found", "url": url, "code": 200, "text": result, "severity": "critical", "description": "File x desc", "time": "12:00:00"}])
def test_output_timeout_add_message_with_level_timeout_to_buffer(self): message = "timeout" output = JSONOutput() output.output_timeout(message) self.assertEqual(output.buffer, [{ "type": "timeout", "text": message, "time": "12:00:00" }])
def test_output_error_add_message_with_level_error_to_buffer(self): message = "!!!ERROR!!!" output = JSONOutput() output.output_error(message) self.assertEqual(output.buffer, [{ "type": "error", "text": message, "time": "12:00:00" }])
def test_output_info_add_message_with_level_info_to_buffer(self): message = "information..." output = JSONOutput() output.output_info(message) self.assertEqual(output.buffer, [{ "type": "info", "text": message, "time": "12:00:00" }])
def test_output_result_add_found_to_buffer(self): url = "http://example.com/y" result = "File x found at " + url data = { "url": url, "severity": "critical", "description": "File x desc", "code": 200 } output = JSONOutput() output.output_result(result, data=data) self.assertEqual(output.buffer, [{ "type": "found", "url": url, "code": 200, "text": result, "severity": "critical", "description": "File x desc", "time": "12:00:00" }])
def test_flush_output_buffer_content_as_json(self): message = "information..." output = JSONOutput() output.output_info(message) output.output_raw_message = MagicMock() output.flush() expected = {"from": "delvelabs/tachyon", "version": __version__, "result": [ {"text": "information...", "time": "12:00:00", "type": "info"}]} actual = output.output_raw_message.call_args[0][0] self.assertEqual(json.loads(actual), expected)
def test_flush_output_buffer_content_as_json(self): message = "information..." output = JSONOutput() output.output_info(message) output.output_raw_message = MagicMock() output.flush() expected = { "from": "delvelabs/tachyon", "version": __version__, "result": [{ "text": "information...", "time": "12:00:00", "type": "info" }] } actual = output.output_raw_message.call_args[0][0] self.assertEqual(json.loads(actual), expected)