-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/migrations/0004_add_model_with_string_primary_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.2.5 on 2023-09-19 10:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("tests", "0003_fieldsetsadminmodel_alter_customadminmodel_id_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="StringAdminModel", | ||
fields=[ | ||
( | ||
"primary", | ||
models.CharField(max_length=32, primary_key=True, serialize=False), | ||
), | ||
("name", models.CharField(max_length=32)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from django.contrib.auth.models import User | ||
from django.contrib import admin | ||
from django.test import TestCase, override_settings, RequestFactory | ||
|
||
try: | ||
from django.urls import reverse | ||
except ImportError: # Django<2.0 | ||
|
@@ -14,6 +15,7 @@ | |
CustomAdminModel2, | ||
InheritedAdminModel, | ||
FieldsetsAdminModel, | ||
StringAdminModel, | ||
) | ||
from .site import CustomAdminSite | ||
from .mocks import MockRenderMassAdmin | ||
|
@@ -76,6 +78,20 @@ def test_update(self, admin_name='admin'): | |
# all models have changed | ||
self.assertEqual(list(new_names), ["new name"] * 3) | ||
|
||
def test_update_with_string_primary_key_and_special_chars(self, admin_name='admin'): | ||
models = [StringAdminModel.objects.create( | ||
primary="{}/3".format(1 + i), | ||
name="model {}".format(i), | ||
) for i in range(0, 3)] | ||
|
||
response = self.client.post(get_massadmin_url(models, self.client.session), | ||
{"_mass_change": "name", | ||
"name": "new name"}) | ||
self.assertRedirects(response, get_changelist_url(StringAdminModel, admin_name)) | ||
new_names = StringAdminModel.objects.order_by("pk").values_list("name", flat=True) | ||
# all models have changed | ||
self.assertEqual(list(new_names), ["new name"] * 3) | ||
|
||
@override_settings(ROOT_URLCONF='tests.urls_custom_admin') | ||
def test_custom_admin_site_update(self): | ||
""" We test_update for a custom admin on top of a regular as well | ||
|
@@ -164,6 +180,7 @@ def test_excluded_queryset(self): | |
class CustomizationTestCase(TestCase): | ||
""" MassAdmin has all customized options from related ModelAdmin | ||
""" | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_superuser( | ||
'temporary', '[email protected]', 'temporary') | ||
|