def test_export_to_json(self):
     ex = solution.WidgetException()
     json_output = ex.to_json()
     expected = {
         'code': 500,
         'message': 'Internal Server Error : Widget Error.',
         'exception type': 'WidgetException'
     }
     self.assertEqual(json.loads(json_output), expected)
 def test_export_to_json_with_customer_msg(self):
     ex = solution.WidgetException(customer_msg="My message")
     json_output = ex.to_json()
     expected = {
         'code': 500,
         'message': 'Internal Server Error : My message',
         'exception type': 'WidgetException'
     }
     self.assertEqual(json.loads(json_output), expected)
 def test_exception_logging_no_args(self):
     ex = solution.WidgetException(customer_msg="My message")
     expected_line1 = "Exception: WidgetException logged at"
     expected_line2 = "Status code: 500"
     expected_line3 = "Message: Widget Error.\nArguments: ()"
     expected_line4 = "Traceback: ['solution.WidgetException\\n']"
     result = ex.log()
     self.assertIn(expected_line1, result)
     self.assertIn(expected_line2, result)
     self.assertIn(expected_line3, result)
     self.assertIn(expected_line4, result)
 def test_exception_argumets(self):
     ex = solution.WidgetException(10, 20, 30)
     self.assertEqual(ex.args, (10, 20, 30))
     self.assertEqual(ex.msg, 10)
 def test_default_customer_message(self):
     ex = solution.WidgetException(10, 20)
     self.assertEqual(ex.customer_msg, "Widget Error.")
 def test_customer_message(self):
     ex = solution.WidgetException(customer_msg="Test message")
     self.assertEqual(ex.customer_msg, "Test message")
 def test_traceback(self):
     ex = solution.WidgetException()
     self.assertEqual(list(ex.traceback), ['solution.WidgetException\n'])