Permalink
Browse files

Replaced dict reprs in tests with explicit looks at each key. This sh…

…ould fix many spurious test failures on other VMs (first noticed on Jython).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7322 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 6035af8 commit bc1f67a6de45fe2ebfdf69ba449295066f365419 @jacobian jacobian committed Mar 19, 2008
@@ -71,8 +71,9 @@ def __unicode__(self):
>>> fran.save()
>>> Employee.objects.filter(last_name__exact='Jones')
[<Employee: Dan Jones>, <Employee: Fran Jones>]
->>> Employee.objects.in_bulk(['ABC123', 'XYZ456'])
-{u'XYZ456': <Employee: Fran Jones>, u'ABC123': <Employee: Dan Jones>}
+>>> emps = Employee.objects.in_bulk(['ABC123', 'XYZ456'])
+>>> emps['ABC123']
+<Employee: Dan Jones>
>>> b = Business(name='Sears')
>>> b.save()
@@ -76,8 +76,11 @@ def __unicode__(self):
# in_bulk() takes a list of IDs and returns a dictionary mapping IDs
# to objects.
->>> Article.objects.in_bulk([1, 2])
-{1: <Article: Article 1>, 2: <Article: Article 2>}
+>>> arts = Article.objects.in_bulk([1, 2])
+>>> arts[1]
+<Article: Article 1>
+>>> arts[2]
+<Article: Article 2>
>>> Article.objects.in_bulk([3])
{3: <Article: Article 3>}
>>> Article.objects.in_bulk([1000])
@@ -41,25 +41,33 @@ def __unicode__(self):
True
# Attempt to add a Musician without a first_name.
->>> man.get_validation_errors(MultiValueDict({'last_name': ['Blakey']}))
-{'first_name': [u'This field is required.']}
+>>> man.get_validation_errors(MultiValueDict({'last_name': ['Blakey']}))['first_name']
+[u'This field is required.']
# Attempt to add a Musician without a first_name and last_name.
->>> man.get_validation_errors(MultiValueDict({}))
-{'first_name': [u'This field is required.'], 'last_name': [u'This field is required.']}
+>>> errors = man.get_validation_errors(MultiValueDict({}))
+>>> errors['first_name']
+[u'This field is required.']
+>>> errors['last_name']
+[u'This field is required.']
# Attempt to create an Album without a name or musician.
>>> man = Album.AddManipulator()
->>> man.get_validation_errors(MultiValueDict({}))
-{'musician': [u'This field is required.'], 'name': [u'This field is required.']}
+>>> errors = man.get_validation_errors(MultiValueDict({}))
+>>> errors['musician']
+[u'This field is required.']
+>>> errors['name']
+[u'This field is required.']
# Attempt to create an Album with an invalid musician.
->>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))
-{'musician': [u"Select a valid choice; 'foo' is not in [u'', u'1']."]}
+>>> errors = man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))
+>>> errors['musician']
+[u"Select a valid choice; 'foo' is not in [u'', u'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': [u'Enter a valid date in YYYY-MM-DD format.']}
+>>> errors = man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'}))
+>>> errors['release_date']
+[u'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']})
@@ -234,8 +234,12 @@ def __unicode__(self):
>>> f = CategoryForm({'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'})
>>> f.is_valid()
True
->>> f.cleaned_data
-{'url': u'entertainment', 'name': u'Entertainment', 'slug': u'entertainment'}
+>>> f.cleaned_data['url']
+u'entertainment'
+>>> f.cleaned_data['name']
+u'Entertainment'
+>>> f.cleaned_data['slug']
+u'entertainment'
>>> obj = f.save()
>>> obj
<Category: Entertainment>
@@ -245,8 +249,12 @@ def __unicode__(self):
>>> f = CategoryForm({'name': "It's a test", 'slug': 'its-test', 'url': 'test'})
>>> f.is_valid()
True
->>> f.cleaned_data
-{'url': u'test', 'name': u"It's a test", 'slug': u'its-test'}
+>>> f.cleaned_data['url']
+u'test'
+>>> f.cleaned_data['name']
+u"It's a test"
+>>> f.cleaned_data['slug']
+u'its-test'
>>> obj = f.save()
>>> obj
<Category: It's a test>
@@ -259,8 +267,12 @@ def __unicode__(self):
>>> f = CategoryForm({'name': 'Third test', 'slug': 'third-test', 'url': 'third'})
>>> f.is_valid()
True
->>> f.cleaned_data
-{'url': u'third', 'name': u'Third test', 'slug': u'third-test'}
+>>> f.cleaned_data['url']
+u'third'
+>>> f.cleaned_data['name']
+u'Third test'
+>>> f.cleaned_data['slug']
+u'third-test'
>>> obj = f.save(commit=False)
>>> obj
<Category: Third test>
@@ -272,8 +284,10 @@ def __unicode__(self):
If you call save() with invalid data, you'll get a ValueError.
>>> f = CategoryForm({'name': '', 'slug': '', 'url': 'foo'})
->>> f.errors
-{'name': [u'This field is required.'], 'slug': [u'This field is required.']}
+>>> f.errors['name']
+[u'This field is required.']
+>>> f.errors['slug']
+[u'This field is required.']
>>> f.cleaned_data
Traceback (most recent call last):
...
@@ -739,8 +753,10 @@ def __unicode__(self):
>>> f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'})
>>> f.is_valid()
True
->>> f.cleaned_data
-{'phone': u'312-555-1212', 'description': u'Assistance'}
+>>> f.cleaned_data['phone']
+u'312-555-1212'
+>>> f.cleaned_data['description']
+u'Assistance'
# FileField ###################################################################
@@ -41,8 +41,8 @@ def __unicode__(self):
23
>>> p = Person(**dict(valid_params, id='foo'))
->>> p.validate()
-{'id': [u'This value must be an integer.']}
+>>> p.validate()['id']
+[u'This value must be an integer.']
>>> p = Person(**dict(valid_params, id=None))
>>> p.validate()
@@ -75,8 +75,8 @@ def __unicode__(self):
False
>>> p = Person(**dict(valid_params, is_child='foo'))
->>> p.validate()
-{'is_child': [u'This value must be either True or False.']}
+>>> p.validate()['is_child']
+[u'This value must be either True or False.']
>>> p = Person(**dict(valid_params, name=u'Jose'))
>>> p.validate()
@@ -115,8 +115,8 @@ def __unicode__(self):
datetime.date(2000, 5, 3)
>>> p = Person(**dict(valid_params, birthdate='foo'))
->>> p.validate()
-{'birthdate': [u'Enter a valid date in YYYY-MM-DD format.']}
+>>> p.validate()['birthdate']
+[u'Enter a valid date in YYYY-MM-DD format.']
>>> p = Person(**dict(valid_params, favorite_moment=datetime.datetime(2002, 4, 3, 13, 23)))
>>> p.validate()
@@ -143,11 +143,15 @@ def __unicode__(self):
u'john@example.com'
>>> p = Person(**dict(valid_params, email=22))
->>> p.validate()
-{'email': [u'Enter a valid e-mail address.']}
+>>> p.validate()['email']
+[u'Enter a valid e-mail address.']
# Make sure that Date and DateTime return validation errors and don't raise Python errors.
->>> Person(name='John Doe', is_child=True, email='abc@def.com').validate()
-{'favorite_moment': [u'This field is required.'], 'birthdate': [u'This field is required.']}
+>>> p = Person(name='John Doe', is_child=True, email='abc@def.com')
+>>> errors = p.validate()
+>>> errors['favorite_moment']
+[u'This field is required.']
+>>> errors['birthdate']
+[u'This field is required.']
"""}
@@ -252,8 +252,8 @@
</select>
<input type="text" name="field1_2_0" value="2007-04-25" id="id_field1_2_0" /><input type="text" name="field1_2_1" value="06:24:00" id="id_field1_2_1" /></td></tr>
->>> f.cleaned_data
-{'field1': u'some text,JP,2007-04-25 06:24:00'}
+>>> f.cleaned_data['field1']
+u'some text,JP,2007-04-25 06:24:00'
# IPAddressField ##################################################################
Oops, something went wrong.

0 comments on commit bc1f67a

Please sign in to comment.