Commit bc1f67a6 authored by Jacob Kaplan-Moss's avatar Jacob Kaplan-Moss
Browse files

Replaced dict reprs in tests with explicit looks at each key. This should fix...

Replaced dict reprs in tests with explicit looks at each key. This should 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
parent 6035af82
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -71,8 +71,9 @@ u'ABC123'
>>> 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()
+5 −2
Original line number Diff line number Diff line
@@ -76,8 +76,11 @@ Article 4

# 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])
+18 −10
Original line number Diff line number Diff line
@@ -41,25 +41,33 @@ __test__ = {'API_TESTS':u"""
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']})
+26 −10
Original line number Diff line number Diff line
@@ -234,8 +234,12 @@ We can also subclass the Meta inner class to change the fields list.
>>> 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 @@ True
>>> 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 @@ save() on the resulting model instance.
>>> 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 @@ True

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 @@ ValidationError: [u'Select a valid choice. 4 is not one of the available choices
>>> 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 ###################################################################

+14 −10
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ __test__ = {'API_TESTS':"""
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 @@ True
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 @@ datetime.date(2000, 5, 3)
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 @@ datetime.datetime(2002, 4, 3, 0, 0)
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.']

"""}
Loading