Ug. Remove crazy tests from blogposts example

This commit is contained in:
Tom Christie 2011-06-07 23:51:28 +01:00
parent d38a3ae7cc
commit f6d807c844

View File

@ -6,80 +6,78 @@ from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils import simplejson as json from django.utils import simplejson as json
from djangorestframework.compat import RequestFactory from blogpost import models
from blogpost import views, models
import blogpost import blogpost
class AcceptHeaderTests(TestCase): # class AcceptHeaderTests(TestCase):
"""Test correct behaviour of the Accept header as specified by RFC 2616: # """Test correct behaviour of the Accept header as specified by RFC 2616:
#
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1""" # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1"""
#
def assert_accept_mimetype(self, mimetype, expect=None): # def assert_accept_mimetype(self, mimetype, expect=None):
"""Assert that a request with given mimetype in the accept header, # """Assert that a request with given mimetype in the accept header,
gives a response with the appropriate content-type.""" # gives a response with the appropriate content-type."""
if expect is None: # if expect is None:
expect = mimetype # expect = mimetype
#
resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT=mimetype) # resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT=mimetype)
#
self.assertEquals(resp['content-type'], expect) # self.assertEquals(resp['content-type'], expect)
#
#
def dont_test_accept_json(self): # def dont_test_accept_json(self):
"""Ensure server responds with Content-Type of JSON when requested.""" # """Ensure server responds with Content-Type of JSON when requested."""
self.assert_accept_mimetype('application/json') # self.assert_accept_mimetype('application/json')
#
def dont_test_accept_xml(self): # def dont_test_accept_xml(self):
"""Ensure server responds with Content-Type of XML when requested.""" # """Ensure server responds with Content-Type of XML when requested."""
self.assert_accept_mimetype('application/xml') # self.assert_accept_mimetype('application/xml')
#
def dont_test_accept_json_when_prefered_to_xml(self): # def dont_test_accept_json_when_prefered_to_xml(self):
"""Ensure server responds with Content-Type of JSON when it is the client's prefered choice.""" # """Ensure server responds with Content-Type of JSON when it is the client's prefered choice."""
self.assert_accept_mimetype('application/json;q=0.9, application/xml;q=0.1', expect='application/json') # self.assert_accept_mimetype('application/json;q=0.9, application/xml;q=0.1', expect='application/json')
#
def dont_test_accept_xml_when_prefered_to_json(self): # def dont_test_accept_xml_when_prefered_to_json(self):
"""Ensure server responds with Content-Type of XML when it is the client's prefered choice.""" # """Ensure server responds with Content-Type of XML when it is the client's prefered choice."""
self.assert_accept_mimetype('application/json;q=0.1, application/xml;q=0.9', expect='application/xml') # self.assert_accept_mimetype('application/json;q=0.1, application/xml;q=0.9', expect='application/xml')
#
def dont_test_default_json_prefered(self): # def dont_test_default_json_prefered(self):
"""Ensure server responds with JSON in preference to XML.""" # """Ensure server responds with JSON in preference to XML."""
self.assert_accept_mimetype('application/json,application/xml', expect='application/json') # self.assert_accept_mimetype('application/json,application/xml', expect='application/json')
#
def dont_test_accept_generic_subtype_format(self): # def dont_test_accept_generic_subtype_format(self):
"""Ensure server responds with an appropriate type, when the subtype is left generic.""" # """Ensure server responds with an appropriate type, when the subtype is left generic."""
self.assert_accept_mimetype('text/*', expect='text/html') # self.assert_accept_mimetype('text/*', expect='text/html')
#
def dont_test_accept_generic_type_format(self): # def dont_test_accept_generic_type_format(self):
"""Ensure server responds with an appropriate type, when the type and subtype are left generic.""" # """Ensure server responds with an appropriate type, when the type and subtype are left generic."""
self.assert_accept_mimetype('*/*', expect='application/json') # self.assert_accept_mimetype('*/*', expect='application/json')
#
def dont_test_invalid_accept_header_returns_406(self): # def dont_test_invalid_accept_header_returns_406(self):
"""Ensure server returns a 406 (not acceptable) response if we set the Accept header to junk.""" # """Ensure server returns a 406 (not acceptable) response if we set the Accept header to junk."""
resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT='invalid/invalid') # resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT='invalid/invalid')
self.assertNotEquals(resp['content-type'], 'invalid/invalid') # self.assertNotEquals(resp['content-type'], 'invalid/invalid')
self.assertEquals(resp.status_code, 406) # self.assertEquals(resp.status_code, 406)
#
def dont_test_prefer_specific_over_generic(self): # This test is broken right now # def dont_test_prefer_specific_over_generic(self): # This test is broken right now
"""More specific accept types have precedence over less specific types.""" # """More specific accept types have precedence over less specific types."""
self.assert_accept_mimetype('application/xml, */*', expect='application/xml') # self.assert_accept_mimetype('application/xml, */*', expect='application/xml')
self.assert_accept_mimetype('*/*, application/xml', expect='application/xml') # self.assert_accept_mimetype('*/*, application/xml', expect='application/xml')
#
#
class AllowedMethodsTests(TestCase): # class AllowedMethodsTests(TestCase):
"""Basic tests to check that only allowed operations may be performed on a Resource""" # """Basic tests to check that only allowed operations may be performed on a Resource"""
#
def dont_test_reading_a_read_only_resource_is_allowed(self): # def dont_test_reading_a_read_only_resource_is_allowed(self):
"""GET requests on a read only resource should default to a 200 (OK) response""" # """GET requests on a read only resource should default to a 200 (OK) response"""
resp = self.client.get(reverse(views.RootResource)) # resp = self.client.get(reverse(views.RootResource))
self.assertEquals(resp.status_code, 200) # self.assertEquals(resp.status_code, 200)
#
def dont_test_writing_to_read_only_resource_is_not_allowed(self): # def dont_test_writing_to_read_only_resource_is_not_allowed(self):
"""PUT requests on a read only resource should default to a 405 (method not allowed) response""" # """PUT requests on a read only resource should default to a 405 (method not allowed) response"""
resp = self.client.put(reverse(views.RootResource), {}) # resp = self.client.put(reverse(views.RootResource), {})
self.assertEquals(resp.status_code, 405) # self.assertEquals(resp.status_code, 405)
# #
# def test_reading_write_only_not_allowed(self): # def test_reading_write_only_not_allowed(self):
# resp = self.client.get(reverse(views.WriteOnlyResource)) # resp = self.client.get(reverse(views.WriteOnlyResource))