# Path: nudge/renderer.py
# class Json(object):
#     ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
#         result as json, and returns.
# 
#         Note this renderer will not allow you to pass back a top level
#         list or tuple (javascript array) because it is insecure, and could
#         allow a CSRF attack. See here:
#         http://flask.pocoo.org/docs/security/#json-security
#     '''
#     def __call__(self, result):
#         if result == None:
#             raise HTTPException(404)
#         if isinstance(result, (types.ListType, types.TupleType)):
#             raise SecurityException(
#                 'Results that encode as json arrays are not '+\
#                 'allowed for security concerns'
#             )
#         return Result(
#             content=json_encode(result),
#             content_type='application/json; charset=UTF-8',
#             http_status=200,
#         )
# 
# Path: nudge/error.py
# class SecurityException(Exception):
#     pass


import unittest
from nose.tools import raises
from nudge.renderer import Json
from nudge.error import SecurityException


class JsonRendererTest(unittest.TestCase):
    
    @raises(SecurityException)
    def test_list_throws_500(self):
        Json()([1,2,3])

    def test_dict(self):

# Path: nudge/renderer.py
# class Json(object):
#     ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
#         result as json, and returns.
# 
#         Note this renderer will not allow you to pass back a top level
#         list or tuple (javascript array) because it is insecure, and could
#         allow a CSRF attack. See here:
#         http://flask.pocoo.org/docs/security/#json-security
#     '''
#     def __call__(self, result):
#         if result == None:
#             raise HTTPException(404)
#         if isinstance(result, (types.ListType, types.TupleType)):
#             raise SecurityException(
#                 'Results that encode as json arrays are not '+\
#                 'allowed for security concerns'
#             )
#         return Result(
#             content=json_encode(result),
#             content_type='application/json; charset=UTF-8',
#             http_status=200,
#         )
# 
# Path: nudge/error.py
# class SecurityException(Exception):
#     pass


# Path: tests/test_renderer.py
import unittest
from nose.tools import raises
from nudge.renderer import Json
from nudge.error import SecurityException



class JsonRendererTest(unittest.TestCase):
    
    @raises(SecurityException)
    def test_list_throws_500(self):
        Json()([1,2,3])

    def test_dict(self):

        result = Json()({'test':'me'}).content