<s> from __future__ import unicode_literals <EOL> from django . test import TestCase <EOL> from rest_framework . negotiation import DefaultContentNegotiation <EOL> from rest_framework . renderers import BaseRenderer <EOL> from rest_framework . request import Request <EOL> from rest_framework . test import APIRequestFactory <EOL> factory = APIRequestFactory ( ) <EOL> class MockJSONRenderer ( BaseRenderer ) : <EOL> media_type = '<STR_LIT:application/json>' <EOL> class MockHTMLRenderer ( BaseRenderer ) : <EOL> media_type = '<STR_LIT>' <EOL> class NoCharsetSpecifiedRenderer ( BaseRenderer ) : <EOL> media_type = '<STR_LIT>' <EOL> class TestAcceptedMediaType ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . renderers = [ MockJSONRenderer ( ) , MockHTMLRenderer ( ) ] <EOL> self . negotiator = DefaultContentNegotiation ( ) <EOL> def select_renderer ( self , request ) : <EOL> return self . negotiator . select_renderer ( request , self . renderers ) <EOL> def test_client_without_accept_use_renderer ( self ) : <EOL> request = Request ( factory . get ( '<STR_LIT:/>' ) ) <EOL> accepted_renderer , accepted_media_type = self . select_renderer ( request ) <EOL> self . assertEqual ( accepted_media_type , '<STR_LIT:application/json>' ) <EOL> def test_client_underspecifies_accept_use_renderer ( self ) : <EOL> request = Request ( factory . get ( '<STR_LIT:/>' , HTTP_ACCEPT = '<STR_LIT>' ) ) <EOL> accepted_renderer , accepted_media_type = self . select_renderer ( request ) <EOL> self . assertEqual ( accepted_media_type , '<STR_LIT:application/json>' ) <EOL> def test_client_overspecifies_accept_use_client ( self ) : <EOL> request = Request ( factory . get ( '<STR_LIT:/>' , HTTP_ACCEPT = '<STR_LIT>' ) ) <EOL> accepted_renderer , accepted_media_type = self . select_renderer ( request ) <EOL> self . assertEqual ( accepted_media_type , '<STR_LIT>' ) </s>
