Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed the model_forms doctests to not depend on writer PKs, which are…

… db-dependent after r12797.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13015 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b5dc7945bd7de5bc2784d69a5e82e7fc1f069de8 1 parent 5a3521f
@kmtracey kmtracey authored
Showing with 32 additions and 32 deletions.
  1. +32 −32 tests/modeltests/model_forms/models.py
View
64 tests/modeltests/model_forms/models.py
@@ -523,10 +523,10 @@ class CustomFieldForExclusionModel(models.Model):
ValueError: The Category could not be created because the data didn't validate.
Create a couple of Writers.
->>> w = Writer(name='Mike Royko')
->>> w.save()
->>> w = Writer(name='Bob Woodward')
->>> w.save()
+>>> w_royko = Writer(name='Mike Royko')
+>>> w_royko.save()
+>>> w_woodward = Writer(name='Bob Woodward')
+>>> w_woodward.save()
ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any
fields with the 'choices' attribute are represented by a ChoiceField.
@@ -540,8 +540,8 @@ class CustomFieldForExclusionModel(models.Model):
<tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr>
<tr><th>Writer:</th><td><select name="writer">
<option value="" selected="selected">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2">Bob Woodward</option>
+<option value="...">Mike Royko</option>
+<option value="...">Bob Woodward</option>
</select></td></tr>
<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
<tr><th>Status:</th><td><select name="status">
@@ -595,8 +595,8 @@ class CustomFieldForExclusionModel(models.Model):
<li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
<li>Writer: <select name="writer">
<option value="">---------</option>
-<option value="1" selected="selected">Mike Royko</option>
-<option value="2">Bob Woodward</option>
+<option value="..." selected="selected">Mike Royko</option>
+<option value="...">Bob Woodward</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
<li>Status: <select name="status">
@@ -610,7 +610,7 @@ class CustomFieldForExclusionModel(models.Model):
<option value="2">It&#39;s a test</option>
<option value="3">Third test</option>
</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>
->>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art)
+>>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': unicode(w_royko.pk), 'article': 'Hello.'}, instance=art)
>>> f.errors
{}
>>> f.is_valid()
@@ -658,8 +658,8 @@ class CustomFieldForExclusionModel(models.Model):
<li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
<li>Writer: <select name="writer">
<option value="">---------</option>
-<option value="1" selected="selected">Mike Royko</option>
-<option value="2">Bob Woodward</option>
+<option value="..." selected="selected">Mike Royko</option>
+<option value="...">Bob Woodward</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
<li>Status: <select name="status">
@@ -682,8 +682,8 @@ class CustomFieldForExclusionModel(models.Model):
<li>Pub date: <input type="text" name="pub_date" /></li>
<li>Writer: <select name="writer">
<option value="" selected="selected">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2">Bob Woodward</option>
+<option value="...">Mike Royko</option>
+<option value="...">Bob Woodward</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
<li>Status: <select name="status">
@@ -699,7 +699,7 @@ class CustomFieldForExclusionModel(models.Model):
</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>
>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
-... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
+... 'writer': unicode(w_royko.pk), 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
>>> new_art = f.save()
>>> new_art.id
1
@@ -709,7 +709,7 @@ class CustomFieldForExclusionModel(models.Model):
Now, submit form data with no categories. This deletes the existing categories.
>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
-... 'writer': u'1', 'article': u'Hello.'}, instance=new_art)
+... 'writer': unicode(w_royko.pk), 'article': u'Hello.'}, instance=new_art)
>>> new_art = f.save()
>>> new_art.id
1
@@ -722,7 +722,7 @@ class CustomFieldForExclusionModel(models.Model):
... class Meta:
... model = Article
>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01',
-... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']})
+... 'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']})
>>> new_art = f.save()
>>> new_art.id
2
@@ -735,7 +735,7 @@ class CustomFieldForExclusionModel(models.Model):
... class Meta:
... model = Article
>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01',
-... 'writer': u'1', 'article': u'Test.'})
+... 'writer': unicode(w_royko.pk), 'article': u'Test.'})
>>> new_art = f.save()
>>> new_art.id
3
@@ -749,7 +749,7 @@ class CustomFieldForExclusionModel(models.Model):
... class Meta:
... model = Article
>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': 'walrus-was-paul', 'pub_date': u'1967-11-01',
-... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']})
+... 'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']})
>>> new_art = f.save(commit=False)
# Manually save the instance
@@ -798,8 +798,8 @@ class CustomFieldForExclusionModel(models.Model):
<li>Pub date: <input type="text" name="pub_date" /></li>
<li>Writer: <select name="writer">
<option value="" selected="selected">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2">Bob Woodward</option>
+<option value="...">Mike Royko</option>
+<option value="...">Bob Woodward</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
<li>Status: <select name="status">
@@ -823,9 +823,9 @@ class CustomFieldForExclusionModel(models.Model):
<li>Pub date: <input type="text" name="pub_date" /></li>
<li>Writer: <select name="writer">
<option value="" selected="selected">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2">Bob Woodward</option>
-<option value="3">Carl Bernstein</option>
+<option value="...">Mike Royko</option>
+<option value="...">Bob Woodward</option>
+<option value="...">Carl Bernstein</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
<li>Status: <select name="status">
@@ -1047,15 +1047,15 @@ class CustomFieldForExclusionModel(models.Model):
>>> print form.as_p()
<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
<option value="" selected="selected">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2">Bob Woodward</option>
-<option value="3">Carl Bernstein</option>
-<option value="4">Joe Better</option>
+<option value="...">Mike Royko</option>
+<option value="...">Bob Woodward</option>
+<option value="...">Carl Bernstein</option>
+<option value="...">Joe Better</option>
</select></p>
<p><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>
>>> data = {
-... 'writer': u'2',
+... 'writer': unicode(w_woodward.pk),
... 'age': u'65',
... }
>>> form = WriterProfileForm(data)
@@ -1067,10 +1067,10 @@ class CustomFieldForExclusionModel(models.Model):
>>> print form.as_p()
<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
<option value="">---------</option>
-<option value="1">Mike Royko</option>
-<option value="2" selected="selected">Bob Woodward</option>
-<option value="3">Carl Bernstein</option>
-<option value="4">Joe Better</option>
+<option value="...">Mike Royko</option>
+<option value="..." selected="selected">Bob Woodward</option>
+<option value="...">Carl Bernstein</option>
+<option value="...">Joe Better</option>
</select></p>
<p><label for="id_age">Age:</label> <input type="text" name="age" value="65" id="id_age" /></p>

0 comments on commit b5dc794

Please sign in to comment.
Something went wrong with that request. Please try again.