  
  from djangorestframework.response import ErrorResponse
  from djangorestframework import status
  from djangorestframework.utils import as_tuple
  from djangorestframework.mediatypes import MediaType
  from djangorestframework.compat import parse_qs
  
  
  class BaseParser(object):
      """All parsers should extend BaseParser, specifying a media_type attribute,
 
</s> remove from djangorestframework.mediatypes import MediaType
 </s> add from djangorestframework.utils.mediatypes import MediaType </s> remove from djangorestframework import renderers, parsers, authenticators, permissions, validators, status
 </s> add from djangorestframework import renderers, parsers, authentication, permissions, validators, status </s> remove from djangorestframework.mediatypes import MediaType
 </s> add from djangorestframework.utils.mediatypes import MediaType </s> remove from django.conf.urls.defaults import patterns, url
from django import http
from django.test import TestCase
from djangorestframework.compat import View
from djangorestframework.emitters import BaseEmitter
from djangorestframework.mixins import ResponseMixin
from djangorestframework.response import Response

DUMMYSTATUS = 200
DUMMYCONTENT = 'dummycontent'

EMITTER_A_SERIALIZER = lambda x: 'Emitter A: %s' % x
EMITTER_B_SERIALIZER = lambda x: 'Emitter B: %s' % x

class MockView(ResponseMixin, View):
    def get(self, request):
        response = Response(DUMMYSTATUS, DUMMYCONTENT)
        return self.emit(response)

class EmitterA(BaseEmitter):
    media_type = 'mock/emittera'

    def emit(self, output, verbose=False):
        return EMITTER_A_SERIALIZER(output)

class EmitterB(BaseEmitter):
    media_type = 'mock/emitterb'

    def emit(self, output, verbose=False):
        return EMITTER_B_SERIALIZER(output)


urlpatterns = patterns('',
    url(r'^$', MockView.as_view(emitters=[EmitterA, EmitterB])),
)


class EmitterIntegrationTests(TestCase):
    """End-to-end testing of emitters using an EmitterMixin on a generic view."""

    urls = 'djangorestframework.tests.emitters'

    def test_default_emitter_serializes_content(self):
        """If the Accept header is not set the default emitter should serialize the response."""
        resp = self.client.get('/')
        self.assertEquals(resp['Content-Type'], EmitterA.media_type)
        self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
        self.assertEquals(resp.status_code, DUMMYSTATUS)

    def test_default_emitter_serializes_content_on_accept_any(self):
        """If the Accept header is set to */* the default emitter should serialize the response."""
        resp = self.client.get('/', HTTP_ACCEPT='*/*')
        self.assertEquals(resp['Content-Type'], EmitterA.media_type)
        self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
        self.assertEquals(resp.status_code, DUMMYSTATUS)

    def test_specified_emitter_serializes_content_default_case(self):
        """If the Accept header is set the specified emitter should serialize the response.
        (In this case we check that works for the default emitter)"""
        resp = self.client.get('/', HTTP_ACCEPT=EmitterA.media_type)
        self.assertEquals(resp['Content-Type'], EmitterA.media_type)
        self.assertEquals(resp.content, EMITTER_A_SERIALIZER(DUMMYCONTENT))
        self.assertEquals(resp.status_code, DUMMYSTATUS)

    def test_specified_emitter_serializes_content_non_default_case(self):
        """If the Accept header is set the specified emitter should serialize the response.
        (In this case we check that works for a non-default emitter)"""
        resp = self.client.get('/', HTTP_ACCEPT=EmitterB.media_type)
        self.assertEquals(resp['Content-Type'], EmitterB.media_type)
        self.assertEquals(resp.content, EMITTER_B_SERIALIZER(DUMMYCONTENT))
        self.assertEquals(resp.status_code, DUMMYSTATUS)
    
    def test_unsatisfiable_accept_header_on_request_returns_406_status(self):
        """If the Accept header is unsatisfiable we should return a 406 Not Acceptable response."""
        resp = self.client.get('/', HTTP_ACCEPT='foo/bar')
        self.assertEquals(resp.status_code, 406) </s> add  </s> remove from djangorestframework.markdownwrapper import apply_markdown
from djangorestframework.description import get_name, get_description
 </s> add from djangorestframework.compat import apply_markdown
from djangorestframework.utils.description import get_name, get_description
from djangorestframework.utils.mediatypes import MediaType
  
  from djangorestframework.response import ErrorResponse
  from djangorestframework import status
  from djangorestframework.utils import as_tuple
from djangorestframework.utils.mediatypes import MediaType
  from djangorestframework.compat import parse_qs
  
  
  class BaseParser(object):
      """All parsers should extend BaseParser, specifying a media_type attribute,
keep keep keep keep replace keep keep keep keep keep
 More refactoring - move various less core stuff into utils etc 
djangorestframework/parsers.py