Ticket #3466: modeltests.serializers.models.diff

File modeltests.serializers.models.diff, 1.0 KB (added by egmanoj@…, 18 years ago)

Added new tests to tests.modeltests.serializers.models

  • models.py

     
    139139...     print obj
    140140<DeserializedObject: Profile of Joe>
    141141
     142# Tests for Trac item #3466 - 'fields' option not working for json serializer.
     143# Serialize and deserialize passing a single field name.
     144>>> json = serializers.serialize("json", AuthorProfile.objects.all(), fields = "date_of_birth")
     145>>> json
     146'[{"pk": "1", "model": "serializers.authorprofile", "fields": {"date_of_birth": "1970-01-01"}}]'
     147
     148>>> for obj in serializers.deserialize("json", json):
     149...     print obj
     150<DeserializedObject: Profile of Joe>
     151
     152# Serialize and deserialize passing multiple field names.
     153>>> json = serializers.serialize("json", Article.objects.all(), fields = ["author", "headline"])
     154>>> for obj in serializers.deserialize("json", json):
     155...     print obj
     156<DeserializedObject: Just kidding; I love TV poker>
     157<DeserializedObject: Time to reform copyright>
     158
    142159"""}
Back to Top