mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
magic-removal: Added more manipulator unit tests
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1746 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c5eed6b303
commit
5d630bcc60
@ -14,6 +14,7 @@ class Musician(models.Model):
|
|||||||
class Album(models.Model):
|
class Album(models.Model):
|
||||||
name = models.CharField(maxlength=100)
|
name = models.CharField(maxlength=100)
|
||||||
musician = models.ForeignKey(Musician)
|
musician = models.ForeignKey(Musician)
|
||||||
|
release_date = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -46,12 +47,43 @@ True
|
|||||||
|
|
||||||
# Attempt to create an Album without a name or musician.
|
# Attempt to create an Album without a name or musician.
|
||||||
>>> man = Album.AddManipulator()
|
>>> man = Album.AddManipulator()
|
||||||
|
>>> man.get_validation_errors(MultiValueDict({}))
|
||||||
# >>> man.get_validation_errors(MultiValueDict({}))
|
{'musician': ['This field is required.'], 'name': ['This field is required.']}
|
||||||
# {'musician': ['This field is required.'], 'name': ['This field is required.']}
|
|
||||||
|
|
||||||
# Attempt to create an Album with an invalid musician.
|
# Attempt to create an Album with an invalid musician.
|
||||||
>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))
|
>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))
|
||||||
{'musician': ["Select a valid choice; 'foo' is not in ['', '1']."]}
|
{'musician': ["Select a valid choice; 'foo' is not in ['', '1']."]}
|
||||||
|
|
||||||
|
# Attempt to create an Album with an invalid release_date.
|
||||||
|
>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'}))
|
||||||
|
{'release_date': ['Enter a valid date in YYYY-MM-DD format.']}
|
||||||
|
|
||||||
|
# Create an Album without a release_date (because it's optional).
|
||||||
|
>>> data = MultiValueDict({'name': ['Ella and Basie'], 'musician': ['1']})
|
||||||
|
>>> man.get_validation_errors(data)
|
||||||
|
{}
|
||||||
|
>>> man.do_html2python(data)
|
||||||
|
>>> a1 = man.save(data)
|
||||||
|
|
||||||
|
# Verify it worked.
|
||||||
|
>>> Album.objects.get_list()
|
||||||
|
[Ella and Basie]
|
||||||
|
>>> Album.objects.get_object().get_musician()
|
||||||
|
Ella Fitzgerald
|
||||||
|
|
||||||
|
# Create an Album with a release_date.
|
||||||
|
>>> data = MultiValueDict({'name': ['Ultimate Ella'], 'musician': ['1'], 'release_date': ['2005-02-13']})
|
||||||
|
>>> man.get_validation_errors(data)
|
||||||
|
{}
|
||||||
|
>>> man.do_html2python(data)
|
||||||
|
>>> a2 = man.save(data)
|
||||||
|
|
||||||
|
# Verify it worked.
|
||||||
|
>>> Album.objects.get_list(order_by=['name'])
|
||||||
|
[Ella and Basie, Ultimate Ella]
|
||||||
|
>>> a2 = Album.objects.get_object(pk=2)
|
||||||
|
>>> a2
|
||||||
|
Ultimate Ella
|
||||||
|
>>> a2.release_date
|
||||||
|
datetime.date(2005, 2, 13)
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user