mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Reverting r14994 (at request of SmileyChris) because of some backwards compatibility issues that need to be resolved.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14995 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b60d5df072
commit
e299ac0cae
6 changed files with 25 additions and 109 deletions
|
@ -264,17 +264,3 @@ class LengthModel(models.Model):
|
|||
|
||||
def __len__(self):
|
||||
return self.data
|
||||
|
||||
#Tests for natural keys.
|
||||
class BookManager(models.Manager):
|
||||
def get_by_natural_key(self, isbn13):
|
||||
return self.get(isbn13=isbn13)
|
||||
|
||||
class Book(models.Model):
|
||||
isbn13 = models.CharField(max_length=14)
|
||||
title = models.CharField(max_length=100)
|
||||
|
||||
objects = BookManager()
|
||||
|
||||
def natural_key(self):
|
||||
return (self.isbn13,)
|
||||
|
|
|
@ -414,36 +414,8 @@ def streamTest(format, self):
|
|||
self.assertEqual(string_data, stream.getvalue())
|
||||
stream.close()
|
||||
|
||||
def naturalKeyTest(format, self):
|
||||
book1 = {'isbn13': '978-1590597255', 'title': 'The Definitive Guide to '
|
||||
'Django: Web Development Done Right'}
|
||||
book2 = {'isbn13':'978-1590599969', 'title': 'Practical Django Projects'}
|
||||
|
||||
# Create the books.
|
||||
adrian = Book.objects.create(**book1)
|
||||
james = Book.objects.create(**book2)
|
||||
|
||||
# Serialize the books.
|
||||
string_data = serializers.serialize(format, Book.objects.all(), indent=2,
|
||||
use_natural_keys=True)
|
||||
|
||||
# Delete one book (to prove that the natural key generation will only
|
||||
# restore the primary keys of books found in the database via the
|
||||
# get_natural_key manager method).
|
||||
james.delete()
|
||||
|
||||
# Deserialize and test.
|
||||
books = list(serializers.deserialize(format, string_data))
|
||||
self.assertEqual(len(books), 2)
|
||||
self.assertEqual(books[0].object.title, book1['title'])
|
||||
self.assertEqual(books[0].object.pk, adrian.pk)
|
||||
self.assertEqual(books[1].object.title, book2['title'])
|
||||
self.assertEqual(books[1].object.pk, None)
|
||||
|
||||
for format in serializers.get_serializer_formats():
|
||||
setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))
|
||||
setattr(SerializerTests, 'test_' + format + '_serializer_fields', curry(fieldsTest, format))
|
||||
setattr(SerializerTests, 'test_' + format + '_serializer_natural_key',
|
||||
curry(naturalKeyTest, format))
|
||||
if format != 'python':
|
||||
setattr(SerializerTests, 'test_' + format + '_serializer_stream', curry(streamTest, format))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue