Ticket #15197: test_serializers_http.patch

File test_serializers_http.patch, 1.9 KB (added by Hiroki Kiyohara, 12 years ago)

Added a test using HttpResponse to streamTest

  • tests/regressiontests/serializers_regress/tests.py

    diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
    index 704e34b..835caa3 100644
    a b from django.db import connection, models  
    2929from django.test import TestCase
    3030from django.utils.functional import curry
    3131from django.utils.unittest import skipUnless
     32from django.http import HttpResponse
    3233
    3334from .models import (BooleanData, CharData, DateData, DateTimeData, EmailData,
    3435    FileData, FilePathData, DecimalData, FloatData, IntegerData, IPAddressData,
    def streamTest(format, self):  
    469470    obj = ComplexModel(field1='first',field2='second',field3='third')
    470471    obj.save_base(raw=True)
    471472
    472     # Serialize the test database to a stream
    473     stream = StringIO()
    474     serializers.serialize(format, [obj], indent=2, stream=stream)
     473    for stream in (StringIO(), HttpResponse()):
     474        # Serialize the test database to a stream
     475        serializers.serialize(format, [obj], indent=2, stream=stream)
    475476
    476     # Serialize normally for a comparison
    477     string_data = serializers.serialize(format, [obj], indent=2)
     477        # Serialize normally for a comparison
     478        string_data = serializers.serialize(format, [obj], indent=2)
    478479
    479     # Check that the two are the same
    480     self.assertEqual(string_data, stream.getvalue())
    481     stream.close()
     480        # Check that the two are the same
     481        if callable(getattr(stream, 'getvalue', None)):
     482            self.assertEqual(string_data, stream.getvalue())
     483        elif callable(getattr(stream, 'content', None)):
     484            self.assertEqual(string_data, stream.content())
     485        stream.close()
    482486
    483487for format in serializers.get_serializer_formats():
    484488    setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))
Back to Top