From d007fcf7291cc3c24d4545e23c759bde22b6a8a6 Mon Sep 17 00:00:00 2001
From: Tim Graham %d ' % story1.id, 1)
- self.assertContains(response, '%d ' % story2.id, 1)
+ self.assertContains(response, '%s ' % story1.id, 1)
+ self.assertContains(response, '%s ' % story2.id, 1)
def test_pk_hidden_fields_with_list_display_links(self):
"""Similarly as test_pk_hidden_fields, but when the hidden pk fields
@@ -4798,19 +4798,19 @@ class AdminViewListEditable(TestCase):
self.assertContains(
response,
'%d ' % (link1, story1.id),
+ '%s ' % (link1, story1.id),
1,
)
self.assertContains(
response,
- '%d ' % (link2, story2.id),
+ '%s ' % (link2, story2.id),
1,
)
@@ -7321,7 +7321,7 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
response = self.client.get(
reverse("admin:admin_views_post_change", args=(p.pk,))
)
- self.assertContains(response, "%d amount of cool" % p.pk)
+ self.assertContains(response, "%s amount of cool" % p.pk)
def test_readonly_text_field(self):
p = Post.objects.create(
diff --git a/tests/auth_tests/test_context_processors.py b/tests/auth_tests/test_context_processors.py
index cebc1108dc..85b9e6367b 100644
--- a/tests/auth_tests/test_context_processors.py
+++ b/tests/auth_tests/test_context_processors.py
@@ -140,7 +140,7 @@ class AuthContextProcessorTests(TestCase):
user = authenticate(username="super", password="secret")
response = self.client.get("/auth_processor_user/")
self.assertContains(response, "unicode: super")
- self.assertContains(response, "id: %d" % self.superuser.pk)
+ self.assertContains(response, "id: %s" % self.superuser.pk)
self.assertContains(response, "username: super")
# bug #12037 is tested by the {% url %} in the template:
self.assertContains(response, "url: /userpage/super/")
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 0701ac2d68..f5027da4e5 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -607,7 +607,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
+ msg = f"group instance with id {nonexistent_group_id!r} is not a valid choice."
with self.assertRaisesMessage(CommandError, msg):
call_command(
@@ -624,7 +624,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
+ msg = f"group instance with id {nonexistent_group_id!r} is not a valid choice."
with mock.patch.dict(
os.environ,
@@ -644,7 +644,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
+ msg = f"group instance with id {nonexistent_group_id!r} is not a valid choice."
@mock_inputs(
{
diff --git a/tests/file_uploads/views.py b/tests/file_uploads/views.py
index f4f3b5c514..49916845d0 100644
--- a/tests/file_uploads/views.py
+++ b/tests/file_uploads/views.py
@@ -157,7 +157,7 @@ def file_upload_filename_case_view(request):
file = request.FILES["file_field"]
obj = FileModel()
obj.testfile.save(file.name, file)
- return HttpResponse("%d" % obj.pk)
+ return HttpResponse("%s" % obj.pk)
def file_upload_content_type_extra(request):
diff --git a/tests/forms_tests/models.py b/tests/forms_tests/models.py
index d6d0725b32..b1319abe17 100644
--- a/tests/forms_tests/models.py
+++ b/tests/forms_tests/models.py
@@ -68,7 +68,7 @@ class ChoiceOptionModel(models.Model):
ordering = ("name",)
def __str__(self):
- return "ChoiceOption %d" % self.pk
+ return "ChoiceOption %s" % self.pk
def choice_default():
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 140083d315..d12b1f6baa 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -895,7 +895,7 @@ class DateDetailViewTests(TestDataMixin, TestCase):
def test_datetime_date_detail(self):
bs = BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0))
- res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk)
+ res = self.client.get("/dates/booksignings/2008/apr/2/%s/" % bs.pk)
self.assertEqual(res.status_code, 200)
@requires_tz_support
@@ -904,17 +904,17 @@ class DateDetailViewTests(TestDataMixin, TestCase):
bs = BookSigning.objects.create(
event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=datetime.UTC)
)
- res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk)
+ res = self.client.get("/dates/booksignings/2008/apr/2/%s/" % bs.pk)
self.assertEqual(res.status_code, 200)
# 2008-04-02T00:00:00+03:00 (beginning of day) >
# 2008-04-01T22:00:00+00:00 (book signing event date).
bs.event_date = datetime.datetime(2008, 4, 1, 22, 0, tzinfo=datetime.UTC)
bs.save()
- res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk)
+ res = self.client.get("/dates/booksignings/2008/apr/2/%s/" % bs.pk)
self.assertEqual(res.status_code, 200)
# 2008-04-03T00:00:00+03:00 (end of day) > 2008-04-02T22:00:00+00:00
# (book signing event date).
bs.event_date = datetime.datetime(2008, 4, 2, 22, 0, tzinfo=datetime.UTC)
bs.save()
- res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk)
+ res = self.client.get("/dates/booksignings/2008/apr/2/%s/" % bs.pk)
self.assertEqual(res.status_code, 404)
diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py
index d66b316090..b483ea1028 100644
--- a/tests/generic_views/test_edit.py
+++ b/tests/generic_views/test_edit.py
@@ -124,7 +124,7 @@ class CreateViewTests(TestCase):
res = self.client.post("/edit/artists/create/", {"name": "Rene Magritte"})
self.assertEqual(res.status_code, 302)
artist = Artist.objects.get(name="Rene Magritte")
- self.assertRedirects(res, "/detail/artist/%d/" % artist.pk)
+ self.assertRedirects(res, "/detail/artist/%s/" % artist.pk)
self.assertQuerySetEqual(Artist.objects.all(), [artist])
def test_create_with_redirect(self):
@@ -148,7 +148,7 @@ class CreateViewTests(TestCase):
)
self.assertEqual(res.status_code, 302)
pk = Author.objects.first().pk
- self.assertRedirects(res, "/edit/author/%d/update/" % pk)
+ self.assertRedirects(res, "/edit/author/%s/update/" % pk)
# Also test with escaped chars in URL
res = self.client.post(
"/edit/authors/create/interpolate_redirect_nonascii/",
@@ -245,7 +245,7 @@ class UpdateViewTests(TestCase):
)
def test_update_post(self):
- res = self.client.get("/edit/author/%d/update/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/update/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertIsInstance(res.context["form"], forms.ModelForm)
self.assertEqual(res.context["object"], self.author)
@@ -255,7 +255,7 @@ class UpdateViewTests(TestCase):
# Modification with both POST and PUT (browser compatible)
res = self.client.post(
- "/edit/author/%d/update/" % self.author.pk,
+ "/edit/author/%s/update/" % self.author.pk,
{"name": "Randall Munroe (xkcd)", "slug": "randall-munroe"},
)
self.assertEqual(res.status_code, 302)
@@ -266,7 +266,7 @@ class UpdateViewTests(TestCase):
def test_update_invalid(self):
res = self.client.post(
- "/edit/author/%d/update/" % self.author.pk,
+ "/edit/author/%s/update/" % self.author.pk,
{"name": "A" * 101, "slug": "randall-munroe"},
)
self.assertEqual(res.status_code, 200)
@@ -278,15 +278,15 @@ class UpdateViewTests(TestCase):
def test_update_with_object_url(self):
a = Artist.objects.create(name="Rene Magritte")
res = self.client.post(
- "/edit/artists/%d/update/" % a.pk, {"name": "Rene Magritte"}
+ "/edit/artists/%s/update/" % a.pk, {"name": "Rene Magritte"}
)
self.assertEqual(res.status_code, 302)
- self.assertRedirects(res, "/detail/artist/%d/" % a.pk)
+ self.assertRedirects(res, "/detail/artist/%s/" % a.pk)
self.assertQuerySetEqual(Artist.objects.all(), [a])
def test_update_with_redirect(self):
res = self.client.post(
- "/edit/author/%d/update/redirect/" % self.author.pk,
+ "/edit/author/%s/update/redirect/" % self.author.pk,
{"name": "Randall Munroe (author of xkcd)", "slug": "randall-munroe"},
)
self.assertEqual(res.status_code, 302)
@@ -298,7 +298,7 @@ class UpdateViewTests(TestCase):
def test_update_with_interpolated_redirect(self):
res = self.client.post(
- "/edit/author/%d/update/interpolate_redirect/" % self.author.pk,
+ "/edit/author/%s/update/interpolate_redirect/" % self.author.pk,
{"name": "Randall Munroe (author of xkcd)", "slug": "randall-munroe"},
)
self.assertQuerySetEqual(
@@ -307,10 +307,10 @@ class UpdateViewTests(TestCase):
)
self.assertEqual(res.status_code, 302)
pk = Author.objects.first().pk
- self.assertRedirects(res, "/edit/author/%d/update/" % pk)
+ self.assertRedirects(res, "/edit/author/%s/update/" % pk)
# Also test with escaped chars in URL
res = self.client.post(
- "/edit/author/%d/update/interpolate_redirect_nonascii/" % self.author.pk,
+ "/edit/author/%s/update/interpolate_redirect_nonascii/" % self.author.pk,
{"name": "John Doe", "slug": "john-doe"},
)
self.assertEqual(res.status_code, 302)
@@ -318,7 +318,7 @@ class UpdateViewTests(TestCase):
self.assertRedirects(res, "/%C3%A9dit/author/{}/update/".format(pk))
def test_update_with_special_properties(self):
- res = self.client.get("/edit/author/%d/update/special/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/update/special/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertIsInstance(res.context["form"], views.AuthorForm)
self.assertEqual(res.context["object"], self.author)
@@ -327,11 +327,11 @@ class UpdateViewTests(TestCase):
self.assertTemplateUsed(res, "generic_views/form.html")
res = self.client.post(
- "/edit/author/%d/update/special/" % self.author.pk,
+ "/edit/author/%s/update/special/" % self.author.pk,
{"name": "Randall Munroe (author of xkcd)", "slug": "randall-munroe"},
)
self.assertEqual(res.status_code, 302)
- self.assertRedirects(res, "/detail/author/%d/" % self.author.pk)
+ self.assertRedirects(res, "/detail/author/%s/" % self.author.pk)
self.assertQuerySetEqual(
Author.objects.values_list("name", flat=True),
["Randall Munroe (author of xkcd)"],
@@ -344,7 +344,7 @@ class UpdateViewTests(TestCase):
)
with self.assertRaisesMessage(ImproperlyConfigured, msg):
self.client.post(
- "/edit/author/%d/update/naive/" % self.author.pk,
+ "/edit/author/%s/update/naive/" % self.author.pk,
{"name": "Randall Munroe (author of xkcd)", "slug": "randall-munroe"},
)
@@ -379,37 +379,37 @@ class DeleteViewTests(TestCase):
)
def test_delete_by_post(self):
- res = self.client.get("/edit/author/%d/delete/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/delete/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["object"], self.author)
self.assertEqual(res.context["author"], self.author)
self.assertTemplateUsed(res, "generic_views/author_confirm_delete.html")
# Deletion with POST
- res = self.client.post("/edit/author/%d/delete/" % self.author.pk)
+ res = self.client.post("/edit/author/%s/delete/" % self.author.pk)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, "/list/authors/")
self.assertQuerySetEqual(Author.objects.all(), [])
def test_delete_by_delete(self):
# Deletion with browser compatible DELETE method
- res = self.client.delete("/edit/author/%d/delete/" % self.author.pk)
+ res = self.client.delete("/edit/author/%s/delete/" % self.author.pk)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, "/list/authors/")
self.assertQuerySetEqual(Author.objects.all(), [])
def test_delete_with_redirect(self):
- res = self.client.post("/edit/author/%d/delete/redirect/" % self.author.pk)
+ res = self.client.post("/edit/author/%s/delete/redirect/" % self.author.pk)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, "/edit/authors/create/")
self.assertQuerySetEqual(Author.objects.all(), [])
def test_delete_with_interpolated_redirect(self):
res = self.client.post(
- "/edit/author/%d/delete/interpolate_redirect/" % self.author.pk
+ "/edit/author/%s/delete/interpolate_redirect/" % self.author.pk
)
self.assertEqual(res.status_code, 302)
- self.assertRedirects(res, "/edit/authors/create/?deleted=%d" % self.author.pk)
+ self.assertRedirects(res, "/edit/authors/create/?deleted=%s" % self.author.pk)
self.assertQuerySetEqual(Author.objects.all(), [])
# Also test with escaped chars in URL
a = Author.objects.create(
@@ -422,14 +422,14 @@ class DeleteViewTests(TestCase):
self.assertRedirects(res, "/%C3%A9dit/authors/create/?deleted={}".format(a.pk))
def test_delete_with_special_properties(self):
- res = self.client.get("/edit/author/%d/delete/special/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/delete/special/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["object"], self.author)
self.assertEqual(res.context["thingy"], self.author)
self.assertNotIn("author", res.context)
self.assertTemplateUsed(res, "generic_views/confirm_delete.html")
- res = self.client.post("/edit/author/%d/delete/special/" % self.author.pk)
+ res = self.client.post("/edit/author/%s/delete/special/" % self.author.pk)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, "/list/authors/")
self.assertQuerySetEqual(Author.objects.all(), [])
@@ -437,29 +437,29 @@ class DeleteViewTests(TestCase):
def test_delete_without_redirect(self):
msg = "No URL to redirect to. Provide a success_url."
with self.assertRaisesMessage(ImproperlyConfigured, msg):
- self.client.post("/edit/author/%d/delete/naive/" % self.author.pk)
+ self.client.post("/edit/author/%s/delete/naive/" % self.author.pk)
def test_delete_with_form_as_post(self):
- res = self.client.get("/edit/author/%d/delete/form/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/delete/form/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["object"], self.author)
self.assertEqual(res.context["author"], self.author)
self.assertTemplateUsed(res, "generic_views/author_confirm_delete.html")
res = self.client.post(
- "/edit/author/%d/delete/form/" % self.author.pk, data={"confirm": True}
+ "/edit/author/%s/delete/form/" % self.author.pk, data={"confirm": True}
)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, "/list/authors/")
self.assertSequenceEqual(Author.objects.all(), [])
def test_delete_with_form_as_post_with_validation_error(self):
- res = self.client.get("/edit/author/%d/delete/form/" % self.author.pk)
+ res = self.client.get("/edit/author/%s/delete/form/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["object"], self.author)
self.assertEqual(res.context["author"], self.author)
self.assertTemplateUsed(res, "generic_views/author_confirm_delete.html")
- res = self.client.post("/edit/author/%d/delete/form/" % self.author.pk)
+ res = self.client.post("/edit/author/%s/delete/form/" % self.author.pk)
self.assertEqual(res.status_code, 200)
self.assertEqual(len(res.context_data["form"].errors), 2)
self.assertEqual(
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index 4d2343e304..193e6e7086 100644
--- a/tests/many_to_one/tests.py
+++ b/tests/many_to_one/tests.py
@@ -889,7 +889,7 @@ class ManyToOneTests(TestCase):
def test_add_remove_set_by_pk_raises(self):
usa = Country.objects.create(name="United States")
chicago = City.objects.create(name="Chicago")
- msg = "'City' instance expected, got %s" % chicago.pk
+ msg = "'City' instance expected, got %r" % chicago.pk
with self.assertRaisesMessage(TypeError, msg):
usa.cities.add(chicago.pk)
with self.assertRaisesMessage(TypeError, msg):
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 7b086fb182..7f66b5b078 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -347,11 +347,11 @@ class ModelChoiceFieldTests(TestCase):
field.widget.render("name", []),
(
"