99from django .conf import settings
1010from django .urls import reverse as urlreverse
1111
12- from tastypie .exceptions import BadRequest
1312from tastypie .test import ResourceTestCaseMixin
1413
1514import debug # pyflakes:ignore
@@ -66,43 +65,17 @@ def test_api_top_level(self):
6665 self .assertIn (name , resource_list ,
6766 "Expected a REST API resource for %s, but didn't find one" % name )
6867
69- def _assertCallbackReturnsSameJSON (self , api_url , json_dict ):
70- cbclient = Client (Accept = 'text/javascript' )
71- identity = lambda x : x # pyflakes:ignore
72-
73- # To be able to eval JSON, we need to have three more symbols
74- # They are used indirectly
75- true = True # pyflakes:ignore
76- false = False # pyflakes:ignore
77- null = None # pyflakes:ignore
78- r = cbclient .get (api_url + '?callback=identity' )
79- code = compile (r .content , '<string>' , 'eval' )
80- # Make sure it is just a call with the identity function
81- self .assertTrue (len (code .co_names ) == 1 , "The callback API returned "
82- "code which uses more symbols than just the given \' identity\' "
83- "callback function: %s" % ', ' .join (code .co_names ))
84- self .assertTrue (code .co_names [0 ] == 'identity' , "The callback API "
85- "returned code with a different symbol than the given "
86- "\' identity\' callback function: %s" % code .co_names [0 ])
87- # After all these checks, I think calling eval is "safe"
88- # Fingers crossed!
89- callback_dict = eval (code )
90- self .assertEqual (callback_dict , json_dict , "The callback API returned "
91- "a different dictionary than the json API" )
92-
9368 def test_all_model_resources_exist (self ):
9469 client = Client (Accept = 'application/json' )
9570 r = client .get ("/api/v1" )
9671 top = json .loads (r .content )
97- #self._assertCallbackReturnsSameJSON("/api/v1", top)
9872 for name in self .apps :
9973 app_name = self .apps [name ]
10074 app = import_module (app_name )
10175 self .assertEqual ("/api/v1/%s/" % name , top [name ]["list_endpoint" ])
10276 r = client .get (top [name ]["list_endpoint" ])
10377 self .assertValidJSONResponse (r )
10478 app_resources = json .loads (r .content )
105- #self._assertCallbackReturnsSameJSON("/api/v1/%s/"%name, app_resources)
10679 #
10780 model_list = apps .get_app_config (name ).get_models ()
10881 for model in model_list :
@@ -111,10 +84,3 @@ def test_all_model_resources_exist(self):
11184 self .assertIn (model ._meta .model_name , app_resources .keys (),
11285 "There doesn't seem to be any API resource for model %s.models.%s" % (app .__name__ ,model .__name__ ,))
11386
114- def test_invalid_jsonp_callback_value (self ):
115- try :
116- Client (Accept = 'text/javascript' ).get ("/api/v1?callback=$.23" )
117- except BadRequest :
118- return
119- self .assertTrue (False ,
120- "The callback API accepted an invalid JSONP callback name" )
0 commit comments