Removed some test code which isn't useful with tastypie 0.14.0

- Legacy-Id: 13768
This commit is contained in:
Henrik Levkowetz 2017-07-03 21:20:36 +00:00
parent bf0aec8e89
commit 27bf51cbb9

View file

@ -9,7 +9,6 @@ from django.test import Client
from django.conf import settings
from django.urls import reverse as urlreverse
from tastypie.exceptions import BadRequest
from tastypie.test import ResourceTestCaseMixin
import debug # pyflakes:ignore
@ -66,35 +65,10 @@ class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
self.assertIn(name, resource_list,
"Expected a REST API resource for %s, but didn't find one" % name)
def _assertCallbackReturnsSameJSON(self, api_url, json_dict):
cbclient = Client(Accept='text/javascript')
identity = lambda x: x # pyflakes:ignore
# To be able to eval JSON, we need to have three more symbols
# They are used indirectly
true = True # pyflakes:ignore
false = False # pyflakes:ignore
null = None # pyflakes:ignore
r = cbclient.get(api_url + '?callback=identity')
code = compile(r.content, '<string>', 'eval')
# Make sure it is just a call with the identity function
self.assertTrue(len(code.co_names) == 1, "The callback API returned "
"code which uses more symbols than just the given \'identity\' "
"callback function: %s" % ', '.join(code.co_names))
self.assertTrue(code.co_names[0] == 'identity', "The callback API "
"returned code with a different symbol than the given "
"\'identity\' callback function: %s" % code.co_names[0])
# After all these checks, I think calling eval is "safe"
# Fingers crossed!
callback_dict = eval(code)
self.assertEqual(callback_dict, json_dict, "The callback API returned "
"a different dictionary than the json API")
def test_all_model_resources_exist(self):
client = Client(Accept='application/json')
r = client.get("/api/v1")
top = json.loads(r.content)
#self._assertCallbackReturnsSameJSON("/api/v1", top)
for name in self.apps:
app_name = self.apps[name]
app = import_module(app_name)
@ -102,7 +76,6 @@ class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
r = client.get(top[name]["list_endpoint"])
self.assertValidJSONResponse(r)
app_resources = json.loads(r.content)
#self._assertCallbackReturnsSameJSON("/api/v1/%s/"%name, app_resources)
#
model_list = apps.get_app_config(name).get_models()
for model in model_list:
@ -111,10 +84,3 @@ class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
self.assertIn(model._meta.model_name, app_resources.keys(),
"There doesn't seem to be any API resource for model %s.models.%s"%(app.__name__,model.__name__,))
def test_invalid_jsonp_callback_value(self):
try:
Client(Accept='text/javascript').get("/api/v1?callback=$.23")
except BadRequest:
return
self.assertTrue(False,
"The callback API accepted an invalid JSONP callback name")