# Path: name/decorators.py
# def jsonp(f):
#     """Wrap a json response in a callback, and set the mimetype (Content-Type)
#     header accordinglly (will wrap in text/javascript if there is a callback).
#     If the "callback" or "jsonp" parameters are provided, will wrap the json
#     output in callback({thejson})
# 
#     Usage:
# 
#     @jsonp
#     def my_json_view(request):
#         d = { 'key': 'value' }
#         return HTTPResponse(json.dumps(d), content_type='application/json')
# 
#     """
#     from functools import wraps
# 
#     @wraps(f)
#     def jsonp_wrapper(request, *args, **kwargs):
#         resp = f(request, *args, **kwargs)
#         if resp.status_code != 200:
#             return resp
#         if 'callback' in request.GET:
#             callback = request.GET['callback']
#             resp['Content-Type'] = 'application/javascript; charset=utf-8'
#             resp.content = "%s(%s)" % (callback, resp.content)
#             return resp
#         else:
#             return resp
# 
#     return jsonp_wrapper


from name.decorators import jsonp
from unittest.mock import MagicMock


def test_jsonp_returns_without_status_code_200():
    """Test jsonp returns correctly when the response does
    not have status code 200."""
    # Setup the mock view.
    f = MagicMock()
    f.__name__ = 'Wrapped View'

    # Setup the mock response.
    response = MagicMock()
    response.status_code = 301

    # Set the response as the return value for the mock
    # view.
    f.return_value = response


# Path: name/decorators.py
# def jsonp(f):
#     """Wrap a json response in a callback, and set the mimetype (Content-Type)
#     header accordinglly (will wrap in text/javascript if there is a callback).
#     If the "callback" or "jsonp" parameters are provided, will wrap the json
#     output in callback({thejson})
# 
#     Usage:
# 
#     @jsonp
#     def my_json_view(request):
#         d = { 'key': 'value' }
#         return HTTPResponse(json.dumps(d), content_type='application/json')
# 
#     """
#     from functools import wraps
# 
#     @wraps(f)
#     def jsonp_wrapper(request, *args, **kwargs):
#         resp = f(request, *args, **kwargs)
#         if resp.status_code != 200:
#             return resp
#         if 'callback' in request.GET:
#             callback = request.GET['callback']
#             resp['Content-Type'] = 'application/javascript; charset=utf-8'
#             resp.content = "%s(%s)" % (callback, resp.content)
#             return resp
#         else:
#             return resp
# 
#     return jsonp_wrapper


# Path: tests/test_decorators.py
from name.decorators import jsonp
from unittest.mock import MagicMock



def test_jsonp_returns_without_status_code_200():
    """Test jsonp returns correctly when the response does
    not have status code 200."""
    # Setup the mock view.
    f = MagicMock()
    f.__name__ = 'Wrapped View'

    # Setup the mock response.
    response = MagicMock()
    response.status_code = 301

    # Set the response as the return value for the mock
    # view.
    f.return_value = response


    decorated_f = jsonp(f)