# Path: canvas_sdk/exceptions.py
# class CanvasAPIError(SDKException):
# 
#     """
#     Error that gets returned from Canvas API calls via request library.  Contains the
#     http status code and the raw json response from the API request.  Note that the
#     structure of the json sent back by Canvas can vary depending on the type of error.
#     """
# 
#     def __init__(self, status_code=500, msg=None, error_json=None):
#         self.status_code = status_code
#         self.error_msg = msg
#         self.error_json = error_json
# 
#     """
#     NOTE: this method of fully defining unicode and having str call upon it is referenced
#     in official pydocs (https://docs.python.org/2/howto/pyporting.html) and other porting
#     libraries (like Django utils).  If we move to Python 3, we'd rewrite this to just have
#     a __str__ method and use futures and mixins to play nice with Python 2.
#     """
# 
#     def __str__(self):
#         if self.error_msg:
#             return '%s: %s' % (self.status_code, self.error_msg)
#         else:
#             return '%s' % self.status_code


import unittest
from canvas_sdk.exceptions import CanvasAPIError


class TestExceptions(unittest.TestCase):
    longMessage = True

    def setUp(self):
        self.default_api_error = CanvasAPIError()

    def test_default_status_for_canvas_api_error(self):
        """ Test expected default status for instance of CanvasAPIError """
        self.assertEqual(self.default_api_error.status_code, 500)

    def test_default_message_for_canvas_api_error(self):
        """ Test expected default msg attribute for instance of CanvasAPIError """
        self.assertIsNone(self.default_api_error.error_msg)

    def test_default_error_json_for_canvas_api_error(self):
        """ Test expected default error_json attribute for instance of CanvasAPIError """
        self.assertIsNone(self.default_api_error.error_json)

    def test_default_str_for_canvas_api_error(self):
        """ Test default CanvasAPIError instance represented as a str """
        self.assertEqual('500', str(self.default_api_error))

    def test_instance_str_for_canvas_api_error(self):
        """ Test string representation of CanvasAPIError with custom attributes """
        status = 404
        error_msg = 'This is a test message'
        error_json = {'Some error json'}


# Path: canvas_sdk/exceptions.py
# class CanvasAPIError(SDKException):
# 
#     """
#     Error that gets returned from Canvas API calls via request library.  Contains the
#     http status code and the raw json response from the API request.  Note that the
#     structure of the json sent back by Canvas can vary depending on the type of error.
#     """
# 
#     def __init__(self, status_code=500, msg=None, error_json=None):
#         self.status_code = status_code
#         self.error_msg = msg
#         self.error_json = error_json
# 
#     """
#     NOTE: this method of fully defining unicode and having str call upon it is referenced
#     in official pydocs (https://docs.python.org/2/howto/pyporting.html) and other porting
#     libraries (like Django utils).  If we move to Python 3, we'd rewrite this to just have
#     a __str__ method and use futures and mixins to play nice with Python 2.
#     """
# 
#     def __str__(self):
#         if self.error_msg:
#             return '%s: %s' % (self.status_code, self.error_msg)
#         else:
#             return '%s' % self.status_code


# Path: tests/test_exceptions.py
import unittest
from canvas_sdk.exceptions import CanvasAPIError



class TestExceptions(unittest.TestCase):
    longMessage = True

    def setUp(self):
        self.default_api_error = CanvasAPIError()

    def test_default_status_for_canvas_api_error(self):
        """ Test expected default status for instance of CanvasAPIError """
        self.assertEqual(self.default_api_error.status_code, 500)

    def test_default_message_for_canvas_api_error(self):
        """ Test expected default msg attribute for instance of CanvasAPIError """
        self.assertIsNone(self.default_api_error.error_msg)

    def test_default_error_json_for_canvas_api_error(self):
        """ Test expected default error_json attribute for instance of CanvasAPIError """
        self.assertIsNone(self.default_api_error.error_json)

    def test_default_str_for_canvas_api_error(self):
        """ Test default CanvasAPIError instance represented as a str """
        self.assertEqual('500', str(self.default_api_error))

    def test_instance_str_for_canvas_api_error(self):
        """ Test string representation of CanvasAPIError with custom attributes """
        status = 404
        error_msg = 'This is a test message'
        error_json = {'Some error json'}


        api_error = CanvasAPIError(status_code=status, msg=error_msg, error_json=error_json)