diff options
| author | Ian Kelly <ian.g.kelly@gmail.com> | 2011-03-10 00:04:43 +0000 |
|---|---|---|
| committer | Ian Kelly <ian.g.kelly@gmail.com> | 2011-03-10 00:04:43 +0000 |
| commit | ec7dd583f2b33aa9a575530fbec215426348fdf6 (patch) | |
| tree | ff98d0dcfa506719d905d2a408663b5390673830 /tests/regressiontests | |
| parent | 317f30a77f744281137cde87ca59855761c8e86e (diff) | |
[1.2.X] Fixed a bunch more tests that were failing in Oracle due to false assumptions about the primary keys of objects.
Backport of r15789 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15790 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/admin_changelist/tests.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/fixtures_regress/tests.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/model_fields/tests.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/model_forms_regress/tests.py | 20 | ||||
| -rw-r--r-- | tests/regressiontests/null_fk/tests.py | 12 | ||||
| -rw-r--r-- | tests/regressiontests/select_related_regress/tests.py | 4 |
6 files changed, 26 insertions, 25 deletions
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py index e3b21ad925..bb6e00a10c 100644 --- a/tests/regressiontests/admin_changelist/tests.py +++ b/tests/regressiontests/admin_changelist/tests.py @@ -32,7 +32,7 @@ class ChangeListTests(TransactionTestCase): template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') context = Context({'cl': cl}) table_output = template.render(context) - row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' + row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % (new_child.id, new_child.id) self.assertFalse(table_output.find(row_html) == -1, 'Failed to find expected row element: %s' % table_output) @@ -53,7 +53,7 @@ class ChangeListTests(TransactionTestCase): template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') context = Context({'cl': cl}) table_output = template.render(context) - row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' + row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % (new_child.id, new_child.id) self.assertFalse(table_output.find(row_html) == -1, 'Failed to find expected row element: %s' % table_output) @@ -84,7 +84,7 @@ class ChangeListTests(TransactionTestCase): context = Context({'cl': cl}) table_output = template.render(context) # make sure that hidden fields are in the correct place - hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>' + hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /></div>' % new_child.id self.assertFalse(table_output.find(hiddenfields_div) == -1, 'Failed to find hidden fields in: %s' % table_output) # make sure that list editable fields are rendered in divs correctly diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 98b9fd6747..c2312c92ac 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -349,7 +349,7 @@ class TestFixtures(TestCase): """ stdout = StringIO() # Create an instance of the concrete class - Widget(name='grommet').save() + widget = Widget.objects.create(name='grommet') management.call_command( 'dumpdata', 'fixtures_regress.widget', @@ -359,7 +359,8 @@ class TestFixtures(TestCase): ) self.assertEqual( stdout.getvalue(), - """[{"pk": 1, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]""" + """[{"pk": %d, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]""" + % widget.pk ) diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py index 6835913f12..f4bc63be7c 100644 --- a/tests/regressiontests/model_fields/tests.py +++ b/tests/regressiontests/model_fields/tests.py @@ -115,8 +115,8 @@ class ForeignKeyTests(django.test.TestCase): bar_b = Bar.objects.create(b='bla', a=b) form = BazForm() fk_field = str(form['foo']) - self.assertEqual(len(re.findall(r'value="2"', fk_field)), 0) - self.assertEqual(len(re.findall(r'value="1"', fk_field)), 1) + self.assertEqual(len(re.findall(r'value="%d"' % b.pk, fk_field)), 0) + self.assertEqual(len(re.findall(r'value="%d"' % a.pk, fk_field)), 1) class DateTimeFieldTests(unittest.TestCase): def test_datetimefield_to_python_usecs(self): diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py index 1d0d6ed017..9a0ef2e117 100644 --- a/tests/regressiontests/model_forms_regress/tests.py +++ b/tests/regressiontests/model_forms_regress/tests.py @@ -23,12 +23,11 @@ class ModelMultipleChoiceFieldTests(TestCase): Test that ModelMultipleChoiceField does O(1) queries instead of O(n) (#10156). """ - for i in range(30): - Person.objects.create(name="Person %s" % i) + persons = [Person.objects.create(name="Person %s" % i) for i in range(30)] db.reset_queries() f = forms.ModelMultipleChoiceField(queryset=Person.objects.all()) - selected = f.clean([1, 3, 5, 7, 9]) + selected = f.clean([p.pk for p in persons[1:11:2]]) self.assertEquals(len(db.connection.queries), 1) def test_model_multiple_choice_run_validators(self): @@ -133,19 +132,20 @@ class ManyToManyCallableInitialTests(TestCase): return db_field.formfield(**kwargs) # Set up some Publications to use as data - Publication(title="First Book", date_published=date(2007,1,1)).save() - Publication(title="Second Book", date_published=date(2008,1,1)).save() - Publication(title="Third Book", date_published=date(2009,1,1)).save() + book1 = Publication.objects.create(title="First Book", date_published=date(2007,1,1)) + book2 = Publication.objects.create(title="Second Book", date_published=date(2008,1,1)) + book3 = Publication.objects.create(title="Third Book", date_published=date(2009,1,1)) # Create a ModelForm, instantiate it, and check that the output is as expected ModelForm = modelform_factory(Article, formfield_callback=formfield_for_dbfield) form = ModelForm() self.assertEquals(form.as_ul(), u"""<li><label for="id_headline">Headline:</label> <input id="id_headline" type="text" name="headline" maxlength="100" /></li> <li><label for="id_publications">Publications:</label> <select multiple="multiple" name="publications" id="id_publications"> -<option value="1" selected="selected">First Book</option> -<option value="2" selected="selected">Second Book</option> -<option value="3">Third Book</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>""") +<option value="%d" selected="selected">First Book</option> +<option value="%d" selected="selected">Second Book</option> +<option value="%d">Third Book</option> +</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>""" + % (book1.pk, book2.pk, book3.pk)) class CFFForm(forms.ModelForm): class Meta: diff --git a/tests/regressiontests/null_fk/tests.py b/tests/regressiontests/null_fk/tests.py index 449f3438a4..60d01fcfc8 100644 --- a/tests/regressiontests/null_fk/tests.py +++ b/tests/regressiontests/null_fk/tests.py @@ -16,15 +16,15 @@ class NullFkTests(TestCase): # set of fields will properly LEFT JOIN multiple levels of NULLs (and the things # that come after the NULLs, or else data that should exist won't). Regression # test for #7369. - c = Comment.objects.select_related().get(id=1) + c = Comment.objects.select_related().get(id=c1.id) self.assertEquals(c.post, p) - self.assertEquals(Comment.objects.select_related().get(id=2).post, None) + self.assertEquals(Comment.objects.select_related().get(id=c2.id).post, None) self.assertQuerysetEqual( Comment.objects.select_related('post__forum__system_info').all(), [ - (1, u'My first comment', '<Post: First Post>'), - (2, u'My second comment', 'None') + (c1.id, u'My first comment', '<Post: First Post>'), + (c2.id, u'My second comment', 'None') ], transform = lambda c: (c.id, c.comment_text, repr(c.post)) ) @@ -35,8 +35,8 @@ class NullFkTests(TestCase): self.assertQuerysetEqual( Comment.objects.select_related('post__forum__system_info__system_details'), [ - (1, u'My first comment', '<Post: First Post>'), - (2, u'My second comment', 'None') + (c1.id, u'My first comment', '<Post: First Post>'), + (c2.id, u'My second comment', 'None') ], transform = lambda c: (c.id, c.comment_text, repr(c.post)) ) diff --git a/tests/regressiontests/select_related_regress/tests.py b/tests/regressiontests/select_related_regress/tests.py index bfa1e2154b..5f2c7d4e80 100644 --- a/tests/regressiontests/select_related_regress/tests.py +++ b/tests/regressiontests/select_related_regress/tests.py @@ -28,11 +28,11 @@ class SelectRelatedRegressTests(TestCase): connections=Connection.objects.filter(start__device__building=b, end__device__building=b).order_by('id') self.assertEquals([(c.id, unicode(c.start), unicode(c.end)) for c in connections], - [(1, u'router/4', u'switch/7'), (2, u'switch/7', u'server/1')]) + [(c1.id, u'router/4', u'switch/7'), (c2.id, u'switch/7', u'server/1')]) connections=Connection.objects.filter(start__device__building=b, end__device__building=b).select_related().order_by('id') self.assertEquals([(c.id, unicode(c.start), unicode(c.end)) for c in connections], - [(1, u'router/4', u'switch/7'), (2, u'switch/7', u'server/1')]) + [(c1.id, u'router/4', u'switch/7'), (c2.id, u'switch/7', u'server/1')]) # This final query should only join seven tables (port, device and building # twice each, plus connection once). |
