forked from noripyt/django-cachalot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test that will cause error noripyt#226
- Loading branch information
1 parent
52406ec
commit c2b5b02
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
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,6 @@ | ||
from django.contrib import admin | ||
from .models import TestModel | ||
|
||
@admin.register(TestModel) | ||
class TestModelAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'owner') |
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,19 @@ | ||
from django.conf import settings | ||
from django.db.models import Q, UniqueConstraint, Model, CharField, ForeignKey, SET_NULL | ||
from django.db.models.functions import Lower | ||
|
||
|
||
class TestModel(Model): | ||
name = CharField(max_length=20) | ||
owner = ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, | ||
on_delete=SET_NULL) | ||
|
||
class Meta: | ||
ordering = ('name',) | ||
constraints = [ | ||
UniqueConstraint( | ||
Lower("name").desc(), | ||
condition=Q(owner=None), | ||
name="unique_name", | ||
) | ||
] |
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,19 @@ | ||
from django.test import TestCase | ||
from django.contrib.auth.models import User | ||
from .models import TestModel | ||
from django.test import Client | ||
|
||
|
||
class AdminTestCase(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
self.user = User.objects.create(username='admin', is_staff=True, is_superuser=True) | ||
|
||
def test_save_test_model(self): | ||
""" | ||
Model 'TestModel' has UniqueConstraint which caused problems when saving TestModelAdmin in Django >= 4.1 | ||
""" | ||
self.client.force_login(self.user) | ||
response = self.client.post('/admin/tests/test/add/', {'name': 'test', 'public': True}) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(Test.objects.count(), 1) |
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