Refs #27953 -- Removed hardcoded uses of Model.__str__() in tests.
This commit is contained in:
parent
0877989c94
commit
7c9cb1ed37
|
@ -186,7 +186,7 @@ class ChangeListTests(TestCase):
|
|||
link = reverse('admin:admin_changelist_child_change', args=(new_child.id,))
|
||||
row_html = (
|
||||
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
|
||||
'<td class="field-parent nowrap">Parent object</td></tr></tbody>' % link
|
||||
'<td class="field-parent nowrap">%s</td></tr></tbody>' % (link, new_parent)
|
||||
)
|
||||
self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ class Article(models.Model):
|
|||
hist = models.CharField(max_length=100, verbose_name=_("History"))
|
||||
created = models.DateTimeField(null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
def test_from_model(self):
|
||||
return "nothing"
|
||||
|
||||
|
|
|
@ -120,23 +120,23 @@ class LogEntryTests(TestCase):
|
|||
json.loads(logentry.change_message),
|
||||
[
|
||||
{"changed": {"fields": ["domain"]}},
|
||||
{"added": {"object": "Article object", "name": "article"}},
|
||||
{"changed": {"fields": ["title"], "object": "Article object", "name": "article"}},
|
||||
{"deleted": {"object": "Article object", "name": "article"}},
|
||||
{"added": {"object": "Added article", "name": "article"}},
|
||||
{"changed": {"fields": ["title"], "object": "Changed Title", "name": "article"}},
|
||||
{"deleted": {"object": "Title second article", "name": "article"}},
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
logentry.get_change_message(),
|
||||
'Changed domain. Added article "Article object". '
|
||||
'Changed title for article "Article object". Deleted article "Article object".'
|
||||
'Changed domain. Added article "Added article". '
|
||||
'Changed title for article "Changed Title". Deleted article "Title second article".'
|
||||
)
|
||||
|
||||
with translation.override('fr'):
|
||||
self.assertEqual(
|
||||
logentry.get_change_message(),
|
||||
"Modification de domain. Ajout de article « Article object ». "
|
||||
"Modification de title pour l'objet article « Article object ». "
|
||||
"Suppression de article « Article object »."
|
||||
"Modification de domain. Ajout de article « Added article ». "
|
||||
"Modification de title pour l'objet article « Changed Title ». "
|
||||
"Suppression de article « Title second article »."
|
||||
)
|
||||
|
||||
def test_logentry_get_edited_object(self):
|
||||
|
|
|
@ -891,11 +891,11 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||
ModelAdmin.changelist_view shouldn't result in a NoReverseMatch if url
|
||||
for change_view is removed from get_urls (#20934).
|
||||
"""
|
||||
UnchangeableObject.objects.create()
|
||||
o = UnchangeableObject.objects.create()
|
||||
response = self.client.get(reverse('admin:admin_views_unchangeableobject_changelist'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# Check the format of the shown object -- shouldn't contain a change link
|
||||
self.assertContains(response, '<th class="field-__str__">UnchangeableObject object</th>', html=True)
|
||||
self.assertContains(response, '<th class="field-__str__">%s</th>' % o, html=True)
|
||||
|
||||
def test_invalid_appindex_url(self):
|
||||
"""
|
||||
|
@ -3306,7 +3306,7 @@ class AdminActionsTest(TestCase):
|
|||
# No 500 caused by NoReverseMatch
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# The page shouldn't display a link to the nonexistent change page
|
||||
self.assertContains(response, "<li>Unchangeable object: UnchangeableObject object</li>", 1, html=True)
|
||||
self.assertContains(response, "<li>Unchangeable object: %s</li>" % obj, 1, html=True)
|
||||
|
||||
def test_custom_function_mail_action(self):
|
||||
"Tests a custom action defined in a function"
|
||||
|
@ -3692,12 +3692,12 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(ShortMessage.objects.count(), 1)
|
||||
# Message should contain non-ugly model verbose name
|
||||
pk = ShortMessage.objects.all()[0].pk
|
||||
sm = ShortMessage.objects.all()[0]
|
||||
self.assertContains(
|
||||
response,
|
||||
'<li class="success">The short message "<a href="%s">'
|
||||
'ShortMessage object</a>" was added successfully.</li>' %
|
||||
reverse('admin:admin_views_shortmessage_change', args=(pk,)), html=True
|
||||
'%s</a>" was added successfully.</li>' %
|
||||
(reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)), sm), html=True
|
||||
)
|
||||
|
||||
def test_add_model_modeladmin_only_qs(self):
|
||||
|
@ -3733,12 +3733,12 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Paper.objects.count(), 1)
|
||||
# Message should contain non-ugly model verbose name
|
||||
pk = Paper.objects.all()[0].pk
|
||||
p = Paper.objects.all()[0]
|
||||
self.assertContains(
|
||||
response,
|
||||
'<li class="success">The paper "<a href="%s">'
|
||||
'Paper object</a>" was added successfully.</li>' %
|
||||
reverse('admin:admin_views_paper_change', args=(pk,)), html=True
|
||||
'%s</a>" was added successfully.</li>' %
|
||||
(reverse('admin:admin_views_paper_change', args=(p.pk,)), p), html=True
|
||||
)
|
||||
|
||||
def test_edit_model_modeladmin_defer_qs(self):
|
||||
|
@ -3786,8 +3786,8 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
self.assertContains(
|
||||
response,
|
||||
'<li class="success">The short message "<a href="%s">'
|
||||
'ShortMessage object</a>" was changed successfully.</li>' %
|
||||
reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)), html=True
|
||||
'%s</a>" was changed successfully.</li>' %
|
||||
(reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)), sm), html=True
|
||||
)
|
||||
|
||||
def test_edit_model_modeladmin_only_qs(self):
|
||||
|
@ -3833,8 +3833,8 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
self.assertContains(
|
||||
response,
|
||||
'<li class="success">The paper "<a href="%s">'
|
||||
'Paper object</a>" was changed successfully.</li>' %
|
||||
reverse('admin:admin_views_paper_change', args=(p.pk,)), html=True
|
||||
'%s</a>" was changed successfully.</li>' %
|
||||
(reverse('admin:admin_views_paper_change', args=(p.pk,)), p), html=True
|
||||
)
|
||||
|
||||
def test_history_view_custom_qs(self):
|
||||
|
|
|
@ -520,8 +520,8 @@ class ForeignKeyRawIdWidgetTest(TestCase):
|
|||
self.assertHTMLEqual(
|
||||
w.render('honeycomb_widget', big_honeycomb.pk, attrs={}),
|
||||
'<input type="text" name="honeycomb_widget" value="%(hcombpk)s" />'
|
||||
' <strong>Honeycomb object</strong>'
|
||||
% {'hcombpk': big_honeycomb.pk}
|
||||
' <strong>%(hcomb)s</strong>'
|
||||
% {'hcombpk': big_honeycomb.pk, 'hcomb': big_honeycomb}
|
||||
)
|
||||
|
||||
def test_fk_to_self_model_not_in_admin(self):
|
||||
|
@ -535,8 +535,8 @@ class ForeignKeyRawIdWidgetTest(TestCase):
|
|||
self.assertHTMLEqual(
|
||||
w.render('individual_widget', subject1.pk, attrs={}),
|
||||
'<input type="text" name="individual_widget" value="%(subj1pk)s" />'
|
||||
' <strong>Individual object</strong>'
|
||||
% {'subj1pk': subject1.pk}
|
||||
' <strong>%(subj1)s</strong>'
|
||||
% {'subj1pk': subject1.pk, 'subj1': subject1}
|
||||
)
|
||||
|
||||
def test_proper_manager_for_label_lookup(self):
|
||||
|
|
|
@ -21,9 +21,9 @@ class TestFloatField(TestCase):
|
|||
instance.size = instance
|
||||
msg = (
|
||||
'Tried to update field model_fields.FloatModel.size with a model '
|
||||
'instance, <FloatModel: FloatModel object>. Use a value '
|
||||
'instance, %r. Use a value '
|
||||
'compatible with FloatField.'
|
||||
)
|
||||
) % instance
|
||||
with transaction.atomic():
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
instance.save()
|
||||
|
|
Loading…
Reference in New Issue