content.ContentSettings: Fix AttributeError in __setitem__.

Code coverage FTW!
This commit is contained in:
Dave Shawley 2016-01-11 07:36:39 -05:00
parent d6493a70e2
commit 3eecbad5c5
2 changed files with 29 additions and 2 deletions

View file

@ -88,7 +88,7 @@ class ContentSettings(object):
def __setitem__(self, content_type, handler):
if content_type in self._handlers:
logger.warning('handler for %s already set to %r',
content_type, self._handers[content_type])
content_type, self._handlers[content_type])
return
self._available_types.append(headers.parse_content_type(content_type))

View file

@ -9,7 +9,7 @@ import uuid
from tornado import testing
import msgpack
from sprockets.mixins.mediatype import transcoders
from sprockets.mixins.mediatype import content, transcoders
import examples
@ -134,3 +134,30 @@ class JSONTranscoderTests(unittest.TestCase):
def test_that_unhandled_objects_raise_type_error(self):
with self.assertRaises(TypeError):
self.transcoder.dumps(object())
class ContentSettingsTests(unittest.TestCase):
def test_that_from_application_creates_instance(self):
class Context(object):
pass
context = Context()
settings = content.ContentSettings.from_application(context)
self.assertIs(content.ContentSettings.from_application(context),
settings)
def test_that_handler_listed_in_available_content_types(self):
settings = content.ContentSettings()
settings['application/json'] = object()
self.assertEqual(len(settings.available_content_types), 1)
self.assertEqual(settings.available_content_types[0].content_type,
'application')
self.assertEqual(settings.available_content_types[0].content_subtype,
'json')
def test_that_handler_is_not_overwritten(self):
settings = content.ContentSettings()
settings['application/json'] = handler = object()
settings['application/json'] = object()
self.assertIs(settings.get('application/json'), handler)