<s> import os . path <EOL> import datetime <EOL> import json <EOL> from django import test <EOL> import six <EOL> from django_extras . http import FileResponse , JsonResponse <EOL> class FileResponseTestCase ( test . TestCase ) : <EOL> def test_with_file_handle ( self ) : <EOL> path = os . path . dirname ( __file__ ) <EOL> f = open ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> target = FileResponse ( f , '<STR_LIT>' ) <EOL> self . assertEqual ( target [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> class JsonResponseTestCase ( test . TestCase ) : <EOL> def assertJSONEqual ( self , raw , expected_data , msg = None ) : <EOL> try : <EOL> data = json . loads ( raw ) <EOL> except ValueError : <EOL> self . fail ( "<STR_LIT>" % raw ) <EOL> if isinstance ( expected_data , six . string_types ) : <EOL> try : <EOL> expected_data = json . loads ( expected_data ) <EOL> except ValueError : <EOL> self . fail ( "<STR_LIT>" % expected_data ) <EOL> self . assertEqual ( data , expected_data , msg = msg ) <EOL> def test_simple_dictionary ( self ) : <EOL> target = JsonResponse ( { <EOL> '<STR_LIT:foo>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } ) <EOL> if six . PY3 : <EOL> actual = target . content . decode ( '<STR_LIT:utf8>' ) <EOL> else : <EOL> actual = '<STR_LIT>' . join ( target ) <EOL> self . assertJSONEqual ( actual , { "<STR_LIT:foo>" : "<STR_LIT:bar>" , "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . assertEqual ( target [ '<STR_LIT:Content-Type>' ] , '<STR_LIT:application/json>' ) <EOL> def test_with_dates ( self ) : <EOL> target = JsonResponse ( { <EOL> '<STR_LIT:foo>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:9> , <NUM_LIT> ) <EOL> } ) <EOL> if six . PY3 : <EOL> actual = target . content . decode ( '<STR_LIT:utf8>' ) <EOL> else : <EOL> actual = '<STR_LIT>' . join ( target ) <EOL> self . assertJSONEqual ( actual , { "<STR_LIT:foo>" : "<STR_LIT:bar>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( '<STR_LIT:application/json>' , target [ '<STR_LIT:Content-Type>' ] ) </s>
