Ticket #13182: noTrailingWhitespace.diff

File noTrailingWhitespace.diff, 1.5 KB (added by martmatwarne, 12 years ago)
  • django/core/serializers/json.py

    diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
    index 64357bf..b0b88d5 100644
    a b class Serializer(PythonSerializer):  
    3636        if self.options.get("indent"):
    3737            self.stream.write("\n")
    3838        self.stream.write("]")
    39         if self.options.get("indent"):
    40             self.stream.write("\n")
    4139
    4240    def end_object(self, obj):
    4341        # self._current has the field data
  • tests/serializers/tests.py

    diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
    index a96a1af..1bec907 100644
    a b class JsonSerializerTestCase(SerializersTestBase, TestCase):  
    389389                ret_list.append(obj_dict["fields"][field_name])
    390390        return ret_list
    391391
     392_json_expected="""[
     393{
     394  "pk": 1,
     395  "model": "serializers.score",
     396  "fields": {
     397    "score": 5.0
     398  }
     399},
     400{
     401  "pk": 2,
     402  "model": "serializers.score",
     403  "fields": {
     404    "score": 6.0
     405  }
     406}
     407]"""
     408
     409
     410class TestJsonSerializerIndentation(TestCase):
     411    def test_indentation_whitespace(self):
     412        from django.core.serializers.json import Serializer
     413        Score.objects.create(score=5.0)
     414        Score.objects.create(score=6.0)
     415        qset = Score.objects.all()
     416
     417        s = Serializer()
     418        self.assertEqual(s.serialize(qset, indent=2), _json_expected)
     419
    392420class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
    393421    serializer_name = "json"
    394422    fwd_ref_str = """[
Back to Top