Skip to content

Commit 5a247e8

Browse files
committed
edits for many test apps
1 parent 9b8ae4b commit 5a247e8

File tree

20 files changed

+74
-59
lines changed

20 files changed

+74
-59
lines changed

tests/admin_utils/test_logentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_logentry_get_admin_url(self):
202202
"admin:admin_utils_article_change", args=(quote(self.a1.pk),)
203203
)
204204
self.assertEqual(logentry.get_admin_url(), expected_url)
205-
self.assertIn("article/%d/change/" % self.a1.pk, logentry.get_admin_url())
205+
self.assertIn("article/%s/change/" % self.a1.pk, logentry.get_admin_url())
206206

207207
logentry.content_type.model = "nonexistent"
208208
self.assertIsNone(logentry.get_admin_url())

tests/auth_tests/test_context_processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_user_attrs(self):
140140
user = authenticate(username="super", password="secret")
141141
response = self.client.get("/auth_processor_user/")
142142
self.assertContains(response, "unicode: super")
143-
self.assertContains(response, "id: %d" % self.superuser.pk)
143+
self.assertContains(response, "id: %s" % self.superuser.pk)
144144
self.assertContains(response, "username: super")
145145
# bug #12037 is tested by the {% url %} in the template:
146146
self.assertContains(response, "url: /userpage/super/")

tests/auth_tests/test_management.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,12 @@ def test_validate_fk(self):
610610

611611
@override_settings(AUTH_USER_MODEL="auth_tests.CustomUserWithFK")
612612
def test_validate_fk_environment_variable(self):
613+
from bson import ObjectId
614+
613615
email = Email.objects.create(email="[email protected]")
614616
Group.objects.all().delete()
615-
nonexistent_group_id = 1
616-
msg = f"group instance with id {nonexistent_group_id} does not exist."
617+
nonexistent_group_id = ObjectId()
618+
msg = f"group instance with id {nonexistent_group_id!r} does not exist."
617619

618620
with mock.patch.dict(
619621
os.environ,
@@ -1532,5 +1534,5 @@ def test_set_permissions_fk_to_using_parameter(self):
15321534
Permission.objects.using("other").delete()
15331535
with self.assertNumQueries(6, using="other") as captured_queries:
15341536
create_permissions(apps.get_app_config("auth"), verbosity=0, using="other")
1535-
self.assertIn("INSERT INTO", captured_queries[-1]["sql"].upper())
1537+
self.assertIn("INSERT_MANY", captured_queries[-1]["sql"].upper())
15361538
self.assertGreater(Permission.objects.using("other").count(), 0)

tests/contenttypes_tests/test_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_get_object_cache_respects_deleted_objects(self):
3333

3434
post = Post.objects.get(pk=post.pk)
3535
with self.assertNumQueries(1):
36-
self.assertEqual(post.object_id, question_pk)
36+
self.assertEqual(post.object_id, str(question_pk))
3737
self.assertIsNone(post.parent)
3838
self.assertIsNone(post.parent)
3939

tests/contenttypes_tests/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from django.urls import re_path
33

44
urlpatterns = [
5-
re_path(r"^shortcut/([0-9]+)/(.*)/$", views.shortcut),
5+
re_path(r"^shortcut/([\w]+)/(.*)/$", views.shortcut),
66
]

tests/custom_columns/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
1616
"""
1717

18+
from django_mongodb.fields import ObjectIdAutoField
19+
1820
from django.db import models
1921

2022

2123
class Author(models.Model):
22-
Author_ID = models.AutoField(primary_key=True, db_column="Author ID")
24+
Author_ID = ObjectIdAutoField(primary_key=True, db_column="Author ID")
2325
first_name = models.CharField(max_length=30, db_column="firstname")
2426
last_name = models.CharField(max_length=30, db_column="last")
2527

@@ -32,7 +34,7 @@ def __str__(self):
3234

3335

3436
class Article(models.Model):
35-
Article_ID = models.AutoField(primary_key=True, db_column="Article ID")
37+
Article_ID = ObjectIdAutoField(primary_key=True, db_column="Article ID")
3638
headline = models.CharField(max_length=100)
3739
authors = models.ManyToManyField(Author, db_table="my_m2m_table")
3840
primary_author = models.ForeignKey(

tests/file_uploads/tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from unittest import mock
1010
from urllib.parse import quote
1111

12+
from bson import ObjectId
13+
1214
from django.conf import DEFAULT_STORAGE_ALIAS
1315
from django.core.exceptions import SuspiciousFileOperation
1416
from django.core.files import temp as tempfile
@@ -740,7 +742,7 @@ def test_filename_case_preservation(self):
740742
"multipart/form-data; boundary=%(boundary)s" % vars,
741743
)
742744
self.assertEqual(response.status_code, 200)
743-
id = int(response.content)
745+
id = ObjectId(response.content.decode())
744746
obj = FileModel.objects.get(pk=id)
745747
# The name of the file uploaded and the file stored in the server-side
746748
# shouldn't differ.

tests/file_uploads/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def file_upload_filename_case_view(request):
156156
file = request.FILES["file_field"]
157157
obj = FileModel()
158158
obj.testfile.save(file.name, file)
159-
return HttpResponse("%d" % obj.pk)
159+
return HttpResponse("%s" % obj.pk)
160160

161161

162162
def file_upload_content_type_extra(request):

tests/forms_tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Meta:
6868
ordering = ("name",)
6969

7070
def __str__(self):
71-
return "ChoiceOption %d" % self.pk
71+
return "ChoiceOption %s" % self.pk
7272

7373

7474
def choice_default():

tests/generic_relations_regress/tests.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def test_annotate(self):
251251
HasLinkThing.objects.create()
252252
b = Board.objects.create(name=str(hs1.pk))
253253
Link.objects.create(content_object=hs2)
254-
link = Link.objects.create(content_object=hs1)
254+
# An integer PK is required for the Sum() queryset that follows.
255+
link = Link.objects.create(content_object=hs1, pk=10)
255256
Link.objects.create(content_object=b)
256257
qs = HasLinkThing.objects.annotate(Sum("links")).filter(pk=hs1.pk)
257258
# If content_type restriction isn't in the query's join condition,
@@ -265,11 +266,11 @@ def test_annotate(self):
265266
# clear cached results
266267
qs = qs.all()
267268
self.assertEqual(qs.count(), 1)
268-
# Note - 0 here would be a nicer result...
269-
self.assertIs(qs[0].links__sum, None)
269+
# Unlike other databases, MongoDB returns 0 instead of null (None).
270+
self.assertIs(qs[0].links__sum, 0)
270271
# Finally test that filtering works.
271-
self.assertEqual(qs.filter(links__sum__isnull=True).count(), 1)
272-
self.assertEqual(qs.filter(links__sum__isnull=False).count(), 0)
272+
self.assertEqual(qs.filter(links__sum__isnull=True).count(), 0)
273+
self.assertEqual(qs.filter(links__sum__isnull=False).count(), 1)
273274

274275
def test_filter_targets_related_pk(self):
275276
# Use hardcoded PKs to ensure different PKs for "link" and "hs2"

0 commit comments

Comments
 (0)