2015-01-28 12:35:27 +00:00
|
|
|
|
import datetime
|
2012-02-09 18:59:05 +00:00
|
|
|
|
import os
|
2009-03-10 11:19:26 +00:00
|
|
|
|
import re
|
2013-07-01 20:49:07 +00:00
|
|
|
|
import unittest
|
2017-01-07 11:11:46 +00:00
|
|
|
|
from urllib.parse import parse_qsl, urljoin, urlparse
|
2010-12-04 07:28:12 +00:00
|
|
|
|
|
2017-02-24 15:22:25 +00:00
|
|
|
|
import pytz
|
|
|
|
|
|
2015-09-10 13:05:31 +00:00
|
|
|
|
from django.contrib.admin import AdminSite, ModelAdmin
|
2011-10-13 18:51:33 +00:00
|
|
|
|
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
2015-03-16 21:55:44 +00:00
|
|
|
|
from django.contrib.admin.models import ADDITION, DELETION, LogEntry
|
2014-08-07 04:18:10 +00:00
|
|
|
|
from django.contrib.admin.options import TO_FIELD_VAR
|
2014-03-28 14:42:58 +00:00
|
|
|
|
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
|
2016-02-07 02:24:36 +00:00
|
|
|
|
from django.contrib.admin.tests import AdminSeleniumTestCase
|
2013-09-16 16:52:05 +00:00
|
|
|
|
from django.contrib.admin.utils import quote
|
2011-01-02 01:32:40 +00:00
|
|
|
|
from django.contrib.admin.views.main import IS_POPUP_VAR
|
2015-01-28 12:35:27 +00:00
|
|
|
|
from django.contrib.auth import REDIRECT_FIELD_NAME, get_permission_codename
|
|
|
|
|
from django.contrib.auth.models import Group, Permission, User
|
2011-10-13 18:51:33 +00:00
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2015-01-28 12:35:27 +00:00
|
|
|
|
from django.core import mail
|
|
|
|
|
from django.core.checks import Error
|
|
|
|
|
from django.core.files import temp as tempfile
|
2013-09-16 16:52:05 +00:00
|
|
|
|
from django.forms.utils import ErrorList
|
2011-04-22 18:17:16 +00:00
|
|
|
|
from django.template.response import TemplateResponse
|
2015-01-28 12:35:27 +00:00
|
|
|
|
from django.test import (
|
2017-09-03 01:09:22 +00:00
|
|
|
|
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
|
2015-01-28 12:35:27 +00:00
|
|
|
|
)
|
2018-04-28 13:20:27 +00:00
|
|
|
|
from django.test.utils import override_script_prefix
|
2015-12-30 15:51:16 +00:00
|
|
|
|
from django.urls import NoReverseMatch, resolve, reverse
|
2016-12-29 15:27:49 +00:00
|
|
|
|
from django.utils import formats, translation
|
2009-07-13 13:46:31 +00:00
|
|
|
|
from django.utils.cache import get_max_age
|
2018-02-07 19:20:04 +00:00
|
|
|
|
from django.utils.encoding import iri_to_uri
|
2008-07-18 23:54:34 +00:00
|
|
|
|
from django.utils.html import escape
|
2014-06-26 14:55:36 +00:00
|
|
|
|
from django.utils.http import urlencode
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
2014-12-27 07:16:53 +00:00
|
|
|
|
from . import customadmin
|
2015-01-28 12:35:27 +00:00
|
|
|
|
from .admin import CityAdmin, site, site2
|
|
|
|
|
from .models import (
|
|
|
|
|
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
|
2017-02-24 15:22:25 +00:00
|
|
|
|
AdminOrderedModelMethod, Answer, Answer2, Article, BarAccount, Book,
|
|
|
|
|
Bookmark, Category, Chapter, ChapterXtra1, ChapterXtra2, Character, Child,
|
|
|
|
|
Choice, City, Collector, Color, ComplexSortedPerson, CoverLetter,
|
|
|
|
|
CustomArticle, CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel,
|
2017-06-19 19:10:26 +00:00
|
|
|
|
Fabric, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
|
|
|
|
|
FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link,
|
|
|
|
|
MainPrepopulated, Media, ModelWithStringPrimaryKey, OtherStory, Paper,
|
|
|
|
|
Parent, ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona,
|
|
|
|
|
Picture, Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post,
|
2017-08-22 23:48:55 +00:00
|
|
|
|
PrePopulatedPost, Promo, Question, ReadablePizza, ReadOnlyPizza,
|
|
|
|
|
Recommendation, Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel,
|
|
|
|
|
Report, Restaurant, RowLevelChangePermissionModel, SecretHideout, Section,
|
2017-06-19 19:10:26 +00:00
|
|
|
|
ShortMessage, Simple, State, Story, SuperSecretHideout, SuperVillain,
|
|
|
|
|
Telegram, TitleTranslation, Topping, UnchangeableObject, UndeletableObject,
|
|
|
|
|
UnorderedObject, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour,
|
2015-01-28 12:35:27 +00:00
|
|
|
|
)
|
2011-10-13 18:51:33 +00:00
|
|
|
|
|
2011-09-22 04:16:21 +00:00
|
|
|
|
ERROR_MESSAGE = "Please enter the correct username and password \
|
2012-12-15 23:18:45 +00:00
|
|
|
|
for a staff account. Note that both fields may be case-sensitive."
|
2011-09-22 04:16:21 +00:00
|
|
|
|
|
2017-11-08 00:06:32 +00:00
|
|
|
|
MULTIPART_ENCTYPE = 'enctype="multipart/form-data"'
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2017-01-19 07:39:46 +00:00
|
|
|
|
class AdminFieldExtractionMixin:
|
2016-01-09 20:15:21 +00:00
|
|
|
|
"""
|
|
|
|
|
Helper methods for extracting data from AdminForm.
|
|
|
|
|
"""
|
|
|
|
|
def get_admin_form_fields(self, response):
|
|
|
|
|
"""
|
|
|
|
|
Return a list of AdminFields for the AdminForm in the response.
|
|
|
|
|
"""
|
|
|
|
|
fields = []
|
2018-09-25 15:06:41 +00:00
|
|
|
|
for fieldset in response.context['adminform']:
|
|
|
|
|
for field_line in fieldset:
|
|
|
|
|
fields.extend(field_line)
|
2016-01-09 20:15:21 +00:00
|
|
|
|
return fields
|
|
|
|
|
|
|
|
|
|
def get_admin_readonly_fields(self, response):
|
|
|
|
|
"""
|
|
|
|
|
Return the readonly fields for the response's AdminForm.
|
|
|
|
|
"""
|
|
|
|
|
return [f for f in self.get_admin_form_fields(response) if f.is_readonly]
|
|
|
|
|
|
|
|
|
|
def get_admin_readonly_field(self, response, field_name):
|
|
|
|
|
"""
|
|
|
|
|
Return the readonly field for the given field_name.
|
|
|
|
|
"""
|
|
|
|
|
admin_readonly_fields = self.get_admin_readonly_fields(response)
|
|
|
|
|
for field in admin_readonly_fields:
|
|
|
|
|
if field.field['name'] == field_name:
|
|
|
|
|
return field
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls', USE_I18N=True, USE_L10N=False, LANGUAGE_CODE='en')
|
2013-06-28 00:13:42 +00:00
|
|
|
|
class AdminViewBasicTestCase(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
cls.color1 = Color.objects.create(value='Red', warm=True)
|
|
|
|
|
cls.color2 = Color.objects.create(value='Orange', warm=True)
|
|
|
|
|
cls.color3 = Color.objects.create(value='Blue', warm=False)
|
|
|
|
|
cls.color4 = Color.objects.create(value='Green', warm=False)
|
|
|
|
|
cls.fab1 = Fabric.objects.create(surface='x')
|
|
|
|
|
cls.fab2 = Fabric.objects.create(surface='y')
|
|
|
|
|
cls.fab3 = Fabric.objects.create(surface='plain')
|
|
|
|
|
cls.b1 = Book.objects.create(name='Book 1')
|
|
|
|
|
cls.b2 = Book.objects.create(name='Book 2')
|
|
|
|
|
cls.pro1 = Promo.objects.create(name='Promo 1', book=cls.b1)
|
|
|
|
|
cls.pro1 = Promo.objects.create(name='Promo 2', book=cls.b2)
|
|
|
|
|
cls.chap1 = Chapter.objects.create(title='Chapter 1', content='[ insert contents here ]', book=cls.b1)
|
|
|
|
|
cls.chap2 = Chapter.objects.create(title='Chapter 2', content='[ insert contents here ]', book=cls.b1)
|
|
|
|
|
cls.chap3 = Chapter.objects.create(title='Chapter 1', content='[ insert contents here ]', book=cls.b2)
|
|
|
|
|
cls.chap4 = Chapter.objects.create(title='Chapter 2', content='[ insert contents here ]', book=cls.b2)
|
|
|
|
|
cls.cx1 = ChapterXtra1.objects.create(chap=cls.chap1, xtra='ChapterXtra1 1')
|
|
|
|
|
cls.cx2 = ChapterXtra1.objects.create(chap=cls.chap3, xtra='ChapterXtra1 2')
|
2016-02-09 00:35:03 +00:00
|
|
|
|
Actor.objects.create(name='Palin', age=27)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
# Post data for edit inline
|
|
|
|
|
cls.inline_post_data = {
|
|
|
|
|
"name": "Test section",
|
|
|
|
|
# inline data
|
|
|
|
|
"article_set-TOTAL_FORMS": "6",
|
|
|
|
|
"article_set-INITIAL_FORMS": "3",
|
|
|
|
|
"article_set-MAX_NUM_FORMS": "0",
|
|
|
|
|
"article_set-0-id": cls.a1.pk,
|
|
|
|
|
# there is no title in database, give one here or formset will fail.
|
|
|
|
|
"article_set-0-title": "Norske bostaver æøå skaper problemer",
|
|
|
|
|
"article_set-0-content": "<p>Middle content</p>",
|
|
|
|
|
"article_set-0-date_0": "2008-03-18",
|
|
|
|
|
"article_set-0-date_1": "11:54:58",
|
|
|
|
|
"article_set-0-section": cls.s1.pk,
|
|
|
|
|
"article_set-1-id": cls.a2.pk,
|
|
|
|
|
"article_set-1-title": "Need a title.",
|
|
|
|
|
"article_set-1-content": "<p>Oldest content</p>",
|
|
|
|
|
"article_set-1-date_0": "2000-03-18",
|
|
|
|
|
"article_set-1-date_1": "11:54:58",
|
|
|
|
|
"article_set-2-id": cls.a3.pk,
|
|
|
|
|
"article_set-2-title": "Need a title.",
|
|
|
|
|
"article_set-2-content": "<p>Newest content</p>",
|
|
|
|
|
"article_set-2-date_0": "2009-03-18",
|
|
|
|
|
"article_set-2-date_1": "11:54:58",
|
|
|
|
|
"article_set-3-id": "",
|
|
|
|
|
"article_set-3-title": "",
|
|
|
|
|
"article_set-3-content": "",
|
|
|
|
|
"article_set-3-date_0": "",
|
|
|
|
|
"article_set-3-date_1": "",
|
|
|
|
|
"article_set-4-id": "",
|
|
|
|
|
"article_set-4-title": "",
|
|
|
|
|
"article_set-4-content": "",
|
|
|
|
|
"article_set-4-date_0": "",
|
|
|
|
|
"article_set-4-date_1": "",
|
|
|
|
|
"article_set-5-id": "",
|
|
|
|
|
"article_set-5-title": "",
|
|
|
|
|
"article_set-5-content": "",
|
|
|
|
|
"article_set-5-date_0": "",
|
|
|
|
|
"article_set-5-date_1": "",
|
|
|
|
|
}
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2008-08-09 20:52:40 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2012-08-14 12:36:11 +00:00
|
|
|
|
def assertContentBefore(self, response, text1, text2, failing_msg=None):
|
|
|
|
|
"""
|
|
|
|
|
Testing utility asserting that text1 appears before text2 in response
|
|
|
|
|
content.
|
|
|
|
|
"""
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-12-28 16:25:46 +00:00
|
|
|
|
self.assertLess(
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.index(text1.encode()),
|
|
|
|
|
response.content.index(text2.encode()),
|
2015-12-28 17:26:39 +00:00
|
|
|
|
(failing_msg or '') + '\nResponse:\n' + response.content.decode(response.charset)
|
2015-12-28 16:25:46 +00:00
|
|
|
|
)
|
2013-11-03 04:36:09 +00:00
|
|
|
|
|
2012-08-14 12:36:11 +00:00
|
|
|
|
|
2013-06-28 00:13:42 +00:00
|
|
|
|
class AdminViewBasicTest(AdminViewBasicTestCase):
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_trailing_slash_required(self):
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
|
|
|
|
If you leave off the trailing slash, app should redirect and add it.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
add_url = reverse('admin:admin_views_article_add')
|
|
|
|
|
response = self.client.get(add_url[:-1])
|
|
|
|
|
self.assertRedirects(response, add_url, status_code=301)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_add_GET(self):
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
|
|
|
|
A smoke test to ensure GET on the add_view works.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'))
|
2011-04-22 18:17:16 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_add_with_GET_args(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'), {'name': 'My Section'})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response, 'value="My Section"',
|
|
|
|
|
msg_prefix="Couldn't find an input with the right value in the response"
|
|
|
|
|
)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_edit_GET(self):
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
2009-12-28 14:08:11 +00:00
|
|
|
|
A smoke test to ensure GET on the change_view works.
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_change', args=(self.s1.pk,)))
|
2011-04-22 18:17:16 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_edit_GET_string_PK(self):
|
2009-12-28 14:08:11 +00:00
|
|
|
|
"""
|
2016-11-05 13:56:03 +00:00
|
|
|
|
GET on the change_view (when passing a string as the PK argument for a
|
|
|
|
|
model with an integer PK field) redirects to the index page with a
|
|
|
|
|
message saying the object doesn't exist.
|
2009-12-28 14:08:11 +00:00
|
|
|
|
"""
|
2017-01-04 15:12:06 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_change', args=(quote("abc/<b>"),)), follow=True)
|
2016-11-05 13:56:03 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:index'))
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[m.message for m in response.context['messages']],
|
2017-01-04 15:12:06 +00:00
|
|
|
|
["""section with ID "abc/<b>" doesn't exist. Perhaps it was deleted?"""]
|
2016-11-05 13:56:03 +00:00
|
|
|
|
)
|
2009-12-28 14:08:11 +00:00
|
|
|
|
|
2015-02-07 16:55:47 +00:00
|
|
|
|
def test_basic_edit_GET_old_url_redirect(self):
|
|
|
|
|
"""
|
|
|
|
|
The change URL changed in Django 1.9, but the old one still redirects.
|
|
|
|
|
"""
|
|
|
|
|
response = self.client.get(
|
2015-02-23 00:53:57 +00:00
|
|
|
|
reverse('admin:admin_views_section_change', args=(self.s1.pk,)).replace('change/', '')
|
2015-02-07 16:55:47 +00:00
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:admin_views_section_change', args=(self.s1.pk,)))
|
2015-02-07 16:55:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_inheritance_GET_string_PK(self):
|
2013-03-01 05:01:25 +00:00
|
|
|
|
"""
|
2016-11-05 13:56:03 +00:00
|
|
|
|
GET on the change_view (for inherited models) redirects to the index
|
|
|
|
|
page with a message saying the object doesn't exist.
|
2013-03-01 05:01:25 +00:00
|
|
|
|
"""
|
2016-11-05 13:56:03 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_supervillain_change', args=('abc',)), follow=True)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:index'))
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[m.message for m in response.context['messages']],
|
2017-01-04 15:12:06 +00:00
|
|
|
|
["""super villain with ID "abc" doesn't exist. Perhaps it was deleted?"""]
|
2016-11-05 13:56:03 +00:00
|
|
|
|
)
|
2013-03-01 05:01:25 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_add_POST(self):
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
|
|
|
|
A smoke test to ensure POST on add_view works.
|
|
|
|
|
"""
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Another Section",
|
2008-08-09 20:52:40 +00:00
|
|
|
|
# inline data
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"article_set-TOTAL_FORMS": "3",
|
|
|
|
|
"article_set-INITIAL_FORMS": "0",
|
|
|
|
|
"article_set-MAX_NUM_FORMS": "0",
|
2008-08-09 20:52:40 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_section_add'), post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_popup_add_POST(self):
|
2011-01-02 17:34:52 +00:00
|
|
|
|
"""
|
|
|
|
|
Ensure http response from a popup is properly escaped.
|
|
|
|
|
"""
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
'_popup': '1',
|
|
|
|
|
'title': 'title with a new\nline',
|
|
|
|
|
'content': 'some content',
|
|
|
|
|
'date_0': '2010-09-10',
|
|
|
|
|
'date_1': '14:55:39',
|
2011-01-02 17:34:52 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_article_add'), post_data)
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, 'title with a new\\nline')
|
2011-01-02 17:34:52 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_basic_edit_POST(self):
|
2008-08-09 20:52:40 +00:00
|
|
|
|
"""
|
|
|
|
|
A smoke test to ensure POST on edit_view works.
|
|
|
|
|
"""
|
2015-09-11 23:33:12 +00:00
|
|
|
|
url = reverse('admin:admin_views_section_change', args=(self.s1.pk,))
|
|
|
|
|
response = self.client.post(url, self.inline_post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2009-04-02 00:01:15 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_edit_save_as(self):
|
2009-04-02 00:01:15 +00:00
|
|
|
|
"""
|
|
|
|
|
Test "save as".
|
|
|
|
|
"""
|
|
|
|
|
post_data = self.inline_post_data.copy()
|
|
|
|
|
post_data.update({
|
2012-06-07 16:08:47 +00:00
|
|
|
|
'_saveasnew': 'Save+as+new',
|
|
|
|
|
"article_set-1-section": "1",
|
|
|
|
|
"article_set-2-section": "1",
|
|
|
|
|
"article_set-3-section": "1",
|
|
|
|
|
"article_set-4-section": "1",
|
|
|
|
|
"article_set-5-section": "1",
|
2009-04-02 00:01:15 +00:00
|
|
|
|
})
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_section_change', args=(self.s1.pk,)), post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2008-08-09 20:52:40 +00:00
|
|
|
|
|
2014-12-04 13:22:45 +00:00
|
|
|
|
def test_edit_save_as_delete_inline(self):
|
|
|
|
|
"""
|
|
|
|
|
Should be able to "Save as new" while also deleting an inline.
|
|
|
|
|
"""
|
|
|
|
|
post_data = self.inline_post_data.copy()
|
|
|
|
|
post_data.update({
|
|
|
|
|
'_saveasnew': 'Save+as+new',
|
|
|
|
|
"article_set-1-section": "1",
|
|
|
|
|
"article_set-2-section": "1",
|
|
|
|
|
"article_set-2-DELETE": "1",
|
|
|
|
|
"article_set-3-section": "1",
|
|
|
|
|
})
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_section_change', args=(self.s1.pk,)), post_data)
|
2014-12-04 13:22:45 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
# started with 3 articles, one was deleted.
|
|
|
|
|
self.assertEqual(Section.objects.latest('id').article_set.count(), 2)
|
|
|
|
|
|
2015-12-28 20:31:45 +00:00
|
|
|
|
def test_change_list_column_field_classes(self):
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'))
|
|
|
|
|
# callables display the callable name.
|
|
|
|
|
self.assertContains(response, 'column-callable_year')
|
|
|
|
|
self.assertContains(response, 'field-callable_year')
|
|
|
|
|
# lambdas display as "lambda" + index that they appear in list_display.
|
|
|
|
|
self.assertContains(response, 'column-lambda8')
|
|
|
|
|
self.assertContains(response, 'field-lambda8')
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_callable(self):
|
2008-10-08 14:47:01 +00:00
|
|
|
|
"""
|
2009-03-10 11:19:26 +00:00
|
|
|
|
Ensure we can sort on a list_display field that is a callable
|
2008-10-08 14:47:01 +00:00
|
|
|
|
(column 2 is callable_year in ArticleAdmin)
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': 2})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Oldest content', 'Middle content',
|
|
|
|
|
"Results of sorting on callable are out of order."
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Middle content', 'Newest content',
|
|
|
|
|
"Results of sorting on callable are out of order."
|
|
|
|
|
)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2018-02-16 02:00:31 +00:00
|
|
|
|
def test_change_list_sorting_callable_query_expression(self):
|
|
|
|
|
"""
|
|
|
|
|
Query expressions may be used for admin_order_field. (column 9 is
|
|
|
|
|
order_by_expression in ArticleAdmin).
|
|
|
|
|
"""
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '9'})
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Oldest content', 'Middle content',
|
|
|
|
|
'Results of sorting on callable are out of order.'
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Middle content', 'Newest content',
|
|
|
|
|
'Results of sorting on callable are out of order.'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_change_list_sorting_callable_query_expression_reverse(self):
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '-9'})
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Middle content', 'Oldest content',
|
|
|
|
|
'Results of sorting on callable are out of order.'
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Newest content', 'Middle content',
|
|
|
|
|
'Results of sorting on callable are out of order.'
|
|
|
|
|
)
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_model(self):
|
2008-10-08 14:47:01 +00:00
|
|
|
|
"""
|
2009-03-10 11:19:26 +00:00
|
|
|
|
Ensure we can sort on a list_display field that is a Model method
|
2014-03-02 14:25:53 +00:00
|
|
|
|
(column 3 is 'model_year' in ArticleAdmin)
|
2008-10-08 14:47:01 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '-3'})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Newest content', 'Middle content',
|
|
|
|
|
"Results of sorting on Model method are out of order."
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Middle content', 'Oldest content',
|
|
|
|
|
"Results of sorting on Model method are out of order."
|
|
|
|
|
)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_model_admin(self):
|
2008-10-08 14:47:01 +00:00
|
|
|
|
"""
|
2009-03-10 11:19:26 +00:00
|
|
|
|
Ensure we can sort on a list_display field that is a ModelAdmin method
|
2014-01-23 02:13:59 +00:00
|
|
|
|
(column 4 is 'modeladmin_year' in ArticleAdmin)
|
2008-10-08 14:47:01 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '4'})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Oldest content', 'Middle content',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, 'Middle content', 'Newest content',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_model_admin_reverse(self):
|
2014-01-23 02:13:59 +00:00
|
|
|
|
"""
|
|
|
|
|
Ensure we can sort on a list_display field that is a ModelAdmin
|
|
|
|
|
method in reverse order (i.e. admin_order_field uses the '-' prefix)
|
|
|
|
|
(column 6 is 'model_year_reverse' in ArticleAdmin)
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '6'})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, '2009', '2008',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, '2008', '2000',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
2014-01-23 02:13:59 +00:00
|
|
|
|
# Let's make sure the ordering is right and that we don't get a
|
|
|
|
|
# FieldError when we change to descending order
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'), {'o': '-6'})
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, '2000', '2008',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
|
|
|
|
self.assertContentBefore(
|
|
|
|
|
response, '2008', '2009',
|
|
|
|
|
"Results of sorting on ModelAdmin method are out of order."
|
|
|
|
|
)
|
2014-01-23 02:13:59 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_multiple(self):
|
2011-06-02 16:18:47 +00:00
|
|
|
|
p1 = Person.objects.create(name="Chris", gender=1, alive=True)
|
|
|
|
|
p2 = Person.objects.create(name="Chris", gender=2, alive=True)
|
|
|
|
|
p3 = Person.objects.create(name="Bob", gender=1, alive=True)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_person_change', args=(p1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_person_change', args=(p2.pk,))
|
|
|
|
|
link3 = reverse('admin:admin_views_person_change', args=(p3.pk,))
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
|
|
|
|
# Sort by name, gender
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist'), {'o': '1.2'})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link3, link1)
|
|
|
|
|
self.assertContentBefore(response, link1, link2)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
|
|
|
|
# Sort by gender descending, name
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist'), {'o': '-2.1'})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link2, link3)
|
|
|
|
|
self.assertContentBefore(response, link3, link1)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_preserve_queryset_ordering(self):
|
2012-03-03 02:13:35 +00:00
|
|
|
|
"""
|
|
|
|
|
If no ordering is defined in `ModelAdmin.ordering` or in the query
|
|
|
|
|
string, then the underlying order of the queryset should not be
|
2013-03-08 14:15:23 +00:00
|
|
|
|
changed, even if it is defined in `Modeladmin.get_queryset()`.
|
2012-03-03 02:13:35 +00:00
|
|
|
|
Refs #11868, #7309.
|
|
|
|
|
"""
|
2011-06-02 16:18:47 +00:00
|
|
|
|
p1 = Person.objects.create(name="Amy", gender=1, alive=True, age=80)
|
|
|
|
|
p2 = Person.objects.create(name="Bob", gender=1, alive=True, age=70)
|
|
|
|
|
p3 = Person.objects.create(name="Chris", gender=2, alive=False, age=60)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_person_change', args=(p1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_person_change', args=(p2.pk,))
|
|
|
|
|
link3 = reverse('admin:admin_views_person_change', args=(p3.pk,))
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist'), {})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link3, link2)
|
|
|
|
|
self.assertContentBefore(response, link2, link1)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_model_meta(self):
|
2011-06-02 16:18:47 +00:00
|
|
|
|
# Test ordering on Model Meta is respected
|
|
|
|
|
|
|
|
|
|
l1 = Language.objects.create(iso='ur', name='Urdu')
|
|
|
|
|
l2 = Language.objects.create(iso='ar', name='Arabic')
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_language_change', args=(quote(l1.pk),))
|
|
|
|
|
link2 = reverse('admin:admin_views_language_change', args=(quote(l2.pk),))
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_language_changelist'), {})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link2, link1)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
|
|
|
|
# Test we can override with query string
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_language_changelist'), {'o': '-1'})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link1, link2)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_sorting_override_model_admin(self):
|
2011-06-02 16:18:47 +00:00
|
|
|
|
# Test ordering on Model Admin is respected, and overrides Model Meta
|
|
|
|
|
dt = datetime.datetime.now()
|
|
|
|
|
p1 = Podcast.objects.create(name="A", release_date=dt)
|
|
|
|
|
p2 = Podcast.objects.create(name="B", release_date=dt - datetime.timedelta(10))
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_podcast_change', args=(p1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_podcast_change', args=(p2.pk,))
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_podcast_changelist'), {})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link1, link2)
|
2011-06-02 16:18:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_multiple_sort_same_field(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The changelist displays the correct columns if two columns correspond
|
|
|
|
|
# to the same ordering field.
|
2011-06-03 11:54:29 +00:00
|
|
|
|
dt = datetime.datetime.now()
|
|
|
|
|
p1 = Podcast.objects.create(name="A", release_date=dt)
|
|
|
|
|
p2 = Podcast.objects.create(name="B", release_date=dt - datetime.timedelta(10))
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_podcast_change', args=(quote(p1.pk),))
|
|
|
|
|
link2 = reverse('admin:admin_views_podcast_change', args=(quote(p2.pk),))
|
2011-06-03 11:54:29 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_podcast_changelist'), {})
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link1, link2)
|
2011-06-03 11:54:29 +00:00
|
|
|
|
|
|
|
|
|
p1 = ComplexSortedPerson.objects.create(name="Bob", age=10)
|
|
|
|
|
p2 = ComplexSortedPerson.objects.create(name="Amy", age=20)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_complexsortedperson_change', args=(p1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_complexsortedperson_change', args=(p2.pk,))
|
2011-06-03 11:54:29 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_complexsortedperson_changelist'), {})
|
2011-06-03 11:54:29 +00:00
|
|
|
|
# Should have 5 columns (including action checkbox col)
|
|
|
|
|
self.assertContains(response, '<th scope="col"', count=5)
|
|
|
|
|
|
|
|
|
|
self.assertContains(response, 'Name')
|
|
|
|
|
self.assertContains(response, 'Colored name')
|
|
|
|
|
|
|
|
|
|
# Check order
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertContentBefore(response, 'Name', 'Colored name')
|
2011-06-03 11:54:29 +00:00
|
|
|
|
|
|
|
|
|
# Check sorting - should be by name
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContentBefore(response, link2, link1)
|
2011-06-03 11:54:29 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_sort_indicators_admin_order(self):
|
2011-11-22 09:14:09 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin shows default sort indicators for all kinds of 'ordering'
|
|
|
|
|
fields: field names, method on the model admin and model itself, and
|
|
|
|
|
other callables. See #17252.
|
2011-11-22 09:14:09 +00:00
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
models = [(AdminOrderedField, 'adminorderedfield'),
|
2011-11-22 09:14:09 +00:00
|
|
|
|
(AdminOrderedModelMethod, 'adminorderedmodelmethod'),
|
|
|
|
|
(AdminOrderedAdminMethod, 'adminorderedadminmethod'),
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
(AdminOrderedCallable, 'adminorderedcallable')]
|
2011-11-22 09:14:09 +00:00
|
|
|
|
for model, url in models:
|
2013-09-08 15:05:16 +00:00
|
|
|
|
model.objects.create(stuff='The Last Item', order=3)
|
|
|
|
|
model.objects.create(stuff='The First Item', order=1)
|
|
|
|
|
model.objects.create(stuff='The Middle Item', order=2)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_%s_changelist' % url), {})
|
2011-11-22 09:14:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
# Should have 3 columns including action checkbox col.
|
|
|
|
|
self.assertContains(response, '<th scope="col"', count=3, msg_prefix=url)
|
|
|
|
|
# Check if the correct column was selected. 2 is the index of the
|
|
|
|
|
# 'order' column in the model admin's 'list_display' with 0 being
|
|
|
|
|
# the implicit 'action_checkbox' and 1 being the column 'stuff'.
|
|
|
|
|
self.assertEqual(response.context['cl'].get_ordering_field_columns(), {2: 'asc'})
|
|
|
|
|
# Check order of records.
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertContentBefore(response, 'The First Item', 'The Middle Item')
|
|
|
|
|
self.assertContentBefore(response, 'The Middle Item', 'The Last Item')
|
2011-11-22 09:14:09 +00:00
|
|
|
|
|
2016-09-13 02:13:00 +00:00
|
|
|
|
def test_has_related_field_in_list_display_fk(self):
|
2016-04-23 17:35:18 +00:00
|
|
|
|
"""Joins shouldn't be performed for <FK>_id fields in list display."""
|
|
|
|
|
state = State.objects.create(name='Karnataka')
|
|
|
|
|
City.objects.create(state=state, name='Bangalore')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_city_changelist'), {})
|
|
|
|
|
|
|
|
|
|
response.context['cl'].list_display = ['id', 'name', 'state']
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(response.context['cl'].has_related_field_in_list_display(), True)
|
2016-04-23 17:35:18 +00:00
|
|
|
|
|
|
|
|
|
response.context['cl'].list_display = ['id', 'name', 'state_id']
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(response.context['cl'].has_related_field_in_list_display(), False)
|
2016-04-23 17:35:18 +00:00
|
|
|
|
|
2016-09-13 02:13:00 +00:00
|
|
|
|
def test_has_related_field_in_list_display_o2o(self):
|
|
|
|
|
"""Joins shouldn't be performed for <O2O>_id fields in list display."""
|
|
|
|
|
media = Media.objects.create(name='Foo')
|
|
|
|
|
Vodcast.objects.create(media=media)
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_vodcast_changelist'), {})
|
|
|
|
|
|
|
|
|
|
response.context['cl'].list_display = ['media']
|
|
|
|
|
self.assertIs(response.context['cl'].has_related_field_in_list_display(), True)
|
|
|
|
|
|
|
|
|
|
response.context['cl'].list_display = ['media_id']
|
|
|
|
|
self.assertIs(response.context['cl'].has_related_field_in_list_display(), False)
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_limited_filter(self):
|
2010-11-21 19:29:15 +00:00
|
|
|
|
"""Ensure admin changelist filters do not contain objects excluded via limit_choices_to.
|
|
|
|
|
This also tests relation-spanning filters (e.g. 'color__value').
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_thing_changelist'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response, '<div id="changelist-filter">',
|
|
|
|
|
msg_prefix="Expected filter not found in changelist view"
|
|
|
|
|
)
|
|
|
|
|
self.assertNotContains(
|
|
|
|
|
response, '<a href="?color__id__exact=3">Blue</a>',
|
|
|
|
|
msg_prefix="Changelist filter not correctly limited by limit_choices_to"
|
|
|
|
|
)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_relation_spanning_filters(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
changelist_url = reverse('admin:admin_views_chapterxtra1_changelist')
|
|
|
|
|
response = self.client.get(changelist_url)
|
2010-11-21 19:29:15 +00:00
|
|
|
|
self.assertContains(response, '<div id="changelist-filter">')
|
|
|
|
|
filters = {
|
2017-01-24 00:13:49 +00:00
|
|
|
|
'chap__id__exact': {
|
|
|
|
|
'values': [c.id for c in Chapter.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.id == value,
|
|
|
|
|
},
|
|
|
|
|
'chap__title': {
|
|
|
|
|
'values': [c.title for c in Chapter.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.title == value,
|
|
|
|
|
},
|
|
|
|
|
'chap__book__id__exact': {
|
|
|
|
|
'values': [b.id for b in Book.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.book.id == value,
|
|
|
|
|
},
|
|
|
|
|
'chap__book__name': {
|
|
|
|
|
'values': [b.name for b in Book.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.book.name == value,
|
|
|
|
|
},
|
|
|
|
|
'chap__book__promo__id__exact': {
|
|
|
|
|
'values': [p.id for p in Promo.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.book.promo_set.filter(id=value).exists(),
|
|
|
|
|
},
|
|
|
|
|
'chap__book__promo__name': {
|
|
|
|
|
'values': [p.name for p in Promo.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.chap.book.promo_set.filter(name=value).exists(),
|
|
|
|
|
},
|
2017-06-04 18:10:48 +00:00
|
|
|
|
# A forward relation (book) after a reverse relation (promo).
|
|
|
|
|
'guest_author__promo__book__id__exact': {
|
|
|
|
|
'values': [p.id for p in Book.objects.all()],
|
|
|
|
|
'test': lambda obj, value: obj.guest_author.promo_set.filter(book=value).exists(),
|
|
|
|
|
},
|
2013-10-18 09:02:43 +00:00
|
|
|
|
}
|
2010-11-21 19:29:15 +00:00
|
|
|
|
for filter_path, params in filters.items():
|
|
|
|
|
for value in params['values']:
|
|
|
|
|
query_string = urlencode({filter_path: value})
|
|
|
|
|
# ensure filter link exists
|
2016-07-08 01:58:11 +00:00
|
|
|
|
self.assertContains(response, '<a href="?%s"' % query_string)
|
2010-11-21 19:29:15 +00:00
|
|
|
|
# ensure link works
|
2015-02-06 22:25:15 +00:00
|
|
|
|
filtered_response = self.client.get('%s?%s' % (changelist_url, query_string))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(filtered_response.status_code, 200)
|
2010-11-21 19:29:15 +00:00
|
|
|
|
# ensure changelist contains only valid objects
|
2013-03-08 14:15:23 +00:00
|
|
|
|
for obj in filtered_response.context['cl'].queryset.all():
|
2010-11-21 19:29:15 +00:00
|
|
|
|
self.assertTrue(params['test'](obj, value))
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_incorrect_lookup_parameters(self):
|
2008-10-22 23:09:35 +00:00
|
|
|
|
"""Ensure incorrect lookup parameters are handled gracefully."""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
changelist_url = reverse('admin:admin_views_thing_changelist')
|
|
|
|
|
response = self.client.get(changelist_url, {'notarealfield': '5'})
|
|
|
|
|
self.assertRedirects(response, '%s?e=1' % changelist_url)
|
2011-08-28 07:57:56 +00:00
|
|
|
|
|
2014-11-03 22:48:03 +00:00
|
|
|
|
# Spanning relationships through a nonexistent related object (Refs #16716)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'notarealfield__whatever': '5'})
|
|
|
|
|
self.assertRedirects(response, '%s?e=1' % changelist_url)
|
2011-08-28 07:57:56 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'color__id__exact': 'StringNotInteger!'})
|
|
|
|
|
self.assertRedirects(response, '%s?e=1' % changelist_url)
|
2009-01-14 20:22:25 +00:00
|
|
|
|
|
2012-09-15 23:20:56 +00:00
|
|
|
|
# Regression test for #18530
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'pub_date__gte': 'foo'})
|
|
|
|
|
self.assertRedirects(response, '%s?e=1' % changelist_url)
|
2012-09-15 23:20:56 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_isnull_lookups(self):
|
2010-03-16 19:01:40 +00:00
|
|
|
|
"""Ensure is_null is handled correctly."""
|
|
|
|
|
Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
|
2015-02-06 22:25:15 +00:00
|
|
|
|
changelist_url = reverse('admin:admin_views_article_changelist')
|
|
|
|
|
response = self.client.get(changelist_url)
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertContains(response, '4 articles')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'section__isnull': 'false'})
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertContains(response, '3 articles')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'section__isnull': '0'})
|
2013-05-27 16:31:49 +00:00
|
|
|
|
self.assertContains(response, '3 articles')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'section__isnull': 'true'})
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertContains(response, '1 article')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(changelist_url, {'section__isnull': '1'})
|
2013-05-27 16:31:49 +00:00
|
|
|
|
self.assertContains(response, '1 article')
|
2010-03-16 19:01:40 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_logout_and_password_change_URLs(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'))
|
|
|
|
|
self.assertContains(response, '<a href="%s">' % reverse('admin:logout'))
|
|
|
|
|
self.assertContains(response, '<a href="%s">' % reverse('admin:password_change'))
|
2009-07-16 16:16:13 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_named_group_field_choices_change_list(self):
|
2009-04-01 14:14:20 +00:00
|
|
|
|
"""
|
|
|
|
|
Ensures the admin changelist shows correct values in the relevant column
|
|
|
|
|
for rows corresponding to instances of a model in which a named group
|
|
|
|
|
has been used in the choices option of a field.
|
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_fabric_change', args=(self.fab1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_fabric_change', args=(self.fab2.pk,))
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_fabric_changelist'))
|
2015-09-11 23:33:12 +00:00
|
|
|
|
fail_msg = (
|
|
|
|
|
"Changelist table isn't showing the right human-readable values "
|
|
|
|
|
"set by a model field 'choices' option named group."
|
|
|
|
|
)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
self.assertContains(response, '<a href="%s">Horizontal</a>' % link1, msg_prefix=fail_msg, html=True)
|
|
|
|
|
self.assertContains(response, '<a href="%s">Vertical</a>' % link2, msg_prefix=fail_msg, html=True)
|
2009-04-01 14:14:20 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_named_group_field_choices_filter(self):
|
2009-04-01 14:14:20 +00:00
|
|
|
|
"""
|
|
|
|
|
Ensures the filter UI shows correctly when at least one named group has
|
|
|
|
|
been used in the choices option of a model field.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_fabric_changelist'))
|
2015-09-11 23:33:12 +00:00
|
|
|
|
fail_msg = (
|
|
|
|
|
"Changelist filter isn't showing options contained inside a model "
|
|
|
|
|
"field 'choices' option named group."
|
|
|
|
|
)
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertContains(response, '<div id="changelist-filter">')
|
2016-07-08 01:58:11 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response, '<a href="?surface__exact=x" title="Horizontal">Horizontal</a>',
|
|
|
|
|
msg_prefix=fail_msg, html=True
|
|
|
|
|
)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response, '<a href="?surface__exact=y" title="Vertical">Vertical</a>',
|
|
|
|
|
msg_prefix=fail_msg, html=True
|
|
|
|
|
)
|
2009-04-01 14:14:20 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_list_null_boolean_display(self):
|
2010-03-10 08:37:17 +00:00
|
|
|
|
Post.objects.create(public=None)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_post_changelist'))
|
2015-08-15 20:38:57 +00:00
|
|
|
|
self.assertContains(response, 'icon-unknown.svg')
|
2010-03-10 08:37:17 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_i18n_language_non_english_default(self):
|
2010-05-02 19:46:31 +00:00
|
|
|
|
"""
|
2012-03-02 17:16:52 +00:00
|
|
|
|
Check if the JavaScript i18n view returns an empty language catalog
|
2010-05-02 19:46:31 +00:00
|
|
|
|
if the default language is non-English but the selected language
|
|
|
|
|
is English. See #13388 and #3594 for more details.
|
|
|
|
|
"""
|
2013-08-16 18:12:10 +00:00
|
|
|
|
with self.settings(LANGUAGE_CODE='fr'), translation.override('en-us'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:jsi18n'))
|
2013-08-16 18:12:10 +00:00
|
|
|
|
self.assertNotContains(response, 'Choisir une heure')
|
2010-05-02 19:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_i18n_language_non_english_fallback(self):
|
2010-05-02 19:46:31 +00:00
|
|
|
|
"""
|
|
|
|
|
Makes sure that the fallback language is still working properly
|
|
|
|
|
in cases where the selected language cannot be found.
|
|
|
|
|
"""
|
2013-08-16 18:12:10 +00:00
|
|
|
|
with self.settings(LANGUAGE_CODE='fr'), translation.override('none'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:jsi18n'))
|
2013-08-16 18:12:10 +00:00
|
|
|
|
self.assertContains(response, 'Choisir une heure')
|
2011-02-04 13:52:36 +00:00
|
|
|
|
|
2016-06-19 10:51:58 +00:00
|
|
|
|
def test_jsi18n_with_context(self):
|
|
|
|
|
response = self.client.get(reverse('admin-extra-context:jsi18n'))
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_L10N_deactivated(self):
|
2011-02-04 13:52:36 +00:00
|
|
|
|
"""
|
2012-03-02 17:16:52 +00:00
|
|
|
|
Check if L10N is deactivated, the JavaScript i18n view doesn't
|
2011-02-04 13:52:36 +00:00
|
|
|
|
return localized date/time formats. Refs #14824.
|
|
|
|
|
"""
|
2013-08-16 18:12:10 +00:00
|
|
|
|
with self.settings(LANGUAGE_CODE='ru', USE_L10N=False), translation.override('none'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:jsi18n'))
|
2013-08-16 18:12:10 +00:00
|
|
|
|
self.assertNotContains(response, '%d.%m.%Y %H:%M:%S')
|
|
|
|
|
self.assertContains(response, '%Y-%m-%d %H:%M:%S')
|
2010-05-02 19:46:31 +00:00
|
|
|
|
|
2010-12-23 03:44:38 +00:00
|
|
|
|
def test_disallowed_filtering(self):
|
2018-04-28 13:20:27 +00:00
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminLookup', 'ERROR'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
"%s?owner__email__startswith=fuzzy" % reverse('admin:admin_views_album_changelist')
|
|
|
|
|
)
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2010-12-23 03:44:38 +00:00
|
|
|
|
|
2013-05-15 23:14:28 +00:00
|
|
|
|
# Filters are allowed if explicitly included in list_filter
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get("%s?color__value__startswith=red" % reverse('admin:admin_views_thing_changelist'))
|
2013-05-15 23:14:28 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get("%s?color__value=red" % reverse('admin:admin_views_thing_changelist'))
|
2013-05-15 23:14:28 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2010-05-02 19:46:31 +00:00
|
|
|
|
|
2013-05-15 23:14:28 +00:00
|
|
|
|
# Filters should be allowed if they involve a local field without the
|
|
|
|
|
# need to whitelist them in list_filter or date_hierarchy.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get("%s?age__gt=30" % reverse('admin:admin_views_person_changelist'))
|
2013-05-15 23:14:28 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2011-01-03 13:56:31 +00:00
|
|
|
|
|
2011-01-12 23:30:47 +00:00
|
|
|
|
e1 = Employee.objects.create(name='Anonymous', gender=1, age=22, alive=True, code='123')
|
|
|
|
|
e2 = Employee.objects.create(name='Visitor', gender=2, age=19, alive=True, code='124')
|
|
|
|
|
WorkHour.objects.create(datum=datetime.datetime.now(), employee=e1)
|
|
|
|
|
WorkHour.objects.create(datum=datetime.datetime.now(), employee=e2)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_workhour_changelist'))
|
2011-01-12 23:30:47 +00:00
|
|
|
|
self.assertContains(response, 'employee__person_ptr__exact')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get("%s?employee__person_ptr__exact=%d" % (
|
|
|
|
|
reverse('admin:admin_views_workhour_changelist'), e1.pk)
|
|
|
|
|
)
|
2011-01-12 23:30:47 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-08-07 04:18:10 +00:00
|
|
|
|
def test_disallowed_to_field(self):
|
2018-04-28 13:20:27 +00:00
|
|
|
|
url = reverse('admin:admin_views_section_changelist')
|
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-09-11 23:33:12 +00:00
|
|
|
|
response = self.client.get(url, {TO_FIELD_VAR: 'missing_field'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2014-08-07 04:18:10 +00:00
|
|
|
|
|
2014-11-03 22:48:03 +00:00
|
|
|
|
# Specifying a field that is not referred by any other model registered
|
2014-08-07 04:18:10 +00:00
|
|
|
|
# to this admin site should raise an exception.
|
2018-04-28 13:20:27 +00:00
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_changelist'), {TO_FIELD_VAR: 'name'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2014-08-07 04:18:10 +00:00
|
|
|
|
|
2014-11-16 15:42:09 +00:00
|
|
|
|
# #23839 - Primary key should always be allowed, even if the referenced model isn't registered.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_notreferenced_changelist'), {TO_FIELD_VAR: 'id'})
|
2014-08-07 04:18:10 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-11-25 19:27:46 +00:00
|
|
|
|
# #23915 - Specifying a field referenced by another model though a m2m should be allowed.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_recipe_changelist'), {TO_FIELD_VAR: 'rname'})
|
2014-08-21 15:55:23 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-11-25 19:27:46 +00:00
|
|
|
|
# #23604, #23915 - Specifying a field referenced through a reverse m2m relationship should be allowed.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_ingredient_changelist'), {TO_FIELD_VAR: 'iname'})
|
2014-10-05 18:06:51 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-11-03 22:48:03 +00:00
|
|
|
|
# #23329 - Specifying a field that is not referred by any other model directly registered
|
2014-08-21 15:55:23 +00:00
|
|
|
|
# to this admin site but registered through inheritance should be allowed.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_referencedbyparent_changelist'), {TO_FIELD_VAR: 'name'})
|
2014-08-21 15:55:23 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-11-03 22:48:03 +00:00
|
|
|
|
# #23431 - Specifying a field that is only referred to by a inline of a registered
|
2014-09-04 21:04:53 +00:00
|
|
|
|
# model should be allowed.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_referencedbyinline_changelist'), {TO_FIELD_VAR: 'name'})
|
2014-09-04 21:04:53 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2015-10-28 15:25:25 +00:00
|
|
|
|
# #25622 - Specifying a field of a model only referred by a generic
|
|
|
|
|
# relation should raise DisallowedModelAdminToField.
|
|
|
|
|
url = reverse('admin:admin_views_referencedbygenrel_changelist')
|
2018-04-28 13:20:27 +00:00
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-10-28 15:25:25 +00:00
|
|
|
|
response = self.client.get(url, {TO_FIELD_VAR: 'object_id'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2015-10-28 15:25:25 +00:00
|
|
|
|
|
2013-11-17 22:26:20 +00:00
|
|
|
|
# We also want to prevent the add, change, and delete views from
|
|
|
|
|
# leaking a disallowed field value.
|
2018-04-28 13:20:27 +00:00
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_section_add'), {TO_FIELD_VAR: 'name'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2014-08-07 04:18:10 +00:00
|
|
|
|
|
|
|
|
|
section = Section.objects.create()
|
2018-04-28 13:20:27 +00:00
|
|
|
|
url = reverse('admin:admin_views_section_change', args=(section.pk,))
|
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-09-11 23:33:12 +00:00
|
|
|
|
response = self.client.post(url, {TO_FIELD_VAR: 'name'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2014-08-07 04:18:10 +00:00
|
|
|
|
|
2018-04-28 13:20:27 +00:00
|
|
|
|
url = reverse('admin:admin_views_section_delete', args=(section.pk,))
|
|
|
|
|
with self.assertLogs('django.security.DisallowedModelAdminToField', 'ERROR'):
|
2015-09-11 23:33:12 +00:00
|
|
|
|
response = self.client.post(url, {TO_FIELD_VAR: 'name'})
|
2018-04-28 13:20:27 +00:00
|
|
|
|
self.assertEqual(response.status_code, 400)
|
2013-11-17 22:26:20 +00:00
|
|
|
|
|
2011-01-28 14:08:25 +00:00
|
|
|
|
def test_allowed_filtering_15103(self):
|
|
|
|
|
"""
|
|
|
|
|
Regressions test for ticket 15103 - filtering on fields defined in a
|
|
|
|
|
ForeignKey 'limit_choices_to' should be allowed, otherwise raw_id_fields
|
|
|
|
|
can break.
|
|
|
|
|
"""
|
2013-05-15 23:14:28 +00:00
|
|
|
|
# Filters should be allowed if they are defined on a ForeignKey pointing to this model
|
2015-09-11 23:33:12 +00:00
|
|
|
|
url = "%s?leader__name=Palin&leader__age=27" % reverse('admin:admin_views_inquisition_changelist')
|
|
|
|
|
response = self.client.get(url)
|
2013-05-15 23:14:28 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2011-01-28 14:08:25 +00:00
|
|
|
|
|
2013-06-27 23:39:20 +00:00
|
|
|
|
def test_popup_dismiss_related(self):
|
|
|
|
|
"""
|
|
|
|
|
Regression test for ticket 20664 - ensure the pk is properly quoted.
|
|
|
|
|
"""
|
|
|
|
|
actor = Actor.objects.create(name="Palin", age=27)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get("%s?%s" % (reverse('admin:admin_views_actor_changelist'), IS_POPUP_VAR))
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, 'data-popup-opener="%s"' % actor.pk)
|
2013-06-27 23:39:20 +00:00
|
|
|
|
|
2012-04-29 11:56:22 +00:00
|
|
|
|
def test_hide_change_password(self):
|
|
|
|
|
"""
|
|
|
|
|
Tests if the "change password" link in the admin is hidden if the User
|
|
|
|
|
does not have a usable password set.
|
|
|
|
|
(against 9bea85795705d015cdadc82c68b99196a8554f5c)
|
|
|
|
|
"""
|
|
|
|
|
user = User.objects.get(username='super')
|
|
|
|
|
user.set_unusable_password()
|
|
|
|
|
user.save()
|
2015-09-03 00:50:34 +00:00
|
|
|
|
self.client.force_login(user)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertNotContains(
|
|
|
|
|
response, reverse('admin:password_change'),
|
|
|
|
|
msg_prefix='The "change password" link should not be displayed if a user does not have a usable password.'
|
|
|
|
|
)
|
2012-04-29 11:56:22 +00:00
|
|
|
|
|
2012-07-22 01:10:24 +00:00
|
|
|
|
def test_change_view_with_show_delete_extra_context(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The 'show_delete' context variable in the admin's change view controls
|
|
|
|
|
the display of the delete button.
|
2012-07-22 01:10:24 +00:00
|
|
|
|
"""
|
|
|
|
|
instance = UndeletableObject.objects.create(name='foo')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_undeletableobject_change', args=(instance.pk,)))
|
2012-07-22 01:10:24 +00:00
|
|
|
|
self.assertNotContains(response, 'deletelink')
|
2012-02-05 10:26:05 +00:00
|
|
|
|
|
2017-04-05 03:54:46 +00:00
|
|
|
|
def test_change_view_logs_m2m_field_changes(self):
|
|
|
|
|
"""Changes to ManyToManyFields are included in the object's history."""
|
|
|
|
|
pizza = ReadablePizza.objects.create(name='Cheese')
|
|
|
|
|
cheese = Topping.objects.create(name='cheese')
|
|
|
|
|
post_data = {'name': pizza.name, 'toppings': [cheese.pk]}
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_readablepizza_change', args=(pizza.pk,)), post_data)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:admin_views_readablepizza_changelist'))
|
|
|
|
|
pizza_ctype = ContentType.objects.get_for_model(ReadablePizza, for_concrete_model=False)
|
|
|
|
|
log = LogEntry.objects.filter(content_type=pizza_ctype, object_id=pizza.pk).first()
|
|
|
|
|
self.assertEqual(log.get_change_message(), 'Changed toppings.')
|
|
|
|
|
|
2012-09-08 15:18:08 +00:00
|
|
|
|
def test_allows_attributeerror_to_bubble_up(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
AttributeErrors are allowed to bubble when raised inside a change list
|
|
|
|
|
view. Requires a model to be created so there's something to display.
|
2012-09-08 15:18:08 +00:00
|
|
|
|
Refs: #16655, #18593, and #18747
|
|
|
|
|
"""
|
|
|
|
|
Simple.objects.create()
|
|
|
|
|
with self.assertRaises(AttributeError):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:admin_views_simple_changelist'))
|
2012-09-08 15:18:08 +00:00
|
|
|
|
|
2013-08-21 16:22:22 +00:00
|
|
|
|
def test_changelist_with_no_change_url(self):
|
|
|
|
|
"""
|
|
|
|
|
ModelAdmin.changelist_view shouldn't result in a NoReverseMatch if url
|
2016-10-27 07:53:39 +00:00
|
|
|
|
for change_view is removed from get_urls (#20934).
|
2013-08-21 16:22:22 +00:00
|
|
|
|
"""
|
2017-06-09 16:36:09 +00:00
|
|
|
|
o = UnchangeableObject.objects.create()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_unchangeableobject_changelist'))
|
2013-08-21 16:22:22 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
# Check the format of the shown object -- shouldn't contain a change link
|
2017-06-09 16:36:09 +00:00
|
|
|
|
self.assertContains(response, '<th class="field-__str__">%s</th>' % o, html=True)
|
2013-08-21 16:22:22 +00:00
|
|
|
|
|
2013-09-07 13:20:04 +00:00
|
|
|
|
def test_invalid_appindex_url(self):
|
|
|
|
|
"""
|
|
|
|
|
#21056 -- URL reversing shouldn't work for nonexistent apps.
|
|
|
|
|
"""
|
|
|
|
|
good_url = '/test_admin/admin/admin_views/'
|
|
|
|
|
confirm_good_url = reverse('admin:app_list',
|
|
|
|
|
kwargs={'app_label': 'admin_views'})
|
|
|
|
|
self.assertEqual(good_url, confirm_good_url)
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(NoReverseMatch):
|
|
|
|
|
reverse('admin:app_list', kwargs={'app_label': 'this_should_fail'})
|
|
|
|
|
with self.assertRaises(NoReverseMatch):
|
|
|
|
|
reverse('admin:app_list', args=('admin_views2',))
|
|
|
|
|
|
2014-12-27 07:16:53 +00:00
|
|
|
|
def test_resolve_admin_views(self):
|
|
|
|
|
index_match = resolve('/test_admin/admin4/')
|
|
|
|
|
list_match = resolve('/test_admin/admin4/auth/user/')
|
|
|
|
|
self.assertIs(index_match.func.admin_site, customadmin.simple_site)
|
|
|
|
|
self.assertIsInstance(list_match.func.model_admin, customadmin.CustomPwdTemplateUserAdmin)
|
|
|
|
|
|
2014-08-26 11:10:30 +00:00
|
|
|
|
def test_adminsite_display_site_url(self):
|
|
|
|
|
"""
|
|
|
|
|
#13749 - Admin should display link to front-end site 'View site'
|
|
|
|
|
"""
|
|
|
|
|
url = reverse('admin:index')
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertEqual(response.context['site_url'], '/my-site-url/')
|
|
|
|
|
self.assertContains(response, '<a href="/my-site-url/">View site</a>')
|
|
|
|
|
|
2017-02-24 15:22:25 +00:00
|
|
|
|
@override_settings(TIME_ZONE='America/Sao_Paulo', USE_TZ=True)
|
|
|
|
|
def test_date_hierarchy_timezone_dst(self):
|
|
|
|
|
# This datetime doesn't exist in this timezone due to DST.
|
|
|
|
|
date = pytz.timezone('America/Sao_Paulo').localize(datetime.datetime(2016, 10, 16, 15), is_dst=None)
|
|
|
|
|
q = Question.objects.create(question='Why?', expires=date)
|
|
|
|
|
Answer2.objects.create(question=q, answer='Because.')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_answer2_changelist'))
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertContains(response, 'question__expires__day=16')
|
|
|
|
|
self.assertContains(response, 'question__expires__month=10')
|
|
|
|
|
self.assertContains(response, 'question__expires__year=2016')
|
|
|
|
|
|
2016-02-09 00:35:03 +00:00
|
|
|
|
def test_sortable_by_columns_subset(self):
|
|
|
|
|
expected_sortable_fields = ('date', 'callable_year')
|
|
|
|
|
expected_not_sortable_fields = (
|
|
|
|
|
'content', 'model_year', 'modeladmin_year', 'model_year_reversed',
|
|
|
|
|
'section',
|
|
|
|
|
)
|
|
|
|
|
response = self.client.get(reverse('admin6:admin_views_article_changelist'))
|
|
|
|
|
for field_name in expected_sortable_fields:
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="sortable column-%s">' % field_name)
|
|
|
|
|
for field_name in expected_not_sortable_fields:
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="column-%s">' % field_name)
|
|
|
|
|
|
|
|
|
|
def test_get_sortable_by_columns_subset(self):
|
|
|
|
|
response = self.client.get(reverse('admin6:admin_views_actor_changelist'))
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="sortable column-age">')
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="column-name">')
|
|
|
|
|
|
|
|
|
|
def test_sortable_by_no_column(self):
|
|
|
|
|
expected_not_sortable_fields = ('title', 'book')
|
|
|
|
|
response = self.client.get(reverse('admin6:admin_views_chapter_changelist'))
|
|
|
|
|
for field_name in expected_not_sortable_fields:
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="column-%s">' % field_name)
|
|
|
|
|
self.assertNotContains(response, '<th scope="col" class="sortable column')
|
|
|
|
|
|
|
|
|
|
def test_get_sortable_by_no_column(self):
|
|
|
|
|
response = self.client.get(reverse('admin6:admin_views_color_changelist'))
|
|
|
|
|
self.assertContains(response, '<th scope="col" class="column-value">')
|
|
|
|
|
self.assertNotContains(response, '<th scope="col" class="sortable column')
|
|
|
|
|
|
2012-09-08 15:18:08 +00:00
|
|
|
|
|
2014-12-17 21:51:42 +00:00
|
|
|
|
@override_settings(TEMPLATES=[{
|
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2015-02-09 01:09:15 +00:00
|
|
|
|
# Put this app's and the shared tests templates dirs in DIRS to take precedence
|
|
|
|
|
# over the admin's templates dir.
|
|
|
|
|
'DIRS': [
|
2017-01-20 13:01:02 +00:00
|
|
|
|
os.path.join(os.path.dirname(__file__), 'templates'),
|
|
|
|
|
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates'),
|
2015-02-09 01:09:15 +00:00
|
|
|
|
],
|
2014-12-17 21:51:42 +00:00
|
|
|
|
'APP_DIRS': True,
|
|
|
|
|
'OPTIONS': {
|
|
|
|
|
'context_processors': [
|
|
|
|
|
'django.template.context_processors.debug',
|
2015-01-12 21:31:44 +00:00
|
|
|
|
'django.template.context_processors.request',
|
2014-12-17 21:51:42 +00:00
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}])
|
2014-01-08 16:48:43 +00:00
|
|
|
|
class AdminCustomTemplateTests(AdminViewBasicTestCase):
|
2015-02-09 01:09:15 +00:00
|
|
|
|
def test_custom_model_admin_templates(self):
|
|
|
|
|
# Test custom change list template with custom extra context
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_customarticle_changelist'))
|
|
|
|
|
self.assertContains(response, "var hello = 'Hello!';")
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/change_list.html')
|
|
|
|
|
|
|
|
|
|
# Test custom add form template
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_customarticle_add'))
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/add_form.html')
|
|
|
|
|
|
|
|
|
|
# Add an article so we can test delete, change, and history views
|
|
|
|
|
post = self.client.post(reverse('admin:admin_views_customarticle_add'), {
|
|
|
|
|
'content': '<p>great article</p>',
|
|
|
|
|
'date_0': '2008-03-18',
|
|
|
|
|
'date_1': '10:54:39'
|
|
|
|
|
})
|
|
|
|
|
self.assertRedirects(post, reverse('admin:admin_views_customarticle_changelist'))
|
|
|
|
|
self.assertEqual(CustomArticle.objects.all().count(), 1)
|
|
|
|
|
article_pk = CustomArticle.objects.all()[0].pk
|
|
|
|
|
|
|
|
|
|
# Test custom delete, change, and object history templates
|
|
|
|
|
# Test custom change form template
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_customarticle_change', args=(article_pk,)))
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/change_form.html')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_customarticle_delete', args=(article_pk,)))
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/delete_confirmation.html')
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_customarticle_changelist'), data={
|
|
|
|
|
'index': 0,
|
|
|
|
|
'action': ['delete_selected'],
|
|
|
|
|
'_selected_action': ['1'],
|
|
|
|
|
})
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/delete_selected_confirmation.html')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_customarticle_history', args=(article_pk,)))
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/object_history.html')
|
|
|
|
|
|
2016-11-12 19:09:15 +00:00
|
|
|
|
# A custom popup response template may be specified by
|
|
|
|
|
# ModelAdmin.popup_response_template.
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_customarticle_add') + '?%s=1' % IS_POPUP_VAR, {
|
|
|
|
|
'content': '<p>great article</p>',
|
|
|
|
|
'date_0': '2008-03-18',
|
|
|
|
|
'date_1': '10:54:39',
|
|
|
|
|
IS_POPUP_VAR: '1'
|
|
|
|
|
})
|
|
|
|
|
self.assertEqual(response.template_name, 'custom_admin/popup_response.html')
|
|
|
|
|
|
2014-01-08 16:48:43 +00:00
|
|
|
|
def test_extended_bodyclass_template_change_form(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/change_form.html template uses block.super in the
|
2014-01-08 16:48:43 +00:00
|
|
|
|
bodyclass block.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
2016-06-08 15:37:26 +00:00
|
|
|
|
def test_change_password_template(self):
|
2014-01-08 16:48:43 +00:00
|
|
|
|
user = User.objects.get(username='super')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_user_password_change', args=(user.id,)))
|
2016-06-08 15:37:26 +00:00
|
|
|
|
# The auth/user/change_password.html template uses super in the
|
|
|
|
|
# bodyclass block.
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
2016-06-08 15:37:26 +00:00
|
|
|
|
# When a site has multiple passwords in the browser's password manager,
|
|
|
|
|
# a browser pop up asks which user the new password is for. To prevent
|
|
|
|
|
# this, the username is added to the change password form.
|
2018-01-21 07:09:10 +00:00
|
|
|
|
self.assertContains(response, '<input type="text" name="username" value="super" style="display: none">')
|
2016-06-08 15:37:26 +00:00
|
|
|
|
|
2014-01-08 16:48:43 +00:00
|
|
|
|
def test_extended_bodyclass_template_index(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/index.html template uses block.super in the bodyclass block.
|
2014-01-08 16:48:43 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
|
|
|
|
def test_extended_bodyclass_change_list(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/change_list.html' template uses block.super
|
2014-01-08 16:48:43 +00:00
|
|
|
|
in the bodyclass block.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_changelist'))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
|
|
|
|
def test_extended_bodyclass_template_login(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/login.html template uses block.super in the
|
2014-01-08 16:48:43 +00:00
|
|
|
|
bodyclass block.
|
|
|
|
|
"""
|
|
|
|
|
self.client.logout()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:login'))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
|
|
|
|
def test_extended_bodyclass_template_delete_confirmation(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/delete_confirmation.html template uses
|
2014-01-08 16:48:43 +00:00
|
|
|
|
block.super in the bodyclass block.
|
|
|
|
|
"""
|
|
|
|
|
group = Group.objects.create(name="foogroup")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_group_delete', args=(group.id,)))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
|
|
|
|
def test_extended_bodyclass_template_delete_selected_confirmation(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The admin/delete_selected_confirmation.html template uses
|
2014-01-08 16:48:43 +00:00
|
|
|
|
block.super in bodyclass block.
|
|
|
|
|
"""
|
|
|
|
|
group = Group.objects.create(name="foogroup")
|
|
|
|
|
post_data = {
|
|
|
|
|
'action': 'delete_selected',
|
2014-03-02 14:25:53 +00:00
|
|
|
|
'selected_across': '0',
|
2014-01-08 16:48:43 +00:00
|
|
|
|
'index': '0',
|
|
|
|
|
'_selected_action': group.id
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_group_changelist'), post_data)
|
2014-11-23 14:08:34 +00:00
|
|
|
|
self.assertEqual(response.context['site_header'], 'Django administration')
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, 'bodyclass_consistency_check ')
|
|
|
|
|
|
|
|
|
|
def test_filter_with_custom_template(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
A custom template can be used to render an admin filter.
|
2014-01-08 16:48:43 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_color2_changelist'))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertTemplateUsed(response, 'custom_filter_template.html')
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2012-02-09 18:56:32 +00:00
|
|
|
|
class AdminViewFormUrlTest(TestCase):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
current_app = "admin3"
|
2012-02-09 18:56:32 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
|
2012-02-09 18:56:32 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2012-02-09 18:56:32 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_form_URL_has_correct_value(self):
|
2012-02-09 18:56:32 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
change_view has form_url in response.context
|
2012-02-09 18:56:32 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
2015-02-23 00:53:57 +00:00
|
|
|
|
reverse('admin:admin_views_section_change', args=(self.s1.pk,), current_app=self.current_app)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
)
|
2014-10-28 10:02:56 +00:00
|
|
|
|
self.assertIn('form_url', response.context, msg='form_url not present in response.context')
|
2012-02-09 18:56:32 +00:00
|
|
|
|
self.assertEqual(response.context['form_url'], 'pony')
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_initial_data_can_be_overridden(self):
|
2014-02-26 22:34:19 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The behavior for setting initial form data can be overridden in the
|
|
|
|
|
ModelAdmin class. Usually, the initial value is set via the GET params.
|
2014-02-26 22:34:19 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_restaurant_add', current_app=self.current_app),
|
|
|
|
|
{'name': 'test_value'}
|
|
|
|
|
)
|
2014-02-26 22:34:19 +00:00
|
|
|
|
# this would be the usual behaviour
|
|
|
|
|
self.assertNotContains(response, 'value="test_value"')
|
|
|
|
|
# this is the overridden behaviour
|
|
|
|
|
self.assertContains(response, 'value="overridden_value"')
|
|
|
|
|
|
2012-02-09 18:59:05 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2012-02-27 13:29:56 +00:00
|
|
|
|
class AdminJavaScriptTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2012-02-27 13:29:56 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2012-02-27 13:29:56 +00:00
|
|
|
|
|
2012-02-05 10:26:05 +00:00
|
|
|
|
def test_js_minified_only_if_debug_is_false(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The minified versions of the JS files are only used when DEBUG is False.
|
2012-02-05 10:26:05 +00:00
|
|
|
|
"""
|
|
|
|
|
with override_settings(DEBUG=False):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'))
|
2015-06-06 23:32:54 +00:00
|
|
|
|
self.assertNotContains(response, 'vendor/jquery/jquery.js')
|
|
|
|
|
self.assertContains(response, 'vendor/jquery/jquery.min.js')
|
2012-02-05 10:26:05 +00:00
|
|
|
|
self.assertNotContains(response, 'prepopulate.js')
|
|
|
|
|
self.assertContains(response, 'prepopulate.min.js')
|
|
|
|
|
self.assertNotContains(response, 'actions.js')
|
|
|
|
|
self.assertContains(response, 'actions.min.js')
|
|
|
|
|
self.assertNotContains(response, 'collapse.js')
|
|
|
|
|
self.assertContains(response, 'collapse.min.js')
|
|
|
|
|
self.assertNotContains(response, 'inlines.js')
|
|
|
|
|
self.assertContains(response, 'inlines.min.js')
|
|
|
|
|
with override_settings(DEBUG=True):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'))
|
2015-06-06 23:32:54 +00:00
|
|
|
|
self.assertContains(response, 'vendor/jquery/jquery.js')
|
|
|
|
|
self.assertNotContains(response, 'vendor/jquery/jquery.min.js')
|
2012-02-05 10:26:05 +00:00
|
|
|
|
self.assertContains(response, 'prepopulate.js')
|
|
|
|
|
self.assertNotContains(response, 'prepopulate.min.js')
|
|
|
|
|
self.assertContains(response, 'actions.js')
|
|
|
|
|
self.assertNotContains(response, 'actions.min.js')
|
|
|
|
|
self.assertContains(response, 'collapse.js')
|
|
|
|
|
self.assertNotContains(response, 'collapse.min.js')
|
|
|
|
|
self.assertContains(response, 'inlines.js')
|
|
|
|
|
self.assertNotContains(response, 'inlines.min.js')
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-05-08 12:53:14 +00:00
|
|
|
|
class SaveAsTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2009-05-08 12:53:14 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-05-08 12:53:14 +00:00
|
|
|
|
|
|
|
|
|
def test_save_as_duplication(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""'save as' creates a new person"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42}
|
2016-04-03 14:50:01 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_person_change', args=(self.per1.pk,)), post_data)
|
2009-05-08 12:53:14 +00:00
|
|
|
|
self.assertEqual(len(Person.objects.filter(name='John M')), 1)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertEqual(len(Person.objects.filter(id=self.per1.pk)), 1)
|
2016-04-03 14:50:01 +00:00
|
|
|
|
new_person = Person.objects.latest('id')
|
|
|
|
|
self.assertRedirects(response, reverse('admin:admin_views_person_change', args=(new_person.pk,)))
|
|
|
|
|
|
|
|
|
|
def test_save_as_continue_false(self):
|
|
|
|
|
"""
|
|
|
|
|
Saving a new object using "Save as new" redirects to the changelist
|
|
|
|
|
instead of the change view when ModelAdmin.save_as_continue=False.
|
|
|
|
|
"""
|
|
|
|
|
post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42}
|
|
|
|
|
url = reverse('admin:admin_views_person_change', args=(self.per1.pk,), current_app=site2.name)
|
|
|
|
|
response = self.client.post(url, post_data)
|
|
|
|
|
self.assertEqual(len(Person.objects.filter(name='John M')), 1)
|
|
|
|
|
self.assertEqual(len(Person.objects.filter(id=self.per1.pk)), 1)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:admin_views_person_changelist', current_app=site2.name))
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2015-04-25 01:31:26 +00:00
|
|
|
|
def test_save_as_new_with_validation_errors(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
When you click "Save as new" and have a validation error,
|
2015-04-25 01:31:26 +00:00
|
|
|
|
you only see the "Save as new" button and not the other save buttons,
|
|
|
|
|
and that only the "Save as" button is visible.
|
|
|
|
|
"""
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_person_change', args=(self.per1.pk,)), {
|
|
|
|
|
'_saveasnew': '',
|
|
|
|
|
'gender': 'invalid',
|
|
|
|
|
'_addanother': 'fail',
|
|
|
|
|
})
|
|
|
|
|
self.assertContains(response, 'Please correct the errors below.')
|
|
|
|
|
self.assertFalse(response.context['show_save_and_add_another'])
|
|
|
|
|
self.assertFalse(response.context['show_save_and_continue'])
|
|
|
|
|
self.assertTrue(response.context['show_save_as_new'])
|
|
|
|
|
|
|
|
|
|
def test_save_as_new_with_validation_errors_with_inlines(self):
|
|
|
|
|
parent = Parent.objects.create(name='Father')
|
|
|
|
|
child = Child.objects.create(parent=parent, name='Child')
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_parent_change', args=(parent.pk,)), {
|
|
|
|
|
'_saveasnew': 'Save as new',
|
|
|
|
|
'child_set-0-parent': parent.pk,
|
|
|
|
|
'child_set-0-id': child.pk,
|
|
|
|
|
'child_set-0-name': 'Child',
|
|
|
|
|
'child_set-INITIAL_FORMS': 1,
|
|
|
|
|
'child_set-MAX_NUM_FORMS': 1000,
|
|
|
|
|
'child_set-MIN_NUM_FORMS': 0,
|
|
|
|
|
'child_set-TOTAL_FORMS': 4,
|
|
|
|
|
'name': '_invalid',
|
|
|
|
|
})
|
|
|
|
|
self.assertContains(response, 'Please correct the error below.')
|
|
|
|
|
self.assertFalse(response.context['show_save_and_add_another'])
|
|
|
|
|
self.assertFalse(response.context['show_save_and_continue'])
|
|
|
|
|
self.assertTrue(response.context['show_save_as_new'])
|
|
|
|
|
|
|
|
|
|
def test_save_as_new_with_inlines_with_validation_errors(self):
|
|
|
|
|
parent = Parent.objects.create(name='Father')
|
|
|
|
|
child = Child.objects.create(parent=parent, name='Child')
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_parent_change', args=(parent.pk,)), {
|
|
|
|
|
'_saveasnew': 'Save as new',
|
|
|
|
|
'child_set-0-parent': parent.pk,
|
|
|
|
|
'child_set-0-id': child.pk,
|
|
|
|
|
'child_set-0-name': '_invalid',
|
|
|
|
|
'child_set-INITIAL_FORMS': 1,
|
|
|
|
|
'child_set-MAX_NUM_FORMS': 1000,
|
|
|
|
|
'child_set-MIN_NUM_FORMS': 0,
|
|
|
|
|
'child_set-TOTAL_FORMS': 4,
|
|
|
|
|
'name': 'Father',
|
|
|
|
|
})
|
|
|
|
|
self.assertContains(response, 'Please correct the error below.')
|
|
|
|
|
self.assertFalse(response.context['show_save_and_add_another'])
|
|
|
|
|
self.assertFalse(response.context['show_save_and_continue'])
|
|
|
|
|
self.assertTrue(response.context['show_save_as_new'])
|
2009-05-08 12:53:14 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2013-06-28 00:13:42 +00:00
|
|
|
|
class CustomModelAdminTest(AdminViewBasicTestCase):
|
2009-01-14 20:22:25 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_login_form(self):
|
2010-12-02 00:44:35 +00:00
|
|
|
|
self.client.logout()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:index'), follow=True)
|
2011-04-22 18:17:16 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login = self.client.post(reverse('admin2:login'), {
|
|
|
|
|
REDIRECT_FIELD_NAME: reverse('admin2:index'),
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'customform',
|
|
|
|
|
'password': 'secret',
|
2014-01-31 14:18:55 +00:00
|
|
|
|
}, follow=True)
|
2011-04-22 18:17:16 +00:00
|
|
|
|
self.assertIsInstance(login, TemplateResponse)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(login.status_code, 200)
|
2010-12-02 00:44:35 +00:00
|
|
|
|
self.assertContains(login, 'custom form error')
|
2015-03-07 10:57:52 +00:00
|
|
|
|
self.assertContains(login, 'path/to/media.css')
|
2010-12-02 00:44:35 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_login_template(self):
|
2009-01-14 20:22:25 +00:00
|
|
|
|
self.client.logout()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:index'), follow=True)
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/login.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom login template')
|
2009-01-14 20:22:25 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_logout_template(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:logout'))
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/logout.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom logout template')
|
2010-01-12 23:34:46 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_index_view_and_template(self):
|
2016-06-28 15:21:26 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:index'))
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/index.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom index template *bar*')
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_app_index_view_and_template(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:app_list', args=('admin_views',)))
|
2013-07-31 06:37:54 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/app_index.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom app_index template')
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_password_change_template(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:password_change'))
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/password_change_form.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom password change form template')
|
2010-01-12 23:34:46 +00:00
|
|
|
|
|
2014-11-29 06:19:59 +00:00
|
|
|
|
def test_custom_admin_site_password_change_with_extra_context(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:password_change'))
|
2014-11-29 06:19:59 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/password_change_form.html')
|
|
|
|
|
self.assertContains(response, 'eggs')
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_password_change_done_template(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:password_change_done'))
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertIsInstance(response, TemplateResponse)
|
|
|
|
|
self.assertTemplateUsed(response, 'custom_admin/password_change_done.html')
|
|
|
|
|
self.assertContains(response, 'Hello from a custom password change done template')
|
2010-01-12 23:34:46 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_custom_admin_site_view(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:my_view'))
|
2012-08-14 09:57:18 +00:00
|
|
|
|
self.assertEqual(response.content, b"Django is a magical pony!")
|
2009-01-14 20:22:25 +00:00
|
|
|
|
|
2012-12-03 23:39:03 +00:00
|
|
|
|
def test_pwd_change_custom_template(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2012-12-03 23:39:03 +00:00
|
|
|
|
su = User.objects.get(username='super')
|
2016-06-28 15:21:26 +00:00
|
|
|
|
response = self.client.get(reverse('admin4:auth_user_password_change', args=(su.pk,)))
|
2012-12-03 23:39:03 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def get_perm(Model, perm):
|
|
|
|
|
"""Return the permission object, for the Model"""
|
|
|
|
|
ct = ContentType.objects.get_for_model(Model)
|
2008-08-09 20:52:40 +00:00
|
|
|
|
return Permission.objects.get(content_type=ct, codename=perm)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-05-04 00:11:21 +00:00
|
|
|
|
@override_settings(
|
|
|
|
|
ROOT_URLCONF='admin_views.urls',
|
|
|
|
|
# Test with the admin's documented list of required context processors.
|
|
|
|
|
TEMPLATES=[{
|
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
|
'APP_DIRS': True,
|
|
|
|
|
'OPTIONS': {
|
|
|
|
|
'context_processors': [
|
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}],
|
|
|
|
|
)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
class AdminViewPermissionsTest(TestCase):
|
|
|
|
|
"""Tests for Admin Views Permissions."""
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2015-02-09 01:10:12 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2018-05-02 08:39:12 +00:00
|
|
|
|
cls.viewuser = User.objects.create_user(username='viewuser', password='secret', is_staff=True)
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.adduser = User.objects.create_user(username='adduser', password='secret', is_staff=True)
|
|
|
|
|
cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
|
|
|
|
|
cls.deleteuser = User.objects.create_user(username='deleteuser', password='secret', is_staff=True)
|
|
|
|
|
cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
|
|
|
|
|
cls.nostaffuser = User.objects.create_user(username='nostaff', password='secret')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
2015-12-10 07:06:01 +00:00
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1,
|
|
|
|
|
another_section=cls.s1,
|
2015-02-23 00:53:57 +00:00
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
# Setup permissions, for our users who can add, change, and delete.
|
2008-07-18 23:54:34 +00:00
|
|
|
|
opts = Article._meta
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# User who can view Articles
|
|
|
|
|
cls.viewuser.user_permissions.add(get_perm(Article, get_permission_codename('view', opts)))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# User who can add Articles
|
2015-11-20 17:02:38 +00:00
|
|
|
|
cls.adduser.user_permissions.add(get_perm(Article, get_permission_codename('add', opts)))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# User who can change Articles
|
2015-11-20 17:02:38 +00:00
|
|
|
|
cls.changeuser.user_permissions.add(get_perm(Article, get_permission_codename('change', opts)))
|
|
|
|
|
cls.nostaffuser.user_permissions.add(get_perm(Article, get_permission_codename('change', opts)))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# User who can delete Articles
|
2015-11-20 17:02:38 +00:00
|
|
|
|
cls.deleteuser.user_permissions.add(get_perm(Article, get_permission_codename('delete', opts)))
|
|
|
|
|
cls.deleteuser.user_permissions.add(get_perm(Section, get_permission_codename('delete', Section._meta)))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# login POST dicts
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.index_url = reverse('admin:index')
|
|
|
|
|
cls.super_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'super',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.super_email_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'super@example.com',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.super_email_bad_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'super@example.com',
|
|
|
|
|
'password': 'notsecret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.adduser_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'adduser',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.changeuser_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'changeuser',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.deleteuser_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'deleteuser',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.nostaff_login = {
|
2015-02-06 22:25:15 +00:00
|
|
|
|
REDIRECT_FIELD_NAME: reverse('has_permission_admin:index'),
|
2014-12-31 21:25:00 +00:00
|
|
|
|
'username': 'nostaff',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.joepublic_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'username': 'joepublic',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2018-05-02 08:39:12 +00:00
|
|
|
|
cls.viewuser_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
|
|
|
|
'username': 'viewuser',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2015-02-09 01:10:12 +00:00
|
|
|
|
cls.no_username_login = {
|
|
|
|
|
REDIRECT_FIELD_NAME: cls.index_url,
|
2010-12-02 00:44:35 +00:00
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_login(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Make sure only staff members can log in.
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2014-04-26 17:18:45 +00:00
|
|
|
|
Successful posts to the login page will redirect to the original url.
|
|
|
|
|
Unsuccessful attempts will continue to render the login page with
|
2008-07-18 23:54:34 +00:00
|
|
|
|
a 200 status code.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index'))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Super User
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2015-06-26 19:56:51 +00:00
|
|
|
|
self.assertRedirects(response, login_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2012-09-26 12:14:51 +00:00
|
|
|
|
# Test if user enters email address
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.super_email_login)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertContains(login, ERROR_MESSAGE)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# only correct passwords get a username hint
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_email_bad_login)
|
2011-09-22 04:16:21 +00:00
|
|
|
|
self.assertContains(login, ERROR_MESSAGE)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
new_user = User(username='jondoe', password='secret', email='super@example.com')
|
|
|
|
|
new_user.save()
|
2012-09-26 12:14:51 +00:00
|
|
|
|
# check to ensure if there are multiple email addresses a user doesn't get a 500
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_email_login)
|
2011-09-22 04:16:21 +00:00
|
|
|
|
self.assertContains(login, ERROR_MESSAGE)
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# View User
|
|
|
|
|
response = self.client.get(self.index_url)
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.viewuser_login)
|
|
|
|
|
self.assertRedirects(login, self.index_url)
|
|
|
|
|
self.assertFalse(login.context)
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Add User
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.adduser_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Change User
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.changeuser_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Delete User
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.deleteuser_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Regular User should not be able to login.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.joepublic_login)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(login.status_code, 200)
|
2011-09-22 04:16:21 +00:00
|
|
|
|
self.assertContains(login, ERROR_MESSAGE)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
2009-09-10 16:50:57 +00:00
|
|
|
|
# Requests without username should not return 500 errors.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
login = self.client.post(login_url, self.no_username_login)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(login.status_code, 200)
|
2016-09-27 13:56:19 +00:00
|
|
|
|
self.assertFormError(login, 'form', 'username', ['This field is required.'])
|
2009-09-10 16:50:57 +00:00
|
|
|
|
|
2015-06-26 19:56:51 +00:00
|
|
|
|
def test_login_redirect_for_direct_get(self):
|
|
|
|
|
"""
|
|
|
|
|
Login redirect should be to the admin index page when going directly to
|
|
|
|
|
/admin/login/.
|
|
|
|
|
"""
|
|
|
|
|
response = self.client.get(reverse('admin:login'))
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.context[REDIRECT_FIELD_NAME], reverse('admin:index'))
|
|
|
|
|
|
2014-12-31 21:25:00 +00:00
|
|
|
|
def test_login_has_permission(self):
|
|
|
|
|
# Regular User should not be able to login.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('has_permission_admin:index'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login = self.client.post(reverse('has_permission_admin:login'), self.joepublic_login)
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertEqual(login.status_code, 200)
|
|
|
|
|
self.assertContains(login, 'permission denied')
|
|
|
|
|
|
|
|
|
|
# User with permissions should be able to login.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('has_permission_admin:index'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login = self.client.post(reverse('has_permission_admin:login'), self.nostaff_login)
|
|
|
|
|
self.assertRedirects(login, reverse('has_permission_admin:index'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('has_permission_admin:logout'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
|
|
|
|
|
# Staff should be able to login.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('has_permission_admin:index'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login = self.client.post(reverse('has_permission_admin:login'), {
|
|
|
|
|
REDIRECT_FIELD_NAME: reverse('has_permission_admin:index'),
|
2014-12-31 21:25:00 +00:00
|
|
|
|
'username': 'deleteuser',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
})
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, reverse('has_permission_admin:index'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('has_permission_admin:logout'))
|
2014-12-31 21:25:00 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_login_successfully_redirects_to_original_URL(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2010-12-02 00:44:35 +00:00
|
|
|
|
query_string = 'the-answer=42'
|
2015-02-06 22:25:15 +00:00
|
|
|
|
redirect_url = '%s?%s' % (self.index_url, query_string)
|
2010-12-02 00:44:35 +00:00
|
|
|
|
new_next = {REDIRECT_FIELD_NAME: redirect_url}
|
2014-01-31 14:18:55 +00:00
|
|
|
|
post_data = self.super_login.copy()
|
|
|
|
|
post_data.pop(REDIRECT_FIELD_NAME)
|
|
|
|
|
login = self.client.post(
|
|
|
|
|
'%s?%s' % (reverse('admin:login'), urlencode(new_next)),
|
|
|
|
|
post_data)
|
2010-12-02 00:44:35 +00:00
|
|
|
|
self.assertRedirects(login, redirect_url)
|
2008-08-09 17:35:19 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_double_login_is_not_allowed(self):
|
2013-03-18 23:58:33 +00:00
|
|
|
|
"""Regression test for #19327"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index'))
|
2014-01-31 14:18:55 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2013-03-18 23:58:33 +00:00
|
|
|
|
|
|
|
|
|
# Establish a valid admin session
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2013-03-18 23:58:33 +00:00
|
|
|
|
self.assertFalse(login.context)
|
|
|
|
|
|
|
|
|
|
# Logging in with non-admin user fails
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.joepublic_login)
|
2013-03-18 23:58:33 +00:00
|
|
|
|
self.assertEqual(login.status_code, 200)
|
|
|
|
|
self.assertContains(login, ERROR_MESSAGE)
|
|
|
|
|
|
|
|
|
|
# Establish a valid admin session
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2013-03-18 23:58:33 +00:00
|
|
|
|
self.assertFalse(login.context)
|
|
|
|
|
|
|
|
|
|
# Logging in with admin user while already logged in
|
2014-01-31 14:18:55 +00:00
|
|
|
|
login = self.client.post(login_url, self.super_login)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(login, self.index_url)
|
2013-03-18 23:58:33 +00:00
|
|
|
|
self.assertFalse(login.context)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2013-03-18 23:58:33 +00:00
|
|
|
|
|
2015-07-25 14:49:00 +00:00
|
|
|
|
def test_login_page_notice_for_non_staff_users(self):
|
|
|
|
|
"""
|
|
|
|
|
A logged-in non-staff user trying to access the admin index should be
|
|
|
|
|
presented with the login page and a hint indicating that the current
|
|
|
|
|
user doesn't have access to it.
|
|
|
|
|
"""
|
|
|
|
|
hint_template = 'You are authenticated as {}'
|
|
|
|
|
|
|
|
|
|
# Anonymous user should not be shown the hint
|
|
|
|
|
response = self.client.get(self.index_url, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
self.assertNotContains(response, hint_template.format(''), status_code=200)
|
|
|
|
|
|
|
|
|
|
# Non-staff user should be shown the hint
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.nostaffuser)
|
2015-07-25 14:49:00 +00:00
|
|
|
|
response = self.client.get(self.index_url, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.assertContains(response, hint_template.format(self.nostaffuser.username), status_code=200)
|
2015-07-25 14:49:00 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_add_view(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
|
"""Test add view restricts access and actually adds items."""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
add_dict = {'title': 'Døm ikke',
|
2008-08-08 18:07:33 +00:00
|
|
|
|
'content': '<p>great article</p>',
|
2008-07-18 23:54:34 +00:00
|
|
|
|
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
2015-02-23 00:53:57 +00:00
|
|
|
|
'section': self.s1.pk}
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Change User should not have access to add articles
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2008-08-23 14:12:58 +00:00
|
|
|
|
# make sure the view removes test cookie
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(self.client.session.test_cookie_worked(), False)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_add'))
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertEqual(response.status_code, 403)
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Try POST just to make sure
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(post.status_code, 403)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.assertEqual(Article.objects.count(), 3)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# View User should not have access to add articles
|
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_add'))
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
# Try POST just to make sure
|
|
|
|
|
post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
|
|
|
|
|
self.assertEqual(post.status_code, 403)
|
|
|
|
|
self.assertEqual(Article.objects.count(), 3)
|
|
|
|
|
# Now give the user permission to add but not change.
|
|
|
|
|
self.viewuser.user_permissions.add(get_perm(Article, get_permission_codename('add', Article._meta)))
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_add'))
|
|
|
|
|
self.assertContains(response, '<input type="submit" value="Save and view" name="_continue">')
|
|
|
|
|
post = self.client.post(reverse('admin:admin_views_article_add'), add_dict, follow=False)
|
|
|
|
|
self.assertEqual(post.status_code, 302)
|
|
|
|
|
self.assertEqual(Article.objects.count(), 4)
|
|
|
|
|
article = Article.objects.latest('pk')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_change', args=(article.pk,)))
|
|
|
|
|
self.assertContains(response, '<li class="success">The article "Døm ikke" was added successfully.</li>')
|
|
|
|
|
article.delete()
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Add user may login and POST to add view, then redirect to admin root
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
addpage = self.client.get(reverse('admin:admin_views_article_add'))
|
|
|
|
|
change_list_link = '› <a href="%s">Articles</a>' % reverse('admin:admin_views_article_changelist')
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertNotContains(
|
|
|
|
|
addpage, change_list_link,
|
|
|
|
|
msg_prefix='User restricted to add permission is given link to change list view in breadcrumbs.'
|
|
|
|
|
)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
|
|
|
|
|
self.assertRedirects(post, self.index_url)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.assertEqual(Article.objects.count(), 4)
|
2018-05-02 08:39:12 +00:00
|
|
|
|
self.assertEqual(len(mail.outbox), 2)
|
2011-03-03 15:04:39 +00:00
|
|
|
|
self.assertEqual(mail.outbox[0].subject, 'Greetings from a created object')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The addition was logged correctly
|
2015-03-16 21:55:44 +00:00
|
|
|
|
addition_log = LogEntry.objects.all()[0]
|
|
|
|
|
new_article = Article.objects.last()
|
|
|
|
|
article_ct = ContentType.objects.get_for_model(Article)
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.assertEqual(addition_log.user_id, self.adduser.pk)
|
2015-03-16 21:55:44 +00:00
|
|
|
|
self.assertEqual(addition_log.content_type_id, article_ct.pk)
|
|
|
|
|
self.assertEqual(addition_log.object_id, str(new_article.pk))
|
|
|
|
|
self.assertEqual(addition_log.object_repr, "Døm ikke")
|
|
|
|
|
self.assertEqual(addition_log.action_flag, ADDITION)
|
2015-12-26 18:51:22 +00:00
|
|
|
|
self.assertEqual(addition_log.get_change_message(), "Added.")
|
2015-03-16 21:55:44 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# Super can add too, but is redirected to the change list view
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
addpage = self.client.get(reverse('admin:admin_views_article_add'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
addpage, change_list_link,
|
|
|
|
|
msg_prefix='Unrestricted user is not given link to change list view in breadcrumbs.'
|
|
|
|
|
)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
|
|
|
|
|
self.assertRedirects(post, reverse('admin:admin_views_article_changelist'))
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.assertEqual(Article.objects.count(), 5)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-08-24 06:34:18 +00:00
|
|
|
|
# 8509 - if a normal user is already logged in, it is possible
|
|
|
|
|
# to change user into the superuser without error
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.joepublicuser)
|
2008-08-24 06:34:18 +00:00
|
|
|
|
# Check and make sure that if user expires, data still persists
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2008-08-24 06:34:18 +00:00
|
|
|
|
# make sure the view removes test cookie
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(self.client.session.test_cookie_worked(), False)
|
2008-08-24 06:34:18 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_change_view(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
|
"""Change view should restrict access and allow users to edit items."""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
change_dict = {'title': 'Ikke fordømt',
|
2008-08-08 18:07:33 +00:00
|
|
|
|
'content': '<p>edited article</p>',
|
|
|
|
|
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
2015-02-23 00:53:57 +00:00
|
|
|
|
'section': self.s1.pk}
|
|
|
|
|
article_change_url = reverse('admin:admin_views_article_change', args=(self.a1.pk,))
|
2015-02-06 22:25:15 +00:00
|
|
|
|
article_changelist_url = reverse('admin:admin_views_article_changelist')
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2014-03-02 14:25:53 +00:00
|
|
|
|
# add user should not be able to view the list of article or change any of them
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(article_changelist_url)
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertEqual(response.status_code, 403)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(article_change_url)
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertEqual(response.status_code, 403)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(article_change_url, change_dict)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(post.status_code, 403)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# view user should be able to view the article but not change any of them
|
2018-08-01 16:55:53 +00:00
|
|
|
|
# (the POST can be sent, but no modification occurs)
|
2018-05-02 08:39:12 +00:00
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(article_changelist_url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2018-05-23 15:02:37 +00:00
|
|
|
|
self.assertEqual(response.context['title'], 'Select article to view')
|
2018-05-02 08:39:12 +00:00
|
|
|
|
response = self.client.get(article_change_url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2018-05-23 15:02:37 +00:00
|
|
|
|
self.assertEqual(response.context['title'], 'View article')
|
2018-08-18 20:15:18 +00:00
|
|
|
|
self.assertContains(response, '<label>Extra form field:</label>')
|
2018-05-02 08:39:12 +00:00
|
|
|
|
self.assertContains(response, '<a href="/test_admin/admin/admin_views/article/" class="closelink">Close</a>')
|
|
|
|
|
post = self.client.post(article_change_url, change_dict)
|
|
|
|
|
self.assertEqual(post.status_code, 302)
|
|
|
|
|
self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>Middle content</p>')
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
# change user can view all items and edit them
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(article_changelist_url)
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2018-05-23 15:02:37 +00:00
|
|
|
|
self.assertEqual(response.context['title'], 'Select article to change')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(article_change_url)
|
2012-08-14 12:36:11 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2018-05-23 15:02:37 +00:00
|
|
|
|
self.assertEqual(response.context['title'], 'Change article')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(article_change_url, change_dict)
|
|
|
|
|
self.assertRedirects(post, article_changelist_url)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>edited article</p>')
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2008-11-09 18:51:28 +00:00
|
|
|
|
# one error in form should produce singular error message, multiple errors plural
|
|
|
|
|
change_dict['title'] = ''
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(article_change_url, change_dict)
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
post, 'Please correct the error below.',
|
|
|
|
|
msg_prefix='Singular error message not found in response to post with one error'
|
|
|
|
|
)
|
2012-06-07 16:08:47 +00:00
|
|
|
|
|
2008-11-09 18:51:28 +00:00
|
|
|
|
change_dict['content'] = ''
|
2015-02-06 22:25:15 +00:00
|
|
|
|
post = self.client.post(article_change_url, change_dict)
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
post, 'Please correct the errors below.',
|
|
|
|
|
msg_prefix='Plural error message not found in response to post with multiple errors'
|
|
|
|
|
)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
2011-02-19 14:05:07 +00:00
|
|
|
|
# Test redirection when using row-level change permissions. Refs #11513.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
r1 = RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
|
|
|
|
|
r2 = RowLevelChangePermissionModel.objects.create(id=2, name="even id")
|
2018-05-02 08:39:12 +00:00
|
|
|
|
r3 = RowLevelChangePermissionModel.objects.create(id=3, name='odd id mult 3')
|
|
|
|
|
r6 = RowLevelChangePermissionModel.objects.create(id=6, name='even id mult 3')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
change_url_1 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r1.pk,))
|
|
|
|
|
change_url_2 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r2.pk,))
|
2018-05-02 08:39:12 +00:00
|
|
|
|
change_url_3 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r3.pk,))
|
|
|
|
|
change_url_6 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r6.pk,))
|
|
|
|
|
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
|
|
|
|
for login_user in logins:
|
2018-08-13 01:27:19 +00:00
|
|
|
|
with self.subTest(login_user.username):
|
|
|
|
|
self.client.force_login(login_user)
|
|
|
|
|
response = self.client.get(change_url_1)
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
response = self.client.post(change_url_1, {'name': 'changed'})
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
response = self.client.get(change_url_2)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
response = self.client.post(change_url_2, {'name': 'changed'})
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
|
|
|
|
self.assertRedirects(response, self.index_url)
|
|
|
|
|
response = self.client.get(change_url_3)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
response = self.client.post(change_url_3, {'name': 'changed'})
|
|
|
|
|
self.assertRedirects(response, self.index_url)
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=3).name, 'odd id mult 3')
|
|
|
|
|
response = self.client.get(change_url_6)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
response = self.client.post(change_url_6, {'name': 'changed'})
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=6).name, 'changed')
|
|
|
|
|
self.assertRedirects(response, self.index_url)
|
|
|
|
|
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2014-01-31 14:18:55 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
for login_user in [self.joepublicuser, self.nostaffuser]:
|
2018-08-13 01:27:19 +00:00
|
|
|
|
with self.subTest(login_user.username):
|
|
|
|
|
self.client.force_login(login_user)
|
|
|
|
|
response = self.client.get(change_url_1, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
response = self.client.post(change_url_1, {'name': 'changed'}, follow=True)
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
response = self.client.get(change_url_2, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
response = self.client.post(change_url_2, {'name': 'changed again'}, follow=True)
|
|
|
|
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2011-02-19 14:05:07 +00:00
|
|
|
|
|
2018-06-15 21:05:44 +00:00
|
|
|
|
def test_change_view_without_object_change_permission(self):
|
|
|
|
|
"""
|
|
|
|
|
The object should be read-only if the user has permission to view it
|
|
|
|
|
and change objects of that type but not to change the current object.
|
|
|
|
|
"""
|
|
|
|
|
change_url = reverse('admin9:admin_views_article_change', args=(self.a1.pk,))
|
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(change_url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.context['title'], 'View article')
|
|
|
|
|
self.assertContains(response, '<a href="/test_admin/admin9/admin_views/article/" class="closelink">Close</a>')
|
|
|
|
|
|
2018-08-12 14:51:23 +00:00
|
|
|
|
def test_change_view_post_without_object_change_permission(self):
|
|
|
|
|
"""A POST redirectS to changelist without modifications."""
|
|
|
|
|
change_dict = {
|
|
|
|
|
'title': 'Ikke fordømt',
|
|
|
|
|
'content': '<p>edited article</p>',
|
|
|
|
|
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
|
|
|
|
'section': self.s1.pk,
|
|
|
|
|
}
|
|
|
|
|
change_url = reverse('admin10:admin_views_article_change', args=(self.a1.pk,))
|
|
|
|
|
changelist_url = reverse('admin10:admin_views_article_changelist')
|
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.post(change_url, change_dict)
|
|
|
|
|
self.assertRedirects(response, changelist_url)
|
|
|
|
|
self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>Middle content</p>')
|
|
|
|
|
|
2016-01-24 13:13:23 +00:00
|
|
|
|
def test_change_view_save_as_new(self):
|
|
|
|
|
"""
|
|
|
|
|
'Save as new' should raise PermissionDenied for users without the 'add'
|
|
|
|
|
permission.
|
|
|
|
|
"""
|
|
|
|
|
change_dict_save_as_new = {
|
|
|
|
|
'_saveasnew': 'Save as new',
|
|
|
|
|
'title': 'Ikke fordømt',
|
|
|
|
|
'content': '<p>edited article</p>',
|
|
|
|
|
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
|
|
|
|
'section': self.s1.pk,
|
|
|
|
|
}
|
|
|
|
|
article_change_url = reverse('admin:admin_views_article_change', args=(self.a1.pk,))
|
|
|
|
|
|
|
|
|
|
# Add user can perform "Save as new".
|
|
|
|
|
article_count = Article.objects.count()
|
|
|
|
|
self.client.force_login(self.adduser)
|
|
|
|
|
post = self.client.post(article_change_url, change_dict_save_as_new)
|
|
|
|
|
self.assertRedirects(post, self.index_url)
|
|
|
|
|
self.assertEqual(Article.objects.count(), article_count + 1)
|
|
|
|
|
self.client.logout()
|
|
|
|
|
|
|
|
|
|
# Change user cannot perform "Save as new" (no 'add' permission).
|
|
|
|
|
article_count = Article.objects.count()
|
|
|
|
|
self.client.force_login(self.changeuser)
|
|
|
|
|
post = self.client.post(article_change_url, change_dict_save_as_new)
|
|
|
|
|
self.assertEqual(post.status_code, 403)
|
|
|
|
|
self.assertEqual(Article.objects.count(), article_count)
|
|
|
|
|
|
2016-04-03 14:50:01 +00:00
|
|
|
|
# User with both add and change permissions should be redirected to the
|
|
|
|
|
# change page for the newly created object.
|
|
|
|
|
article_count = Article.objects.count()
|
|
|
|
|
self.client.force_login(self.superuser)
|
|
|
|
|
post = self.client.post(article_change_url, change_dict_save_as_new)
|
|
|
|
|
self.assertEqual(Article.objects.count(), article_count + 1)
|
|
|
|
|
new_article = Article.objects.latest('id')
|
|
|
|
|
self.assertRedirects(post, reverse('admin:admin_views_article_change', args=(new_article.pk,)))
|
|
|
|
|
|
2015-02-09 01:10:12 +00:00
|
|
|
|
def test_delete_view(self):
|
|
|
|
|
"""Delete view should restrict access and actually delete items."""
|
|
|
|
|
delete_dict = {'post': 'yes'}
|
2015-02-23 00:53:57 +00:00
|
|
|
|
delete_url = reverse('admin:admin_views_article_delete', args=(self.a1.pk,))
|
2015-02-09 01:10:12 +00:00
|
|
|
|
|
|
|
|
|
# add user should not be able to delete articles
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
response = self.client.get(delete_url)
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
post = self.client.post(delete_url, delete_dict)
|
|
|
|
|
self.assertEqual(post.status_code, 403)
|
|
|
|
|
self.assertEqual(Article.objects.count(), 3)
|
|
|
|
|
self.client.logout()
|
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# view user should not be able to delete articles
|
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(delete_url)
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
post = self.client.post(delete_url, delete_dict)
|
|
|
|
|
self.assertEqual(post.status_code, 403)
|
|
|
|
|
self.assertEqual(Article.objects.count(), 3)
|
|
|
|
|
self.client.logout()
|
|
|
|
|
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# Delete user can delete
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.deleteuser)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_delete', args=(self.s1.pk,)))
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.assertContains(response, "<h2>Summary</h2>")
|
|
|
|
|
self.assertContains(response, "<li>Articles: 3</li>")
|
|
|
|
|
# test response contains link to related Article
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertContains(response, "admin_views/article/%s/" % self.a1.pk)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
|
|
|
|
|
response = self.client.get(delete_url)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertContains(response, "admin_views/article/%s/" % self.a1.pk)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.assertContains(response, "<h2>Summary</h2>")
|
|
|
|
|
self.assertContains(response, "<li>Articles: 1</li>")
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
post = self.client.post(delete_url, delete_dict)
|
|
|
|
|
self.assertRedirects(post, self.index_url)
|
|
|
|
|
self.assertEqual(Article.objects.count(), 2)
|
|
|
|
|
self.assertEqual(len(mail.outbox), 1)
|
|
|
|
|
self.assertEqual(mail.outbox[0].subject, 'Greetings from a deleted object')
|
|
|
|
|
article_ct = ContentType.objects.get_for_model(Article)
|
|
|
|
|
logged = LogEntry.objects.get(content_type=article_ct, action_flag=DELETION)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertEqual(logged.object_id, str(self.a1.pk))
|
2015-02-09 01:10:12 +00:00
|
|
|
|
|
2017-08-22 23:48:55 +00:00
|
|
|
|
def test_delete_view_with_no_default_permissions(self):
|
|
|
|
|
"""
|
|
|
|
|
The delete view allows users to delete collected objects without a
|
|
|
|
|
'delete' permission (ReadOnlyPizza.Meta.default_permissions is empty).
|
|
|
|
|
"""
|
|
|
|
|
pizza = ReadOnlyPizza.objects.create(name='Double Cheese')
|
|
|
|
|
delete_url = reverse('admin:admin_views_readonlypizza_delete', args=(pizza.pk,))
|
|
|
|
|
self.client.force_login(self.adduser)
|
|
|
|
|
response = self.client.get(delete_url)
|
|
|
|
|
self.assertContains(response, 'admin_views/readonlypizza/%s/' % pizza.pk)
|
|
|
|
|
self.assertContains(response, '<h2>Summary</h2>')
|
|
|
|
|
self.assertContains(response, '<li>Read only pizzas: 1</li>')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
post = self.client.post(delete_url, {'post': 'yes'})
|
|
|
|
|
self.assertRedirects(post, reverse('admin:admin_views_readonlypizza_changelist'))
|
|
|
|
|
self.assertEqual(ReadOnlyPizza.objects.count(), 0)
|
|
|
|
|
|
2016-11-05 13:56:03 +00:00
|
|
|
|
def test_delete_view_nonexistent_obj(self):
|
|
|
|
|
self.client.force_login(self.deleteuser)
|
|
|
|
|
url = reverse('admin:admin_views_article_delete', args=('nonexistent',))
|
|
|
|
|
response = self.client.get(url, follow=True)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:index'))
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[m.message for m in response.context['messages']],
|
2017-01-04 15:12:06 +00:00
|
|
|
|
["""article with ID "nonexistent" doesn't exist. Perhaps it was deleted?"""]
|
2016-11-05 13:56:03 +00:00
|
|
|
|
)
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_history_view(self):
|
2013-02-04 23:57:59 +00:00
|
|
|
|
"""History view should restrict access."""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
# add user should not be able to view the list of article or change any of them
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_history', args=(self.a1.pk,)))
|
2013-02-04 23:57:59 +00:00
|
|
|
|
self.assertEqual(response.status_code, 403)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2013-02-04 23:57:59 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
# view user can view all items
|
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_history', args=(self.a1.pk,)))
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
|
|
|
|
|
2013-02-04 23:57:59 +00:00
|
|
|
|
# change user can view all items and edit them
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_history', args=(self.a1.pk,)))
|
2013-02-04 23:57:59 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
# Test redirection when using row-level change permissions. Refs #11513.
|
2015-02-23 00:53:57 +00:00
|
|
|
|
rl1 = RowLevelChangePermissionModel.objects.create(name="odd id")
|
|
|
|
|
rl2 = RowLevelChangePermissionModel.objects.create(name="even id")
|
2018-05-02 08:39:12 +00:00
|
|
|
|
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
|
|
|
|
for login_user in logins:
|
2018-08-13 01:27:19 +00:00
|
|
|
|
with self.subTest(login_user.username):
|
|
|
|
|
self.client.force_login(login_user)
|
|
|
|
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
2013-02-04 23:57:59 +00:00
|
|
|
|
|
2018-08-13 01:27:19 +00:00
|
|
|
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2013-02-04 23:57:59 +00:00
|
|
|
|
|
2018-08-13 01:27:19 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2013-02-04 23:57:59 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
for login_user in [self.joepublicuser, self.nostaffuser]:
|
2018-08-13 01:27:19 +00:00
|
|
|
|
with self.subTest(login_user.username):
|
|
|
|
|
self.client.force_login(login_user)
|
|
|
|
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
|
|
|
|
response = self.client.get(url, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
|
|
|
|
response = self.client.get(url, follow=True)
|
|
|
|
|
self.assertContains(response, 'login-form')
|
|
|
|
|
|
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2013-02-04 23:57:59 +00:00
|
|
|
|
|
2015-02-12 18:40:23 +00:00
|
|
|
|
def test_history_view_bad_url(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2016-11-05 13:56:03 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_article_history', args=('foo',)), follow=True)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:index'))
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[m.message for m in response.context['messages']],
|
2017-01-04 15:12:06 +00:00
|
|
|
|
["""article with ID "foo" doesn't exist. Perhaps it was deleted?"""]
|
2016-11-05 13:56:03 +00:00
|
|
|
|
)
|
2015-02-12 18:40:23 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_conditionally_show_add_section_link(self):
|
2010-09-10 16:56:36 +00:00
|
|
|
|
"""
|
|
|
|
|
The foreign key widget should only show the "add related" button if the
|
|
|
|
|
user has permission to add that related item.
|
|
|
|
|
"""
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# The user can't add sections yet, so they shouldn't see the "add section" link.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
url = reverse('admin:admin_views_article_add')
|
2013-11-17 22:26:20 +00:00
|
|
|
|
add_link_text = 'add_id_section'
|
2010-09-10 16:56:36 +00:00
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertNotContains(response, add_link_text)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# Allow the user to add sections too. Now they can see the "add section" link.
|
2013-11-17 22:26:20 +00:00
|
|
|
|
user = User.objects.get(username='adduser')
|
2013-07-01 13:19:55 +00:00
|
|
|
|
perm = get_perm(Section, get_permission_codename('add', Section._meta))
|
2013-11-17 22:26:20 +00:00
|
|
|
|
user.user_permissions.add(perm)
|
2010-09-10 16:56:36 +00:00
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertContains(response, add_link_text)
|
|
|
|
|
|
2013-11-17 22:26:20 +00:00
|
|
|
|
def test_conditionally_show_change_section_link(self):
|
|
|
|
|
"""
|
|
|
|
|
The foreign key widget should only show the "change related" button if
|
|
|
|
|
the user has permission to change that related item.
|
|
|
|
|
"""
|
|
|
|
|
def get_change_related(response):
|
|
|
|
|
return response.context['adminform'].form.fields['section'].widget.can_change_related
|
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# The user can't change sections yet, so they shouldn't see the "change section" link.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
url = reverse('admin:admin_views_article_add')
|
2013-11-17 22:26:20 +00:00
|
|
|
|
change_link_text = 'change_id_section'
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertFalse(get_change_related(response))
|
|
|
|
|
self.assertNotContains(response, change_link_text)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# Allow the user to change sections too. Now they can see the "change section" link.
|
2013-11-17 22:26:20 +00:00
|
|
|
|
user = User.objects.get(username='adduser')
|
|
|
|
|
perm = get_perm(Section, get_permission_codename('change', Section._meta))
|
|
|
|
|
user.user_permissions.add(perm)
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertTrue(get_change_related(response))
|
|
|
|
|
self.assertContains(response, change_link_text)
|
|
|
|
|
|
|
|
|
|
def test_conditionally_show_delete_section_link(self):
|
|
|
|
|
"""
|
|
|
|
|
The foreign key widget should only show the "delete related" button if
|
|
|
|
|
the user has permission to delete that related item.
|
|
|
|
|
"""
|
|
|
|
|
def get_delete_related(response):
|
|
|
|
|
return response.context['adminform'].form.fields['sub_section'].widget.can_delete_related
|
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# The user can't delete sections yet, so they shouldn't see the "delete section" link.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
url = reverse('admin:admin_views_article_add')
|
2013-11-17 22:26:20 +00:00
|
|
|
|
delete_link_text = 'delete_id_sub_section'
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertFalse(get_delete_related(response))
|
|
|
|
|
self.assertNotContains(response, delete_link_text)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
# Allow the user to delete sections too. Now they can see the "delete section" link.
|
2013-11-17 22:26:20 +00:00
|
|
|
|
user = User.objects.get(username='adduser')
|
|
|
|
|
perm = get_perm(Section, get_permission_codename('delete', Section._meta))
|
|
|
|
|
user.user_permissions.add(perm)
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertTrue(get_delete_related(response))
|
|
|
|
|
self.assertContains(response, delete_link_text)
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_disabled_permissions_when_logged_in(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2010-01-10 16:51:13 +00:00
|
|
|
|
superuser = User.objects.get(username='super')
|
|
|
|
|
superuser.is_active = False
|
|
|
|
|
superuser.save()
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url, follow=True)
|
2010-01-10 16:51:13 +00:00
|
|
|
|
self.assertContains(response, 'id="login-form"')
|
|
|
|
|
self.assertNotContains(response, 'Log out')
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('secure_view'), follow=True)
|
2010-01-10 16:51:13 +00:00
|
|
|
|
self.assertContains(response, 'id="login-form"')
|
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_disabled_staff_permissions_when_logged_in(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2013-09-09 11:59:35 +00:00
|
|
|
|
superuser = User.objects.get(username='super')
|
|
|
|
|
superuser.is_staff = False
|
|
|
|
|
superuser.save()
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url, follow=True)
|
2013-09-09 11:59:35 +00:00
|
|
|
|
self.assertContains(response, 'id="login-form"')
|
|
|
|
|
self.assertNotContains(response, 'Log out')
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('secure_view'), follow=True)
|
2013-09-09 11:59:35 +00:00
|
|
|
|
self.assertContains(response, 'id="login-form"')
|
|
|
|
|
|
2016-08-01 22:07:50 +00:00
|
|
|
|
def test_app_list_permissions(self):
|
2013-09-07 12:32:12 +00:00
|
|
|
|
"""
|
2016-08-01 22:07:50 +00:00
|
|
|
|
If a user has no module perms, the app list returns a 404.
|
2013-09-07 12:32:12 +00:00
|
|
|
|
"""
|
|
|
|
|
opts = Article._meta
|
|
|
|
|
change_user = User.objects.get(username='changeuser')
|
|
|
|
|
permission = get_perm(Article, get_permission_codename('change', opts))
|
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2013-09-07 12:32:12 +00:00
|
|
|
|
|
2016-08-01 22:07:50 +00:00
|
|
|
|
# the user has no module permissions
|
2013-09-07 12:32:12 +00:00
|
|
|
|
change_user.user_permissions.remove(permission)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2016-08-01 22:07:50 +00:00
|
|
|
|
self.assertEqual(response.status_code, 404)
|
2013-09-07 12:32:12 +00:00
|
|
|
|
|
|
|
|
|
# the user now has module permissions
|
|
|
|
|
change_user.user_permissions.add(permission)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2013-09-07 12:32:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2014-01-31 10:59:27 +00:00
|
|
|
|
def test_shortcut_view_only_available_to_staff(self):
|
|
|
|
|
"""
|
|
|
|
|
Only admin users should be able to use the admin shortcut view.
|
|
|
|
|
"""
|
|
|
|
|
model_ctype = ContentType.objects.get_for_model(ModelWithStringPrimaryKey)
|
|
|
|
|
obj = ModelWithStringPrimaryKey.objects.create(string_pk='foo')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
shortcut_url = reverse('admin:view_on_site', args=(model_ctype.pk, obj.pk))
|
2014-01-31 10:59:27 +00:00
|
|
|
|
|
|
|
|
|
# Not logged in: we should see the login page.
|
2014-01-31 14:18:55 +00:00
|
|
|
|
response = self.client.get(shortcut_url, follow=True)
|
2014-01-31 10:59:27 +00:00
|
|
|
|
self.assertTemplateUsed(response, 'admin/login.html')
|
|
|
|
|
|
|
|
|
|
# Logged in? Redirect.
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2014-01-31 10:59:27 +00:00
|
|
|
|
response = self.client.get(shortcut_url, follow=False)
|
|
|
|
|
# Can't use self.assertRedirects() because User.get_absolute_url() is silly.
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2014-06-21 16:27:46 +00:00
|
|
|
|
# Domain may depend on contrib.sites tests also run
|
2016-12-07 22:42:31 +00:00
|
|
|
|
self.assertRegex(response.url, 'http://(testserver|example.com)/dummy/foo/')
|
2014-01-31 10:59:27 +00:00
|
|
|
|
|
2014-05-28 16:07:27 +00:00
|
|
|
|
def test_has_module_permission(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
has_module_permission() returns True for all users who
|
2014-05-28 16:07:27 +00:00
|
|
|
|
have any permission for that module (add, change, or delete), so that
|
|
|
|
|
the module is displayed on the admin index page.
|
|
|
|
|
"""
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertContains(response, 'admin_views')
|
|
|
|
|
self.assertContains(response, 'Articles')
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(self.index_url)
|
|
|
|
|
self.assertContains(response, 'admin_views')
|
|
|
|
|
self.assertContains(response, 'Articles')
|
|
|
|
|
self.client.logout()
|
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertContains(response, 'admin_views')
|
|
|
|
|
self.assertContains(response, 'Articles')
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertContains(response, 'admin_views')
|
|
|
|
|
self.assertContains(response, 'Articles')
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.deleteuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(self.index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertContains(response, 'admin_views')
|
|
|
|
|
self.assertContains(response, 'Articles')
|
|
|
|
|
|
|
|
|
|
def test_overriding_has_module_permission(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
If has_module_permission() always returns False, the module shouldn't
|
|
|
|
|
be displayed on the admin index page for any users.
|
2014-05-28 16:07:27 +00:00
|
|
|
|
"""
|
2016-08-01 22:07:50 +00:00
|
|
|
|
articles = Article._meta.verbose_name_plural.title()
|
|
|
|
|
sections = Section._meta.verbose_name_plural.title()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
index_url = reverse('admin7:index')
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(index_url)
|
2016-08-01 22:07:50 +00:00
|
|
|
|
self.assertContains(response, sections)
|
|
|
|
|
self.assertNotContains(response, articles)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
self.client.force_login(self.viewuser)
|
|
|
|
|
response = self.client.get(index_url)
|
|
|
|
|
self.assertNotContains(response, 'admin_views')
|
|
|
|
|
self.assertNotContains(response, articles)
|
|
|
|
|
self.client.logout()
|
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertNotContains(response, 'admin_views')
|
2016-08-01 22:07:50 +00:00
|
|
|
|
self.assertNotContains(response, articles)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(index_url)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
self.assertNotContains(response, 'admin_views')
|
2016-08-01 22:07:50 +00:00
|
|
|
|
self.assertNotContains(response, articles)
|
2015-02-09 01:10:12 +00:00
|
|
|
|
self.client.logout()
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.deleteuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(index_url)
|
2016-08-01 22:07:50 +00:00
|
|
|
|
self.assertNotContains(response, articles)
|
|
|
|
|
|
|
|
|
|
# The app list displays Sections but not Articles as the latter has
|
|
|
|
|
# ModelAdmin.has_module_permission() = False.
|
|
|
|
|
self.client.force_login(self.superuser)
|
|
|
|
|
response = self.client.get(reverse('admin7:app_list', args=('admin_views',)))
|
|
|
|
|
self.assertContains(response, sections)
|
|
|
|
|
self.assertNotContains(response, articles)
|
2014-05-28 16:07:27 +00:00
|
|
|
|
|
2015-09-07 09:51:03 +00:00
|
|
|
|
def test_post_save_message_no_forbidden_links_visible(self):
|
|
|
|
|
"""
|
|
|
|
|
Post-save message shouldn't contain a link to the change form if the
|
2018-08-01 16:55:53 +00:00
|
|
|
|
user doesn't have the change permission.
|
2015-09-07 09:51:03 +00:00
|
|
|
|
"""
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.adduser)
|
2015-09-07 09:51:03 +00:00
|
|
|
|
# Emulate Article creation for user with add-only permission.
|
|
|
|
|
post_data = {
|
|
|
|
|
"title": "Fun & games",
|
|
|
|
|
"content": "Some content",
|
|
|
|
|
"date_0": "2015-10-31",
|
|
|
|
|
"date_1": "16:35:00",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_article_add'), post_data, follow=True)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<li class="success">The article "Fun & games" was added successfully.</li>',
|
|
|
|
|
html=True
|
|
|
|
|
)
|
|
|
|
|
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-12-19 14:59:14 +00:00
|
|
|
|
class AdminViewsNoUrlTest(TestCase):
|
|
|
|
|
"""Regression test for #17333"""
|
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2011-12-19 14:59:14 +00:00
|
|
|
|
# User who can change Reports
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
|
|
|
|
|
cls.changeuser.user_permissions.add(get_perm(Report, get_permission_codename('change', Report._meta)))
|
2011-12-19 14:59:14 +00:00
|
|
|
|
|
|
|
|
|
def test_no_standard_modeladmin_urls(self):
|
|
|
|
|
"""Admin index views don't break when user's ModelAdmin removes standard urls"""
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.changeuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
r = self.client.get(reverse('admin:index'))
|
2015-01-20 14:54:12 +00:00
|
|
|
|
# we shouldn't get a 500 error caused by a NoReverseMatch
|
2011-12-19 14:59:14 +00:00
|
|
|
|
self.assertEqual(r.status_code, 200)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.get(reverse('admin:logout'))
|
2011-12-19 14:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
2014-06-11 15:45:18 +00:00
|
|
|
|
@skipUnlessDBFeature('can_defer_constraint_checks')
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2010-02-26 13:17:43 +00:00
|
|
|
|
class AdminViewDeletedObjectsTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
|
|
|
|
cls.deleteuser = User.objects.create_user(username='deleteuser', password='secret', is_staff=True)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
|
|
|
|
|
cls.v1 = Villain.objects.create(name='Adam')
|
|
|
|
|
cls.v2 = Villain.objects.create(name='Sue')
|
|
|
|
|
cls.sv1 = SuperVillain.objects.create(name='Bob')
|
|
|
|
|
cls.pl1 = Plot.objects.create(name='World Domination', team_leader=cls.v1, contact=cls.v2)
|
|
|
|
|
cls.pl2 = Plot.objects.create(name='World Peace', team_leader=cls.v2, contact=cls.v2)
|
|
|
|
|
cls.pl3 = Plot.objects.create(name='Corn Conspiracy', team_leader=cls.v1, contact=cls.v1)
|
|
|
|
|
cls.pd1 = PlotDetails.objects.create(details='almost finished', plot=cls.pl1)
|
|
|
|
|
cls.sh1 = SecretHideout.objects.create(location='underground bunker', villain=cls.v1)
|
|
|
|
|
cls.sh2 = SecretHideout.objects.create(location='floating castle', villain=cls.sv1)
|
|
|
|
|
cls.ssh1 = SuperSecretHideout.objects.create(location='super floating castle!', supervillain=cls.sv1)
|
|
|
|
|
cls.cy1 = CyclicOne.objects.create(name='I am recursive', two_id=1)
|
|
|
|
|
cls.cy2 = CyclicTwo.objects.create(name='I am recursive too', one_id=1)
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
|
|
|
|
def test_nesting(self):
|
|
|
|
|
"""
|
|
|
|
|
Objects should be nested to display the relationships that
|
|
|
|
|
cause them to be scheduled for deletion.
|
|
|
|
|
"""
|
2015-09-11 23:33:12 +00:00
|
|
|
|
pattern = re.compile(
|
2018-02-07 19:20:04 +00:00
|
|
|
|
r'<li>Plot: <a href="%s">World Domination</a>\s*<ul>\s*'
|
|
|
|
|
r'<li>Plot details: <a href="%s">almost finished</a>' % (
|
|
|
|
|
reverse('admin:admin_views_plot_change', args=(self.pl1.pk,)),
|
|
|
|
|
reverse('admin:admin_views_plotdetails_change', args=(self.pd1.pk,)),
|
2015-09-11 23:33:12 +00:00
|
|
|
|
)
|
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,)))
|
2018-02-07 19:20:04 +00:00
|
|
|
|
self.assertRegex(response.content.decode(), pattern)
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
|
|
|
|
def test_cyclic(self):
|
|
|
|
|
"""
|
|
|
|
|
Cyclic relationships should still cause each object to only be
|
|
|
|
|
listed once.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
one = '<li>Cyclic one: <a href="%s">I am recursive</a>' % (
|
2015-02-23 00:53:57 +00:00
|
|
|
|
reverse('admin:admin_views_cyclicone_change', args=(self.cy1.pk,)),
|
2015-02-06 22:25:15 +00:00
|
|
|
|
)
|
|
|
|
|
two = '<li>Cyclic two: <a href="%s">I am recursive too</a>' % (
|
2015-02-23 00:53:57 +00:00
|
|
|
|
reverse('admin:admin_views_cyclictwo_change', args=(self.cy2.pk,)),
|
2015-02-06 22:25:15 +00:00
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_cyclicone_delete', args=(self.cy1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
|
|
|
|
self.assertContains(response, one, 1)
|
|
|
|
|
self.assertContains(response, two, 1)
|
|
|
|
|
|
|
|
|
|
def test_perms_needed(self):
|
|
|
|
|
self.client.logout()
|
|
|
|
|
delete_user = User.objects.get(username='deleteuser')
|
2016-02-05 20:56:52 +00:00
|
|
|
|
delete_user.user_permissions.add(get_perm(Plot, get_permission_codename('delete', Plot._meta)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.deleteuser)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_plot_delete', args=(self.pl1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, "your account doesn't have permission to delete the following types of objects")
|
|
|
|
|
self.assertContains(response, "<li>plot details</li>")
|
|
|
|
|
|
2011-01-20 00:33:32 +00:00
|
|
|
|
def test_protected(self):
|
|
|
|
|
q = Question.objects.create(question="Why?")
|
|
|
|
|
a1 = Answer.objects.create(question=q, answer="Because.")
|
|
|
|
|
a2 = Answer.objects.create(question=q, answer="Yes.")
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_question_delete', args=(q.pk,)))
|
2011-01-20 00:33:32 +00:00
|
|
|
|
self.assertContains(response, "would require deleting the following protected related objects")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<li>Answer: <a href="%s">Because.</a></li>' % reverse('admin:admin_views_answer_change', args=(a1.pk,))
|
|
|
|
|
)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<li>Answer: <a href="%s">Yes.</a></li>' % reverse('admin:admin_views_answer_change', args=(a2.pk,))
|
|
|
|
|
)
|
2010-02-26 13:17:43 +00:00
|
|
|
|
|
2016-03-21 10:50:30 +00:00
|
|
|
|
def test_post_delete_protected(self):
|
|
|
|
|
"""
|
|
|
|
|
A POST request to delete protected objects should display the page
|
|
|
|
|
which says the deletion is prohibited.
|
|
|
|
|
"""
|
|
|
|
|
q = Question.objects.create(question='Why?')
|
2016-03-22 00:20:04 +00:00
|
|
|
|
Answer.objects.create(question=q, answer='Because.')
|
2016-03-21 10:50:30 +00:00
|
|
|
|
|
|
|
|
|
response = self.client.post(reverse('admin:admin_views_question_delete', args=(q.pk,)), {'post': 'yes'})
|
|
|
|
|
self.assertEqual(Question.objects.count(), 1)
|
|
|
|
|
self.assertContains(response, "would require deleting the following protected related objects")
|
|
|
|
|
|
2010-02-26 13:17:43 +00:00
|
|
|
|
def test_not_registered(self):
|
|
|
|
|
should_contain = """<li>Secret hideout: underground bunker"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, should_contain, 1)
|
|
|
|
|
|
|
|
|
|
def test_multiple_fkeys_to_same_model(self):
|
|
|
|
|
"""
|
|
|
|
|
If a deleted object has two relationships from another model,
|
|
|
|
|
both of those should be followed in looking for related
|
|
|
|
|
objects to delete.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
should_contain = '<li>Plot: <a href="%s">World Domination</a>' % reverse(
|
2015-02-23 00:53:57 +00:00
|
|
|
|
'admin:admin_views_plot_change', args=(self.pl1.pk,)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v2.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
|
|
|
|
|
|
|
|
|
def test_multiple_fkeys_to_same_instance(self):
|
|
|
|
|
"""
|
|
|
|
|
If a deleted object has two relationships pointing to it from
|
|
|
|
|
another object, the other object should still only be listed
|
|
|
|
|
once.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
should_contain = '<li>Plot: <a href="%s">World Peace</a></li>' % reverse(
|
2015-02-23 00:53:57 +00:00
|
|
|
|
'admin:admin_views_plot_change', args=(self.pl2.pk,)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v2.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, should_contain, 1)
|
|
|
|
|
|
|
|
|
|
def test_inheritance(self):
|
|
|
|
|
"""
|
|
|
|
|
In the case of an inherited model, if either the child or
|
|
|
|
|
parent-model instance is deleted, both instances are listed
|
|
|
|
|
for deletion, as well as any relationships they have.
|
|
|
|
|
"""
|
|
|
|
|
should_contain = [
|
2015-02-23 00:53:57 +00:00
|
|
|
|
'<li>Villain: <a href="%s">Bob</a>' % reverse('admin:admin_views_villain_change', args=(self.sv1.pk,)),
|
2015-09-11 23:33:12 +00:00
|
|
|
|
'<li>Super villain: <a href="%s">Bob</a>' % reverse(
|
|
|
|
|
'admin:admin_views_supervillain_change', args=(self.sv1.pk,)
|
|
|
|
|
),
|
2015-02-06 22:25:15 +00:00
|
|
|
|
'<li>Secret hideout: floating castle',
|
|
|
|
|
'<li>Super secret hideout: super floating castle!',
|
2013-10-18 09:02:43 +00:00
|
|
|
|
]
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.sv1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
for should in should_contain:
|
|
|
|
|
self.assertContains(response, should, 1)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_supervillain_delete', args=(self.sv1.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
for should in should_contain:
|
|
|
|
|
self.assertContains(response, should, 1)
|
|
|
|
|
|
|
|
|
|
def test_generic_relations(self):
|
|
|
|
|
"""
|
|
|
|
|
If a deleted object has GenericForeignKeys pointing to it,
|
|
|
|
|
those objects should be listed for deletion.
|
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
plot = self.pl3
|
2014-12-13 20:00:38 +00:00
|
|
|
|
tag = FunkyTag.objects.create(content_object=plot, name='hott')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
should_contain = '<li>Funky tag: <a href="%s">hott' % reverse(
|
|
|
|
|
'admin:admin_views_funkytag_change', args=(tag.id,))
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_plot_delete', args=(plot.pk,)))
|
2010-02-26 13:17:43 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
|
|
|
|
|
2015-08-27 20:13:24 +00:00
|
|
|
|
def test_generic_relations_with_related_query_name(self):
|
|
|
|
|
"""
|
|
|
|
|
If a deleted object has GenericForeignKey with
|
|
|
|
|
GenericRelation(related_query_name='...') pointing to it, those objects
|
|
|
|
|
should be listed for deletion.
|
|
|
|
|
"""
|
|
|
|
|
bookmark = Bookmark.objects.create(name='djangoproject')
|
|
|
|
|
tag = FunkyTag.objects.create(content_object=bookmark, name='django')
|
|
|
|
|
tag_url = reverse('admin:admin_views_funkytag_change', args=(tag.id,))
|
|
|
|
|
should_contain = '<li>Funky tag: <a href="%s">django' % tag_url
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_bookmark_delete', args=(bookmark.pk,)))
|
|
|
|
|
self.assertContains(response, should_contain)
|
|
|
|
|
|
2017-03-30 09:13:15 +00:00
|
|
|
|
def test_delete_view_uses_get_deleted_objects(self):
|
|
|
|
|
"""The delete view uses ModelAdmin.get_deleted_objects()."""
|
|
|
|
|
book = Book.objects.create(name='Test Book')
|
|
|
|
|
response = self.client.get(reverse('admin2:admin_views_book_delete', args=(book.pk,)))
|
|
|
|
|
# BookAdmin.get_deleted_objects() returns custom text.
|
|
|
|
|
self.assertContains(response, 'a deletable object')
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2014-07-14 11:23:34 +00:00
|
|
|
|
class TestGenericRelations(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.v1 = Villain.objects.create(name='Adam')
|
|
|
|
|
cls.pl3 = Plot.objects.create(name='Corn Conspiracy', team_leader=cls.v1, contact=cls.v1)
|
2014-07-14 11:23:34 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2014-07-14 11:23:34 +00:00
|
|
|
|
|
|
|
|
|
def test_generic_content_object_in_list_display(self):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
FunkyTag.objects.create(content_object=self.pl3, name='hott')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_funkytag_changelist'))
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertContains(response, "%s</td>" % self.pl3)
|
2014-07-14 11:23:34 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2008-07-18 23:54:34 +00:00
|
|
|
|
class AdminViewStringPrimaryKeyTest(TestCase):
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
2015-09-11 23:33:12 +00:00
|
|
|
|
cls.pk = (
|
|
|
|
|
"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 "
|
2016-09-16 16:15:00 +00:00
|
|
|
|
r"""-_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`"""
|
2015-09-11 23:33:12 +00:00
|
|
|
|
)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.m1 = ModelWithStringPrimaryKey.objects.create(string_pk=cls.pk)
|
|
|
|
|
content_type_pk = ContentType.objects.get_for_model(ModelWithStringPrimaryKey).pk
|
2015-11-24 13:22:05 +00:00
|
|
|
|
user_pk = cls.superuser.pk
|
|
|
|
|
LogEntry.objects.log_action(user_pk, content_type_pk, cls.pk, cls.pk, 2, change_message='Changed something')
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2009-12-10 19:58:20 +00:00
|
|
|
|
def test_get_history_view(self):
|
2012-07-02 01:40:50 +00:00
|
|
|
|
"""
|
|
|
|
|
Retrieving the history for an object using urlencoded form of primary
|
|
|
|
|
key should work.
|
|
|
|
|
Refs #12349, #18550.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_modelwithstringprimarykey_history', args=(self.pk,)))
|
2009-12-10 19:58:20 +00:00
|
|
|
|
self.assertContains(response, escape(self.pk))
|
2012-07-02 01:40:50 +00:00
|
|
|
|
self.assertContains(response, 'Changed something')
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2010-01-10 16:51:13 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def test_get_change_view(self):
|
|
|
|
|
"Retrieving the object using urlencoded form of primary key should work"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_modelwithstringprimarykey_change', args=(self.pk,)))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
self.assertContains(response, escape(self.pk))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def test_changelist_to_changeform_link(self):
|
2012-09-25 01:02:59 +00:00
|
|
|
|
"Link to the changeform of the object in changelist should use reverse() and be quoted -- #18072"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_modelwithstringprimarykey_changelist'))
|
2013-03-18 20:52:16 +00:00
|
|
|
|
# this URL now comes through reverse(), thus url quoting and iri_to_uri encoding
|
2014-06-26 14:55:36 +00:00
|
|
|
|
pk_final_url = escape(iri_to_uri(quote(self.pk)))
|
2015-02-06 22:25:15 +00:00
|
|
|
|
change_url = reverse(
|
|
|
|
|
'admin:admin_views_modelwithstringprimarykey_change', args=('__fk__',)
|
|
|
|
|
).replace('__fk__', pk_final_url)
|
|
|
|
|
should_contain = '<th class="field-__str__"><a href="%s">%s</a></th>' % (change_url, escape(self.pk))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def test_recentactions_link(self):
|
|
|
|
|
"The link from the recent actions list referring to the changeform of the object should be quoted"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2013-03-24 02:11:55 +00:00
|
|
|
|
link = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(self.pk),))
|
2014-06-26 14:55:36 +00:00
|
|
|
|
should_contain = """<a href="%s">%s</a>""" % (escape(link), escape(self.pk))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
2008-08-08 18:07:33 +00:00
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
def test_deleteconfirmation_link(self):
|
|
|
|
|
"The link from the delete confirmation page referring back to the changeform of the object should be quoted"
|
2015-09-11 23:33:12 +00:00
|
|
|
|
url = reverse('admin:admin_views_modelwithstringprimarykey_delete', args=(quote(self.pk),))
|
|
|
|
|
response = self.client.get(url)
|
2013-03-18 20:52:16 +00:00
|
|
|
|
# this URL now comes through reverse(), thus url quoting and iri_to_uri encoding
|
2015-02-06 22:25:15 +00:00
|
|
|
|
change_url = reverse(
|
|
|
|
|
'admin:admin_views_modelwithstringprimarykey_change', args=('__fk__',)
|
|
|
|
|
).replace('__fk__', escape(iri_to_uri(quote(self.pk))))
|
|
|
|
|
should_contain = '<a href="%s">%s</a>' % (change_url, escape(self.pk))
|
2008-07-18 23:54:34 +00:00
|
|
|
|
self.assertContains(response, should_contain)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2008-08-29 16:46:46 +00:00
|
|
|
|
def test_url_conflicts_with_add(self):
|
2015-02-07 16:55:47 +00:00
|
|
|
|
"A model with a primary key that ends with add or is `add` should be visible"
|
|
|
|
|
add_model = ModelWithStringPrimaryKey.objects.create(pk="i have something to add")
|
2008-08-29 16:46:46 +00:00
|
|
|
|
add_model.save()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(add_model.pk),))
|
|
|
|
|
)
|
2008-08-29 16:46:46 +00:00
|
|
|
|
should_contain = """<h1>Change model with string primary key</h1>"""
|
|
|
|
|
self.assertContains(response, should_contain)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2015-02-07 16:55:47 +00:00
|
|
|
|
add_model2 = ModelWithStringPrimaryKey.objects.create(pk="add")
|
|
|
|
|
add_url = reverse('admin:admin_views_modelwithstringprimarykey_add')
|
|
|
|
|
change_url = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(add_model2.pk),))
|
|
|
|
|
self.assertNotEqual(add_url, change_url)
|
|
|
|
|
|
2008-08-29 16:46:46 +00:00
|
|
|
|
def test_url_conflicts_with_delete(self):
|
|
|
|
|
"A model with a primary key that ends with delete should be visible"
|
2012-06-07 15:34:25 +00:00
|
|
|
|
delete_model = ModelWithStringPrimaryKey(pk="delete")
|
2008-08-29 16:46:46 +00:00
|
|
|
|
delete_model.save()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(delete_model.pk),))
|
|
|
|
|
)
|
2008-08-29 16:46:46 +00:00
|
|
|
|
should_contain = """<h1>Change model with string primary key</h1>"""
|
|
|
|
|
self.assertContains(response, should_contain)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2008-08-29 16:46:46 +00:00
|
|
|
|
def test_url_conflicts_with_history(self):
|
|
|
|
|
"A model with a primary key that ends with history should be visible"
|
2012-06-07 15:34:25 +00:00
|
|
|
|
history_model = ModelWithStringPrimaryKey(pk="history")
|
2008-08-29 16:46:46 +00:00
|
|
|
|
history_model.save()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(history_model.pk),))
|
|
|
|
|
)
|
2008-08-29 16:46:46 +00:00
|
|
|
|
should_contain = """<h1>Change model with string primary key</h1>"""
|
|
|
|
|
self.assertContains(response, should_contain)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2012-06-07 15:34:25 +00:00
|
|
|
|
def test_shortcut_view_with_escaping(self):
|
|
|
|
|
"'View on site should' work properly with char fields"
|
|
|
|
|
model = ModelWithStringPrimaryKey(pk='abc_123')
|
|
|
|
|
model.save()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(model.pk),))
|
|
|
|
|
)
|
2012-06-07 15:34:25 +00:00
|
|
|
|
should_contain = '/%s/" class="viewsitelink">' % model.pk
|
|
|
|
|
self.assertContains(response, should_contain)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2012-09-25 01:02:59 +00:00
|
|
|
|
def test_change_view_history_link(self):
|
|
|
|
|
"""Object history button link should work and contain the pk value quoted."""
|
2016-04-08 02:04:45 +00:00
|
|
|
|
url = reverse(
|
|
|
|
|
'admin:%s_modelwithstringprimarykey_change' % ModelWithStringPrimaryKey._meta.app_label,
|
|
|
|
|
args=(quote(self.pk),)
|
|
|
|
|
)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2016-04-08 02:04:45 +00:00
|
|
|
|
expected_link = reverse(
|
|
|
|
|
'admin:%s_modelwithstringprimarykey_history' % ModelWithStringPrimaryKey._meta.app_label,
|
|
|
|
|
args=(quote(self.pk),)
|
|
|
|
|
)
|
2015-06-15 10:17:09 +00:00
|
|
|
|
self.assertContains(response, '<a href="%s" class="historylink"' % escape(expected_link))
|
2012-09-25 01:02:59 +00:00
|
|
|
|
|
2014-05-16 15:56:25 +00:00
|
|
|
|
def test_redirect_on_add_view_continue_button(self):
|
|
|
|
|
"""As soon as an object is added using "Save and continue editing"
|
|
|
|
|
button, the user should be redirected to the object's change_view.
|
|
|
|
|
|
|
|
|
|
In case primary key is a string containing some special characters
|
|
|
|
|
like slash or underscore, these characters must be escaped (see #22266)
|
|
|
|
|
"""
|
|
|
|
|
response = self.client.post(
|
2015-02-06 22:25:15 +00:00
|
|
|
|
reverse('admin:admin_views_modelwithstringprimarykey_add'),
|
2014-05-16 15:56:25 +00:00
|
|
|
|
{
|
|
|
|
|
'string_pk': '123/history',
|
|
|
|
|
"_continue": "1", # Save and continue editing
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 302) # temporary redirect
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertIn('/123_2Fhistory/', response['location']) # PK is quoted
|
2014-05-16 15:56:25 +00:00
|
|
|
|
|
2008-08-09 17:35:19 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-02-24 13:34:51 +00:00
|
|
|
|
class SecureViewTests(TestCase):
|
2014-01-31 10:59:27 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Test behavior of a view protected by the staff_member_required decorator.
|
2014-01-31 10:59:27 +00:00
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
2008-08-09 17:35:19 +00:00
|
|
|
|
def test_secure_view_shows_login_if_not_logged_in(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
secure_url = reverse('secure_view')
|
2014-01-31 10:59:27 +00:00
|
|
|
|
response = self.client.get(secure_url)
|
|
|
|
|
self.assertRedirects(response, '%s?next=%s' % (reverse('admin:login'), secure_url))
|
|
|
|
|
response = self.client.get(secure_url, follow=True)
|
2011-02-24 13:34:51 +00:00
|
|
|
|
self.assertTemplateUsed(response, 'admin/login.html')
|
2014-01-31 10:59:27 +00:00
|
|
|
|
self.assertEqual(response.context[REDIRECT_FIELD_NAME], secure_url)
|
2011-02-24 13:34:51 +00:00
|
|
|
|
|
2015-02-06 21:45:46 +00:00
|
|
|
|
def test_staff_member_required_decorator_works_with_argument(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Staff_member_required decorator works with an argument
|
2015-02-06 21:45:46 +00:00
|
|
|
|
(redirect_field_name).
|
|
|
|
|
"""
|
|
|
|
|
secure_url = '/test_admin/admin/secure-view2/'
|
|
|
|
|
response = self.client.get(secure_url)
|
|
|
|
|
self.assertRedirects(response, '%s?myfield=%s' % (reverse('admin:login'), secure_url))
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2008-12-16 15:04:47 +00:00
|
|
|
|
class AdminViewUnicodeTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.b1 = Book.objects.create(name='Lærdommer')
|
|
|
|
|
cls.p1 = Promo.objects.create(name='<Promo for Lærdommer>', book=cls.b1)
|
|
|
|
|
cls.chap1 = Chapter.objects.create(
|
|
|
|
|
title='Norske bostaver æøå skaper problemer', content='<p>Svært frustrerende med UnicodeDecodeErro</p>',
|
|
|
|
|
book=cls.b1
|
|
|
|
|
)
|
|
|
|
|
cls.chap2 = Chapter.objects.create(
|
|
|
|
|
title='Kjærlighet', content='<p>La kjærligheten til de lidende seire.</p>', book=cls.b1)
|
|
|
|
|
cls.chap3 = Chapter.objects.create(title='Kjærlighet', content='<p>Noe innhold</p>', book=cls.b1)
|
|
|
|
|
cls.chap4 = ChapterXtra1.objects.create(chap=cls.chap1, xtra='<Xtra(1) Norske bostaver æøå skaper problemer>')
|
|
|
|
|
cls.chap5 = ChapterXtra1.objects.create(chap=cls.chap2, xtra='<Xtra(1) Kjærlighet>')
|
|
|
|
|
cls.chap6 = ChapterXtra1.objects.create(chap=cls.chap3, xtra='<Xtra(1) Kjærlighet>')
|
|
|
|
|
cls.chap7 = ChapterXtra2.objects.create(chap=cls.chap1, xtra='<Xtra(2) Norske bostaver æøå skaper problemer>')
|
|
|
|
|
cls.chap8 = ChapterXtra2.objects.create(chap=cls.chap2, xtra='<Xtra(2) Kjærlighet>')
|
|
|
|
|
cls.chap9 = ChapterXtra2.objects.create(chap=cls.chap3, xtra='<Xtra(2) Kjærlighet>')
|
2008-12-16 15:04:47 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2008-12-16 15:04:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_unicode_edit(self):
|
2008-12-16 15:04:47 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
A test to ensure that POST on edit_view handles non-ASCII characters.
|
2008-12-16 15:04:47 +00:00
|
|
|
|
"""
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Test lærdommer",
|
2008-12-16 15:04:47 +00:00
|
|
|
|
# inline data
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"chapter_set-TOTAL_FORMS": "6",
|
|
|
|
|
"chapter_set-INITIAL_FORMS": "3",
|
|
|
|
|
"chapter_set-MAX_NUM_FORMS": "0",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"chapter_set-0-id": self.chap1.pk,
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"chapter_set-0-title": "Norske bostaver æøå skaper problemer",
|
|
|
|
|
"chapter_set-0-content": "<p>Svært frustrerende med UnicodeDecodeError</p>",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"chapter_set-1-id": self.chap2.id,
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"chapter_set-1-title": "Kjærlighet.",
|
|
|
|
|
"chapter_set-1-content": "<p>La kjærligheten til de lidende seire.</p>",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"chapter_set-2-id": self.chap3.id,
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"chapter_set-2-title": "Need a title.",
|
|
|
|
|
"chapter_set-2-content": "<p>Newest content</p>",
|
|
|
|
|
"chapter_set-3-id": "",
|
|
|
|
|
"chapter_set-3-title": "",
|
|
|
|
|
"chapter_set-3-content": "",
|
|
|
|
|
"chapter_set-4-id": "",
|
|
|
|
|
"chapter_set-4-title": "",
|
|
|
|
|
"chapter_set-4-content": "",
|
|
|
|
|
"chapter_set-5-id": "",
|
|
|
|
|
"chapter_set-5-title": "",
|
|
|
|
|
"chapter_set-5-content": "",
|
2008-12-16 15:04:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_book_change', args=(self.b1.pk,)), post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2008-12-16 15:04:47 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_unicode_delete(self):
|
2008-12-16 15:04:47 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The delete_view handles non-ASCII characters
|
2008-12-16 15:04:47 +00:00
|
|
|
|
"""
|
|
|
|
|
delete_dict = {'post': 'yes'}
|
2015-02-23 00:53:57 +00:00
|
|
|
|
delete_url = reverse('admin:admin_views_book_delete', args=(self.b1.pk,))
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(delete_url)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(delete_url, delete_dict)
|
|
|
|
|
self.assertRedirects(response, reverse('admin:admin_views_book_changelist'))
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-03-17 20:51:47 +00:00
|
|
|
|
class AdminViewListEditable(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True)
|
|
|
|
|
cls.per2 = Person.objects.create(name='Grace Hopper', gender=1, alive=False)
|
|
|
|
|
cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
|
2009-03-29 18:52:38 +00:00
|
|
|
|
def test_inheritance(self):
|
2016-04-08 02:04:45 +00:00
|
|
|
|
Podcast.objects.create(name="This Week in Django", release_date=datetime.date.today())
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_podcast_changelist'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-03-29 18:52:38 +00:00
|
|
|
|
|
2009-04-18 21:03:29 +00:00
|
|
|
|
def test_inheritance_2(self):
|
|
|
|
|
Vodcast.objects.create(name="This Week in Django", released=True)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_vodcast_changelist'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-04-18 21:03:29 +00:00
|
|
|
|
|
2009-05-07 11:56:10 +00:00
|
|
|
|
def test_custom_pk(self):
|
|
|
|
|
Language.objects.create(iso='en', name='English', english_name='English')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_language_changelist'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-05-07 11:56:10 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
def test_changelist_input_html(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist'))
|
2009-03-17 20:51:47 +00:00
|
|
|
|
# 2 inputs per object(the field and the hidden id field) = 6
|
2013-05-24 06:02:07 +00:00
|
|
|
|
# 4 management hidden fields = 4
|
2009-03-23 20:22:56 +00:00
|
|
|
|
# 4 action inputs (3 regular checkboxes, 1 checkbox to select all)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
# main form submit button = 1
|
|
|
|
|
# search field and search submit button = 2
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-26 23:23:07 +00:00
|
|
|
|
# CSRF field = 1
|
2010-01-27 14:18:50 +00:00
|
|
|
|
# field to track 'select all' across paginated views = 1
|
2013-05-24 06:02:07 +00:00
|
|
|
|
# 6 + 4 + 4 + 1 + 2 + 1 + 1 = 19 inputs
|
|
|
|
|
self.assertContains(response, "<input", count=19)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
# 1 select per object = 3 selects
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertContains(response, "<select", count=4)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2010-02-23 14:48:15 +00:00
|
|
|
|
def test_post_messages(self):
|
|
|
|
|
# Ticket 12707: Saving inline editable should not show admin
|
|
|
|
|
# action warnings
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
|
|
|
|
"form-0-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per1.pk,
|
2010-02-23 14:48:15 +00:00
|
|
|
|
|
|
|
|
|
"form-1-gender": "2",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-1-id": "%s" % self.per2.pk,
|
2010-02-23 14:48:15 +00:00
|
|
|
|
|
|
|
|
|
"form-2-alive": "checked",
|
|
|
|
|
"form-2-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-2-id": "%s" % self.per3.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2010-02-23 14:48:15 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_person_changelist'),
|
2010-02-23 14:48:15 +00:00
|
|
|
|
data, follow=True)
|
|
|
|
|
self.assertEqual(len(response.context['messages']), 1)
|
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
def test_post_submission(self):
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
"form-0-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per1.pk,
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
"form-1-gender": "2",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-1-id": "%s" % self.per2.pk,
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
"form-2-alive": "checked",
|
|
|
|
|
"form-2-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-2-id": "%s" % self.per3.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2009-03-17 20:51:47 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_person_changelist'), data)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(Person.objects.get(name="John Mauchly").alive, False)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
# test a filtered page
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "2",
|
|
|
|
|
"form-INITIAL_FORMS": "2",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per1.pk,
|
2009-03-17 20:51:47 +00:00
|
|
|
|
"form-0-gender": "1",
|
|
|
|
|
"form-0-alive": "checked",
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-1-id": "%s" % self.per3.pk,
|
2009-03-17 20:51:47 +00:00
|
|
|
|
"form-1-gender": "1",
|
|
|
|
|
"form-1-alive": "checked",
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2009-03-17 20:51:47 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_person_changelist') + '?gender__exact=1', data)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(Person.objects.get(name="John Mauchly").alive, True)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2009-03-17 20:51:47 +00:00
|
|
|
|
# test a searched page
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "1",
|
|
|
|
|
"form-INITIAL_FORMS": "1",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per1.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
"form-0-gender": "1",
|
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2009-03-17 20:51:47 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_person_changelist') + '?q=john', data)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(Person.objects.get(name="John Mauchly").alive, False)
|
2009-03-17 20:51:47 +00:00
|
|
|
|
|
2011-02-19 11:48:42 +00:00
|
|
|
|
def test_non_field_errors(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""
|
|
|
|
|
Non-field errors are displayed for each of the forms in the
|
|
|
|
|
changelist's formset.
|
|
|
|
|
"""
|
2011-03-09 00:39:35 +00:00
|
|
|
|
fd1 = FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai')
|
|
|
|
|
fd2 = FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india')
|
|
|
|
|
fd3 = FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza')
|
2011-02-19 11:48:42 +00:00
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-0-id": str(fd1.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-0-reference": "123",
|
|
|
|
|
"form-0-driver": "bill",
|
|
|
|
|
"form-0-restaurant": "thai",
|
|
|
|
|
|
|
|
|
|
# Same data as above: Forbidden because of unique_together!
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-1-id": str(fd2.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-1-reference": "456",
|
|
|
|
|
"form-1-driver": "bill",
|
|
|
|
|
"form-1-restaurant": "thai",
|
|
|
|
|
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-2-id": str(fd3.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-2-reference": "789",
|
|
|
|
|
"form-2-driver": "bill",
|
|
|
|
|
"form-2-restaurant": "pizza",
|
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_fooddelivery_changelist'), data)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<tr><td colspan="4"><ul class="errorlist nonfield"><li>Food delivery '
|
|
|
|
|
'with this Driver and Restaurant already exists.</li></ul></td></tr>',
|
|
|
|
|
1,
|
|
|
|
|
html=True
|
|
|
|
|
)
|
2011-02-19 11:48:42 +00:00
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-0-id": str(fd1.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-0-reference": "123",
|
|
|
|
|
"form-0-driver": "bill",
|
|
|
|
|
"form-0-restaurant": "thai",
|
|
|
|
|
|
|
|
|
|
# Same data as above: Forbidden because of unique_together!
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-1-id": str(fd2.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-1-reference": "456",
|
|
|
|
|
"form-1-driver": "bill",
|
|
|
|
|
"form-1-restaurant": "thai",
|
|
|
|
|
|
|
|
|
|
# Same data also.
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"form-2-id": str(fd3.id),
|
2011-02-19 11:48:42 +00:00
|
|
|
|
"form-2-reference": "789",
|
|
|
|
|
"form-2-driver": "bill",
|
|
|
|
|
"form-2-restaurant": "thai",
|
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_fooddelivery_changelist'), data)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<tr><td colspan="4"><ul class="errorlist nonfield"><li>Food delivery '
|
|
|
|
|
'with this Driver and Restaurant already exists.</li></ul></td></tr>',
|
|
|
|
|
2,
|
|
|
|
|
html=True
|
|
|
|
|
)
|
2011-02-19 11:48:42 +00:00
|
|
|
|
|
2010-02-16 12:17:37 +00:00
|
|
|
|
def test_non_form_errors(self):
|
|
|
|
|
# test if non-form errors are handled; ticket #12716
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "1",
|
|
|
|
|
"form-INITIAL_FORMS": "1",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per2.pk,
|
2010-02-16 12:17:37 +00:00
|
|
|
|
"form-0-alive": "1",
|
|
|
|
|
"form-0-gender": "2",
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The form processing understands this as a list_editable "Save"
|
2010-05-02 23:02:16 +00:00
|
|
|
|
# and not an action "Go".
|
|
|
|
|
"_save": "Save",
|
2010-02-16 12:17:37 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_person_changelist'), data)
|
2010-02-16 12:17:37 +00:00
|
|
|
|
self.assertContains(response, "Grace is not a Zombie")
|
|
|
|
|
|
2010-02-23 20:55:42 +00:00
|
|
|
|
def test_non_form_errors_is_errorlist(self):
|
|
|
|
|
# test if non-form errors are correctly handled; ticket #12878
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "1",
|
|
|
|
|
"form-INITIAL_FORMS": "1",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per2.pk,
|
2010-02-23 20:55:42 +00:00
|
|
|
|
"form-0-alive": "1",
|
|
|
|
|
"form-0-gender": "2",
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2010-02-23 20:55:42 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_person_changelist'), data)
|
2010-02-23 20:55:42 +00:00
|
|
|
|
non_form_errors = response.context['cl'].formset.non_form_errors()
|
2013-05-21 09:42:15 +00:00
|
|
|
|
self.assertIsInstance(non_form_errors, ErrorList)
|
2010-02-23 20:55:42 +00:00
|
|
|
|
self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
|
|
|
|
|
|
2009-07-03 03:05:17 +00:00
|
|
|
|
def test_list_editable_ordering(self):
|
|
|
|
|
collector = Collector.objects.create(id=1, name="Frederick Clegg")
|
|
|
|
|
|
|
|
|
|
Category.objects.create(id=1, order=1, collector=collector)
|
|
|
|
|
Category.objects.create(id=2, order=2, collector=collector)
|
|
|
|
|
Category.objects.create(id=3, order=0, collector=collector)
|
|
|
|
|
Category.objects.create(id=4, order=0, collector=collector)
|
|
|
|
|
|
|
|
|
|
# NB: The order values must be changed so that the items are reordered.
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "4",
|
|
|
|
|
"form-INITIAL_FORMS": "4",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
|
|
|
|
"form-0-order": "14",
|
|
|
|
|
"form-0-id": "1",
|
|
|
|
|
"form-0-collector": "1",
|
|
|
|
|
|
|
|
|
|
"form-1-order": "13",
|
|
|
|
|
"form-1-id": "2",
|
|
|
|
|
"form-1-collector": "1",
|
|
|
|
|
|
|
|
|
|
"form-2-order": "1",
|
|
|
|
|
"form-2-id": "3",
|
|
|
|
|
"form-2-collector": "1",
|
|
|
|
|
|
|
|
|
|
"form-3-order": "0",
|
|
|
|
|
"form-3-id": "4",
|
|
|
|
|
"form-3-collector": "1",
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The form processing understands this as a list_editable "Save"
|
2010-05-02 23:02:16 +00:00
|
|
|
|
# and not an action "Go".
|
|
|
|
|
"_save": "Save",
|
2009-07-03 03:05:17 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_category_changelist'), data)
|
2009-07-03 03:05:17 +00:00
|
|
|
|
# Successful post will redirect
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The order values have been applied to the right objects
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(Category.objects.get(id=1).order, 14)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=2).order, 13)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=3).order, 1)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=4).order, 0)
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
2012-03-03 02:13:35 +00:00
|
|
|
|
def test_list_editable_pagination(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Pagination works for list_editable items.
|
2012-03-03 02:13:35 +00:00
|
|
|
|
"""
|
|
|
|
|
UnorderedObject.objects.create(id=1, name='Unordered object #1')
|
|
|
|
|
UnorderedObject.objects.create(id=2, name='Unordered object #2')
|
|
|
|
|
UnorderedObject.objects.create(id=3, name='Unordered object #3')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_unorderedobject_changelist'))
|
2012-04-09 04:28:32 +00:00
|
|
|
|
self.assertContains(response, 'Unordered object #3')
|
2012-03-03 02:13:35 +00:00
|
|
|
|
self.assertContains(response, 'Unordered object #2')
|
|
|
|
|
self.assertNotContains(response, 'Unordered object #1')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_unorderedobject_changelist') + '?p=1')
|
2012-04-09 04:28:32 +00:00
|
|
|
|
self.assertNotContains(response, 'Unordered object #3')
|
2012-03-03 02:13:35 +00:00
|
|
|
|
self.assertNotContains(response, 'Unordered object #2')
|
2012-04-09 04:28:32 +00:00
|
|
|
|
self.assertContains(response, 'Unordered object #1')
|
2012-03-03 02:13:35 +00:00
|
|
|
|
|
2010-05-02 23:02:16 +00:00
|
|
|
|
def test_list_editable_action_submit(self):
|
|
|
|
|
# List editable changes should not be executed if the action "Go" button is
|
|
|
|
|
# used to submit the form.
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
|
|
|
|
"form-0-gender": "1",
|
|
|
|
|
"form-0-id": "1",
|
|
|
|
|
|
|
|
|
|
"form-1-gender": "2",
|
|
|
|
|
"form-1-id": "2",
|
|
|
|
|
|
|
|
|
|
"form-2-alive": "checked",
|
|
|
|
|
"form-2-gender": "1",
|
|
|
|
|
"form-2-id": "3",
|
|
|
|
|
|
|
|
|
|
"index": "0",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"_selected_action": ['3'],
|
|
|
|
|
"action": ['', 'delete_selected'],
|
2010-05-02 23:02:16 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_person_changelist'), data)
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(Person.objects.get(name="John Mauchly").alive, True)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 1)
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
def test_list_editable_action_choices(self):
|
|
|
|
|
# List editable changes should be executed if the "Save" button is
|
|
|
|
|
# used to submit the form - any action choices should be ignored.
|
|
|
|
|
data = {
|
|
|
|
|
"form-TOTAL_FORMS": "3",
|
|
|
|
|
"form-INITIAL_FORMS": "3",
|
|
|
|
|
"form-MAX_NUM_FORMS": "0",
|
|
|
|
|
|
|
|
|
|
"form-0-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-0-id": "%s" % self.per1.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"form-1-gender": "2",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-1-id": "%s" % self.per2.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"form-2-alive": "checked",
|
|
|
|
|
"form-2-gender": "1",
|
2015-02-23 00:53:57 +00:00
|
|
|
|
"form-2-id": "%s" % self.per3.pk,
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
|
|
|
|
"_save": "Save",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"_selected_action": ['1'],
|
|
|
|
|
"action": ['', 'delete_selected'],
|
2010-05-02 23:02:16 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_person_changelist'), data)
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIs(Person.objects.get(name="John Mauchly").alive, False)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2)
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2011-01-02 01:32:40 +00:00
|
|
|
|
def test_list_editable_popup(self):
|
|
|
|
|
"""
|
|
|
|
|
Fields should not be list-editable in popups.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist'))
|
2011-01-02 01:32:40 +00:00
|
|
|
|
self.assertNotEqual(response.context['cl'].list_editable, ())
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist') + '?%s' % IS_POPUP_VAR)
|
2011-01-02 01:32:40 +00:00
|
|
|
|
self.assertEqual(response.context['cl'].list_editable, ())
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2011-03-03 13:20:45 +00:00
|
|
|
|
def test_pk_hidden_fields(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""
|
|
|
|
|
hidden pk fields aren't displayed in the table body and their
|
|
|
|
|
corresponding human-readable value is displayed instead. The hidden pk
|
|
|
|
|
fields are displayed but separately (not in the table) and only once.
|
2011-03-03 13:20:45 +00:00
|
|
|
|
"""
|
2011-03-09 00:39:35 +00:00
|
|
|
|
story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
|
2015-09-11 23:33:12 +00:00
|
|
|
|
story2 = Story.objects.create(
|
|
|
|
|
title='Crouching Tiger, Hidden Python',
|
|
|
|
|
content='The Python was sneaking into...',
|
|
|
|
|
)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_story_changelist'))
|
2015-09-11 23:33:12 +00:00
|
|
|
|
# Only one hidden field, in a separate place than the table.
|
|
|
|
|
self.assertContains(response, 'id="id_form-0-id"', 1)
|
2011-03-03 13:20:45 +00:00
|
|
|
|
self.assertContains(response, 'id="id_form-1-id"', 1)
|
2015-09-11 23:33:12 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<div class="hiddenfields">\n'
|
2018-01-21 07:09:10 +00:00
|
|
|
|
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
|
|
|
|
|
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n</div>'
|
2015-09-11 23:33:12 +00:00
|
|
|
|
% (story2.id, story1.id),
|
|
|
|
|
html=True
|
|
|
|
|
)
|
2013-07-28 02:50:02 +00:00
|
|
|
|
self.assertContains(response, '<td class="field-id">%d</td>' % story1.id, 1)
|
|
|
|
|
self.assertContains(response, '<td class="field-id">%d</td>' % story2.id, 1)
|
2011-03-03 13:20:45 +00:00
|
|
|
|
|
|
|
|
|
def test_pk_hidden_fields_with_list_display_links(self):
|
|
|
|
|
""" Similarly as test_pk_hidden_fields, but when the hidden pk fields are
|
|
|
|
|
referenced in list_display_links.
|
|
|
|
|
Refs #12475.
|
|
|
|
|
"""
|
2015-09-11 23:33:12 +00:00
|
|
|
|
story1 = OtherStory.objects.create(
|
|
|
|
|
title='The adventures of Guido',
|
|
|
|
|
content='Once upon a time in Djangoland...',
|
|
|
|
|
)
|
|
|
|
|
story2 = OtherStory.objects.create(
|
|
|
|
|
title='Crouching Tiger, Hidden Python',
|
|
|
|
|
content='The Python was sneaking into...',
|
|
|
|
|
)
|
2012-09-25 01:02:59 +00:00
|
|
|
|
link1 = reverse('admin:admin_views_otherstory_change', args=(story1.pk,))
|
|
|
|
|
link2 = reverse('admin:admin_views_otherstory_change', args=(story2.pk,))
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_otherstory_changelist'))
|
2015-09-11 23:33:12 +00:00
|
|
|
|
# Only one hidden field, in a separate place than the table.
|
|
|
|
|
self.assertContains(response, 'id="id_form-0-id"', 1)
|
2011-03-03 13:20:45 +00:00
|
|
|
|
self.assertContains(response, 'id="id_form-1-id"', 1)
|
2015-09-11 23:33:12 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<div class="hiddenfields">\n'
|
2018-01-21 07:09:10 +00:00
|
|
|
|
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
|
|
|
|
|
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n</div>'
|
2015-09-11 23:33:12 +00:00
|
|
|
|
% (story2.id, story1.id),
|
|
|
|
|
html=True
|
|
|
|
|
)
|
2013-07-28 02:50:02 +00:00
|
|
|
|
self.assertContains(response, '<th class="field-id"><a href="%s">%d</a></th>' % (link1, story1.id), 1)
|
|
|
|
|
self.assertContains(response, '<th class="field-id"><a href="%s">%d</a></th>' % (link2, story2.id), 1)
|
2011-03-03 13:20:45 +00:00
|
|
|
|
|
2010-05-02 23:02:16 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-05-07 12:52:43 +00:00
|
|
|
|
class AdminSearchTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
|
|
|
|
cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
|
|
|
|
|
cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True)
|
|
|
|
|
cls.per2 = Person.objects.create(name='Grace Hopper', gender=1, alive=False)
|
|
|
|
|
cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True)
|
|
|
|
|
|
|
|
|
|
cls.t1 = Recommender.objects.create()
|
2016-08-05 15:19:09 +00:00
|
|
|
|
cls.t2 = Recommendation.objects.create(the_recommender=cls.t1)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.t3 = Recommender.objects.create()
|
2016-08-05 15:19:09 +00:00
|
|
|
|
cls.t4 = Recommendation.objects.create(the_recommender=cls.t3)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
cls.tt1 = TitleTranslation.objects.create(title=cls.t1, text='Bar')
|
|
|
|
|
cls.tt2 = TitleTranslation.objects.create(title=cls.t2, text='Foo')
|
|
|
|
|
cls.tt3 = TitleTranslation.objects.create(title=cls.t3, text='Few')
|
|
|
|
|
cls.tt4 = TitleTranslation.objects.create(title=cls.t4, text='Bas')
|
2009-05-07 12:52:43 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-05-07 12:52:43 +00:00
|
|
|
|
|
|
|
|
|
def test_search_on_sibling_models(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"A search that mentions sibling models"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar')
|
2009-05-07 12:52:43 +00:00
|
|
|
|
# confirm the search returned 1 object
|
|
|
|
|
self.assertContains(response, "\n1 recommendation\n")
|
|
|
|
|
|
2011-02-26 12:44:25 +00:00
|
|
|
|
def test_with_fk_to_field(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The to_field GET parameter is preserved when a search is performed.
|
|
|
|
|
Refs #10918.
|
2011-02-26 12:44:25 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_user_changelist') + '?q=joe&%s=id' % TO_FIELD_VAR)
|
2011-02-26 12:44:25 +00:00
|
|
|
|
self.assertContains(response, "\n1 user\n")
|
2018-01-21 07:09:10 +00:00
|
|
|
|
self.assertContains(response, '<input type="hidden" name="%s" value="id">' % TO_FIELD_VAR, html=True)
|
2011-02-26 12:44:25 +00:00
|
|
|
|
|
2011-03-01 02:04:35 +00:00
|
|
|
|
def test_exact_matches(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar')
|
2011-03-01 02:04:35 +00:00
|
|
|
|
# confirm the search returned one object
|
|
|
|
|
self.assertContains(response, "\n1 recommendation\n")
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=ba')
|
2011-03-01 02:04:35 +00:00
|
|
|
|
# confirm the search returned zero objects
|
|
|
|
|
self.assertContains(response, "\n0 recommendations\n")
|
|
|
|
|
|
|
|
|
|
def test_beginning_matches(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist') + '?q=Gui')
|
2011-03-01 02:04:35 +00:00
|
|
|
|
# confirm the search returned one object
|
|
|
|
|
self.assertContains(response, "\n1 person\n")
|
|
|
|
|
self.assertContains(response, "Guido")
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist') + '?q=uido')
|
2011-03-01 02:04:35 +00:00
|
|
|
|
# confirm the search returned zero objects
|
|
|
|
|
self.assertContains(response, "\n0 persons\n")
|
|
|
|
|
self.assertNotContains(response, "Guido")
|
|
|
|
|
|
2013-05-19 08:52:29 +00:00
|
|
|
|
def test_pluggable_search(self):
|
2013-09-08 15:05:16 +00:00
|
|
|
|
PluggableSearchPerson.objects.create(name="Bob", age=10)
|
|
|
|
|
PluggableSearchPerson.objects.create(name="Amy", age=20)
|
2013-05-19 08:52:29 +00:00
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_pluggablesearchperson_changelist') + '?q=Bob')
|
2013-05-19 08:52:29 +00:00
|
|
|
|
# confirm the search returned one object
|
|
|
|
|
self.assertContains(response, "\n1 pluggable search person\n")
|
|
|
|
|
self.assertContains(response, "Bob")
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_pluggablesearchperson_changelist') + '?q=20')
|
2013-05-19 08:52:29 +00:00
|
|
|
|
# confirm the search returned one object
|
|
|
|
|
self.assertContains(response, "\n1 pluggable search person\n")
|
|
|
|
|
self.assertContains(response, "Amy")
|
|
|
|
|
|
2013-12-07 13:11:27 +00:00
|
|
|
|
def test_reset_link(self):
|
|
|
|
|
"""
|
|
|
|
|
Test presence of reset link in search bar ("1 result (_x total_)").
|
|
|
|
|
"""
|
2014-09-22 16:46:43 +00:00
|
|
|
|
# 1 query for session + 1 for fetching user
|
|
|
|
|
# + 1 for filtered result + 1 for filtered count
|
|
|
|
|
# + 1 for total count
|
|
|
|
|
with self.assertNumQueries(5):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_person_changelist') + '?q=Gui')
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2013-12-07 13:11:27 +00:00
|
|
|
|
"""<span class="small quiet">1 result (<a href="?">3 total</a>)</span>""",
|
2016-04-08 02:04:45 +00:00
|
|
|
|
html=True
|
|
|
|
|
)
|
2013-12-07 13:11:27 +00:00
|
|
|
|
|
2014-09-22 16:46:43 +00:00
|
|
|
|
def test_no_total_count(self):
|
|
|
|
|
"""
|
|
|
|
|
#8408 -- "Show all" should be displayed instead of the total count if
|
|
|
|
|
ModelAdmin.show_full_result_count is False.
|
|
|
|
|
"""
|
|
|
|
|
# 1 query for session + 1 for fetching user
|
|
|
|
|
# + 1 for filtered result + 1 for filtered count
|
|
|
|
|
with self.assertNumQueries(4):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar')
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2014-09-22 16:46:43 +00:00
|
|
|
|
"""<span class="small quiet">1 result (<a href="?">Show all</a>)</span>""",
|
2016-04-08 02:04:45 +00:00
|
|
|
|
html=True
|
|
|
|
|
)
|
2015-03-04 17:00:12 +00:00
|
|
|
|
self.assertTrue(response.context['cl'].show_admin_actions)
|
2014-09-22 16:46:43 +00:00
|
|
|
|
|
2011-02-26 12:44:25 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-03-10 11:19:26 +00:00
|
|
|
|
class AdminInheritedInlinesTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_inline(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""
|
|
|
|
|
Inline models which inherit from a common parent are correctly handled.
|
|
|
|
|
"""
|
2012-06-07 16:08:47 +00:00
|
|
|
|
foo_user = "foo username"
|
|
|
|
|
bar_user = "bar username"
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2012-08-14 12:36:11 +00:00
|
|
|
|
name_re = re.compile(b'name="(.*?)"')
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
# test the add case
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_persona_add'))
|
2009-03-10 11:19:26 +00:00
|
|
|
|
names = name_re.findall(response.content)
|
|
|
|
|
# make sure we have no duplicate HTML names
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(len(names), len(set(names)))
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
# test the add case
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Test Name",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
# inline data
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"accounts-TOTAL_FORMS": "1",
|
|
|
|
|
"accounts-INITIAL_FORMS": "0",
|
|
|
|
|
"accounts-MAX_NUM_FORMS": "0",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
"accounts-0-username": foo_user,
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"accounts-2-TOTAL_FORMS": "1",
|
|
|
|
|
"accounts-2-INITIAL_FORMS": "0",
|
|
|
|
|
"accounts-2-MAX_NUM_FORMS": "0",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
"accounts-2-0-username": bar_user,
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_persona_add'), post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(Persona.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FooAccount.objects.count(), 1)
|
|
|
|
|
self.assertEqual(BarAccount.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FooAccount.objects.all()[0].username, foo_user)
|
|
|
|
|
self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
|
|
|
|
|
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2011-03-09 00:39:35 +00:00
|
|
|
|
persona_id = Persona.objects.all()[0].id
|
|
|
|
|
foo_id = FooAccount.objects.all()[0].id
|
|
|
|
|
bar_id = BarAccount.objects.all()[0].id
|
|
|
|
|
|
2009-03-10 11:19:26 +00:00
|
|
|
|
# test the edit case
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_persona_change', args=(persona_id,)))
|
2009-03-10 11:19:26 +00:00
|
|
|
|
names = name_re.findall(response.content)
|
|
|
|
|
# make sure we have no duplicate HTML names
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(len(names), len(set(names)))
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Test Name",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
"accounts-TOTAL_FORMS": "2",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"accounts-INITIAL_FORMS": "1",
|
|
|
|
|
"accounts-MAX_NUM_FORMS": "0",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
"accounts-0-username": "%s-1" % foo_user,
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"accounts-0-account_ptr": str(foo_id),
|
|
|
|
|
"accounts-0-persona": str(persona_id),
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"accounts-2-TOTAL_FORMS": "2",
|
|
|
|
|
"accounts-2-INITIAL_FORMS": "1",
|
|
|
|
|
"accounts-2-MAX_NUM_FORMS": "0",
|
2009-03-10 11:19:26 +00:00
|
|
|
|
|
|
|
|
|
"accounts-2-0-username": "%s-1" % bar_user,
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"accounts-2-0-account_ptr": str(bar_id),
|
|
|
|
|
"accounts-2-0-persona": str(persona_id),
|
2009-03-10 11:19:26 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_persona_change', args=(persona_id,)), post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Persona.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FooAccount.objects.count(), 1)
|
|
|
|
|
self.assertEqual(BarAccount.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FooAccount.objects.all()[0].username, "%s-1" % foo_user)
|
|
|
|
|
self.assertEqual(BarAccount.objects.all()[0].username, "%s-1" % bar_user)
|
|
|
|
|
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
|
2009-03-23 20:22:56 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-12-18 10:08:05 +00:00
|
|
|
|
class TestCustomChangeList(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-12-18 10:08:05 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-12-18 10:08:05 +00:00
|
|
|
|
|
|
|
|
|
def test_custom_changelist(self):
|
|
|
|
|
"""
|
|
|
|
|
Validate that a custom ChangeList class can be used (#9749)
|
|
|
|
|
"""
|
|
|
|
|
# Insert some data
|
2012-06-07 16:08:47 +00:00
|
|
|
|
post_data = {"name": "First Gadget"}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_gadget_add'), post_data)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # redirect somewhere
|
2009-12-18 10:08:05 +00:00
|
|
|
|
# Hit the page once to get messages out of the queue message list
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_gadget_changelist'))
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# Data is still not visible on the page
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_gadget_changelist'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-12-18 10:08:05 +00:00
|
|
|
|
self.assertNotContains(response, 'First Gadget')
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-03-31 00:03:34 +00:00
|
|
|
|
class TestInlineNotEditable(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-03-31 00:03:34 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-03-31 00:03:34 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_GET_parent_add(self):
|
2009-03-31 00:03:34 +00:00
|
|
|
|
"""
|
|
|
|
|
InlineModelAdmin broken?
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_parent_add'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2009-04-01 03:11:58 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-04-01 03:11:58 +00:00
|
|
|
|
class AdminCustomQuerysetTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-04-01 03:11:58 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-04-01 03:11:58 +00:00
|
|
|
|
self.pks = [EmptyModel.objects.create().id for i in range(3)]
|
2013-09-06 20:28:48 +00:00
|
|
|
|
self.super_login = {
|
2015-02-06 22:25:15 +00:00
|
|
|
|
REDIRECT_FIELD_NAME: reverse('admin:index'),
|
2013-09-06 20:28:48 +00:00
|
|
|
|
'username': 'super',
|
|
|
|
|
'password': 'secret',
|
|
|
|
|
}
|
2009-04-01 03:11:58 +00:00
|
|
|
|
|
|
|
|
|
def test_changelist_view(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_emptymodel_changelist'))
|
2009-04-01 03:11:58 +00:00
|
|
|
|
for i in self.pks:
|
|
|
|
|
if i > 1:
|
|
|
|
|
self.assertContains(response, 'Primary key = %s' % i)
|
|
|
|
|
else:
|
|
|
|
|
self.assertNotContains(response, 'Primary key = %s' % i)
|
|
|
|
|
|
2013-02-24 12:18:21 +00:00
|
|
|
|
def test_changelist_view_count_queries(self):
|
2013-03-18 23:58:33 +00:00
|
|
|
|
# create 2 Person objects
|
2013-02-24 12:18:21 +00:00
|
|
|
|
Person.objects.create(name='person1', gender=1)
|
|
|
|
|
Person.objects.create(name='person2', gender=2)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
changelist_url = reverse('admin:admin_views_person_changelist')
|
2013-02-24 12:18:21 +00:00
|
|
|
|
|
2015-11-07 13:01:25 +00:00
|
|
|
|
# 5 queries are expected: 1 for the session, 1 for the user,
|
|
|
|
|
# 2 for the counts and 1 for the objects on the page
|
|
|
|
|
with self.assertNumQueries(5):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
resp = self.client.get(changelist_url)
|
2013-02-24 12:18:21 +00:00
|
|
|
|
self.assertEqual(resp.context['selection_note'], '0 of 2 selected')
|
|
|
|
|
self.assertEqual(resp.context['selection_note_all'], 'All 2 selected')
|
2013-12-07 13:11:27 +00:00
|
|
|
|
with self.assertNumQueries(5):
|
2013-02-24 12:18:21 +00:00
|
|
|
|
extra = {'q': 'not_in_name'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
resp = self.client.get(changelist_url, extra)
|
2013-02-24 12:18:21 +00:00
|
|
|
|
self.assertEqual(resp.context['selection_note'], '0 of 0 selected')
|
|
|
|
|
self.assertEqual(resp.context['selection_note_all'], 'All 0 selected')
|
2013-12-07 13:11:27 +00:00
|
|
|
|
with self.assertNumQueries(5):
|
2013-02-24 12:18:21 +00:00
|
|
|
|
extra = {'q': 'person'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
resp = self.client.get(changelist_url, extra)
|
2013-02-24 12:18:21 +00:00
|
|
|
|
self.assertEqual(resp.context['selection_note'], '0 of 2 selected')
|
|
|
|
|
self.assertEqual(resp.context['selection_note_all'], 'All 2 selected')
|
|
|
|
|
with self.assertNumQueries(5):
|
|
|
|
|
extra = {'gender__exact': '1'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
resp = self.client.get(changelist_url, extra)
|
2013-02-24 12:18:21 +00:00
|
|
|
|
self.assertEqual(resp.context['selection_note'], '0 of 1 selected')
|
|
|
|
|
self.assertEqual(resp.context['selection_note_all'], '1 selected')
|
|
|
|
|
|
2009-04-01 03:11:58 +00:00
|
|
|
|
def test_change_view(self):
|
|
|
|
|
for i in self.pks:
|
2016-11-05 13:56:03 +00:00
|
|
|
|
url = reverse('admin:admin_views_emptymodel_change', args=(i,))
|
|
|
|
|
response = self.client.get(url, follow=True)
|
2009-04-01 03:11:58 +00:00
|
|
|
|
if i > 1:
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
else:
|
2016-11-05 13:56:03 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:index'))
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[m.message for m in response.context['messages']],
|
2017-01-04 15:12:06 +00:00
|
|
|
|
["""empty model with ID "1" doesn't exist. Perhaps it was deleted?"""]
|
2016-11-05 13:56:03 +00:00
|
|
|
|
)
|
2009-04-18 20:29:55 +00:00
|
|
|
|
|
2012-12-24 19:17:16 +00:00
|
|
|
|
def test_add_model_modeladmin_defer_qs(self):
|
2013-03-08 14:15:23 +00:00
|
|
|
|
# Test for #14529. defer() is used in ModelAdmin.get_queryset()
|
2012-12-24 19:17:16 +00:00
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(CoverLetter.objects.count(), 0)
|
|
|
|
|
# Emulate model instance creation via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"author": "Candidate, Best",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_coverletter_add'), post_data, follow=True)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(CoverLetter.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name
|
2015-09-07 09:51:03 +00:00
|
|
|
|
pk = CoverLetter.objects.all()[0].pk
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The cover letter "<a href="%s">'
|
|
|
|
|
'Candidate, Best</a>" was added successfully.</li>' %
|
|
|
|
|
reverse('admin:admin_views_coverletter_change', args=(pk,)), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has no __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(ShortMessage.objects.count(), 0)
|
|
|
|
|
# Emulate model instance creation via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"content": "What's this SMS thing?",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_shortmessage_add'), post_data, follow=True)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(ShortMessage.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name
|
2017-06-09 16:36:09 +00:00
|
|
|
|
sm = ShortMessage.objects.all()[0]
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The short message "<a href="%s">'
|
2017-06-09 16:36:09 +00:00
|
|
|
|
'%s</a>" was added successfully.</li>' %
|
|
|
|
|
(reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)), sm), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
2011-02-20 23:09:25 +00:00
|
|
|
|
def test_add_model_modeladmin_only_qs(self):
|
2013-03-08 14:15:23 +00:00
|
|
|
|
# Test for #14529. only() is used in ModelAdmin.get_queryset()
|
2012-12-24 19:17:16 +00:00
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(Telegram.objects.count(), 0)
|
|
|
|
|
# Emulate model instance creation via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"title": "Urgent telegram",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_telegram_add'), post_data, follow=True)
|
2011-02-20 23:09:25 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(Telegram.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name
|
2015-09-07 09:51:03 +00:00
|
|
|
|
pk = Telegram.objects.all()[0].pk
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The telegram "<a href="%s">'
|
|
|
|
|
'Urgent telegram</a>" was added successfully.</li>' %
|
|
|
|
|
reverse('admin:admin_views_telegram_change', args=(pk,)), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has no __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(Paper.objects.count(), 0)
|
|
|
|
|
# Emulate model instance creation via the admin
|
2011-02-20 23:09:25 +00:00
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"title": "My Modified Paper Title",
|
2011-02-20 23:09:25 +00:00
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_paper_add'), post_data, follow=True)
|
2011-02-20 23:09:25 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(Paper.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name
|
2017-06-09 16:36:09 +00:00
|
|
|
|
p = Paper.objects.all()[0]
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The paper "<a href="%s">'
|
2017-06-09 16:36:09 +00:00
|
|
|
|
'%s</a>" was added successfully.</li>' %
|
|
|
|
|
(reverse('admin:admin_views_paper_change', args=(p.pk,)), p), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_edit_model_modeladmin_defer_qs(self):
|
2013-03-08 14:15:23 +00:00
|
|
|
|
# Test for #14529. defer() is used in ModelAdmin.get_queryset()
|
2011-02-20 23:09:25 +00:00
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has __str__ method
|
2012-06-07 16:08:47 +00:00
|
|
|
|
cl = CoverLetter.objects.create(author="John Doe")
|
2011-02-20 23:09:25 +00:00
|
|
|
|
self.assertEqual(CoverLetter.objects.count(), 1)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_coverletter_change', args=(cl.pk,)))
|
2011-02-20 23:09:25 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
# Emulate model instance edit via the admin
|
2011-02-20 23:09:25 +00:00
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"author": "John Doe II",
|
2011-02-20 23:09:25 +00:00
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
url = reverse('admin:admin_views_coverletter_change', args=(cl.pk,))
|
|
|
|
|
response = self.client.post(url, post_data, follow=True)
|
2011-02-20 23:09:25 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(CoverLetter.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name. Instance
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# representation is set by model's __str__()
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The cover letter "<a href="%s">'
|
|
|
|
|
'John Doe II</a>" was changed successfully.</li>' %
|
|
|
|
|
reverse('admin:admin_views_coverletter_change', args=(cl.pk,)), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has no __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
sm = ShortMessage.objects.create(content="This is expensive")
|
|
|
|
|
self.assertEqual(ShortMessage.objects.count(), 1)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)))
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
# Emulate model instance edit via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"content": "Too expensive",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
url = reverse('admin:admin_views_shortmessage_change', args=(sm.pk,))
|
|
|
|
|
response = self.client.post(url, post_data, follow=True)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(ShortMessage.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name. The ugly(!)
|
2016-12-29 15:27:49 +00:00
|
|
|
|
# instance representation is set by __str__().
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
2015-09-07 09:51:03 +00:00
|
|
|
|
response,
|
|
|
|
|
'<li class="success">The short message "<a href="%s">'
|
2017-06-09 16:36:09 +00:00
|
|
|
|
'%s</a>" was changed successfully.</li>' %
|
|
|
|
|
(reverse('admin:admin_views_shortmessage_change', args=(sm.pk,)), sm), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_edit_model_modeladmin_only_qs(self):
|
2013-03-08 14:15:23 +00:00
|
|
|
|
# Test for #14529. only() is used in ModelAdmin.get_queryset()
|
2012-12-24 19:17:16 +00:00
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has __str__ method
|
2018-08-01 16:55:53 +00:00
|
|
|
|
t = Telegram.objects.create(title="First Telegram")
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(Telegram.objects.count(), 1)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_telegram_change', args=(t.pk,)))
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
# Emulate model instance edit via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"title": "Telegram without typo",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_telegram_change', args=(t.pk,)), post_data, follow=True)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(Telegram.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name. The instance
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# representation is set by model's __str__()
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The telegram "<a href="%s">'
|
|
|
|
|
'Telegram without typo</a>" was changed successfully.</li>' %
|
|
|
|
|
reverse('admin:admin_views_telegram_change', args=(t.pk,)), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
|
|
|
|
|
2015-11-19 20:33:22 +00:00
|
|
|
|
# model has no __str__ method
|
2012-12-24 19:17:16 +00:00
|
|
|
|
p = Paper.objects.create(title="My Paper Title")
|
|
|
|
|
self.assertEqual(Paper.objects.count(), 1)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_paper_change', args=(p.pk,)))
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
# Emulate model instance edit via the admin
|
|
|
|
|
post_data = {
|
|
|
|
|
"title": "My Modified Paper Title",
|
|
|
|
|
"_save": "Save",
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_paper_change', args=(p.pk,)), post_data, follow=True)
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(Paper.objects.count(), 1)
|
|
|
|
|
# Message should contain non-ugly model verbose name. The ugly(!)
|
2016-12-29 15:27:49 +00:00
|
|
|
|
# instance representation is set by __str__().
|
2012-12-24 19:17:16 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2015-09-07 09:51:03 +00:00
|
|
|
|
'<li class="success">The paper "<a href="%s">'
|
2017-06-09 16:36:09 +00:00
|
|
|
|
'%s</a>" was changed successfully.</li>' %
|
|
|
|
|
(reverse('admin:admin_views_paper_change', args=(p.pk,)), p), html=True
|
2012-12-24 19:17:16 +00:00
|
|
|
|
)
|
2011-02-20 23:09:25 +00:00
|
|
|
|
|
2013-09-06 20:28:48 +00:00
|
|
|
|
def test_history_view_custom_qs(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Custom querysets are considered for the admin history view.
|
2013-09-06 20:28:48 +00:00
|
|
|
|
"""
|
2014-01-31 14:18:55 +00:00
|
|
|
|
self.client.post(reverse('admin:login'), self.super_login)
|
2013-09-06 20:28:48 +00:00
|
|
|
|
FilteredManager.objects.create(pk=1)
|
|
|
|
|
FilteredManager.objects.create(pk=2)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_filteredmanager_changelist'))
|
2013-09-06 20:28:48 +00:00
|
|
|
|
self.assertContains(response, "PK=1")
|
|
|
|
|
self.assertContains(response, "PK=2")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.client.get(reverse('admin:admin_views_filteredmanager_history', args=(1,))).status_code, 200
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.client.get(reverse('admin:admin_views_filteredmanager_history', args=(2,))).status_code, 200
|
|
|
|
|
)
|
2013-09-06 20:28:48 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-04-18 20:29:55 +00:00
|
|
|
|
class AdminInlineFileUploadTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-04-18 20:29:55 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-05-05 11:52:03 +00:00
|
|
|
|
|
2009-04-18 20:29:55 +00:00
|
|
|
|
# Set up test Picture and Gallery.
|
|
|
|
|
# These must be set up here instead of in fixtures in order to allow Picture
|
|
|
|
|
# to use a NamedTemporaryFile.
|
2015-02-21 18:18:54 +00:00
|
|
|
|
file1 = tempfile.NamedTemporaryFile(suffix=".file1")
|
2012-08-14 12:36:11 +00:00
|
|
|
|
file1.write(b'a' * (2 ** 21))
|
2009-04-18 20:29:55 +00:00
|
|
|
|
filename = file1.name
|
|
|
|
|
file1.close()
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.gallery = Gallery(name="Test Gallery")
|
|
|
|
|
self.gallery.save()
|
|
|
|
|
self.picture = Picture(name="Test Picture", image=filename, gallery=self.gallery)
|
|
|
|
|
self.picture.save()
|
2009-04-18 20:29:55 +00:00
|
|
|
|
|
2017-11-08 00:06:32 +00:00
|
|
|
|
def test_form_has_multipart_enctype(self):
|
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_gallery_change', args=(self.gallery.id,))
|
|
|
|
|
)
|
|
|
|
|
self.assertIs(response.context['has_file_field'], True)
|
|
|
|
|
self.assertContains(response, MULTIPART_ENCTYPE)
|
|
|
|
|
|
2009-04-18 20:29:55 +00:00
|
|
|
|
def test_inline_file_upload_edit_validation_error_post(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Inline file uploads correctly display prior data (#10002).
|
2009-04-18 20:29:55 +00:00
|
|
|
|
"""
|
|
|
|
|
post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Test Gallery",
|
|
|
|
|
"pictures-TOTAL_FORMS": "2",
|
|
|
|
|
"pictures-INITIAL_FORMS": "1",
|
|
|
|
|
"pictures-MAX_NUM_FORMS": "0",
|
2016-12-29 15:27:49 +00:00
|
|
|
|
"pictures-0-id": str(self.picture.id),
|
|
|
|
|
"pictures-0-gallery": str(self.gallery.id),
|
2009-04-18 20:29:55 +00:00
|
|
|
|
"pictures-0-name": "Test Picture",
|
|
|
|
|
"pictures-0-image": "",
|
|
|
|
|
"pictures-1-id": "",
|
2011-03-09 00:39:35 +00:00
|
|
|
|
"pictures-1-gallery": str(self.gallery.id),
|
2009-04-18 20:29:55 +00:00
|
|
|
|
"pictures-1-name": "Test Picture 2",
|
|
|
|
|
"pictures-1-image": "",
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(
|
|
|
|
|
reverse('admin:admin_views_gallery_change', args=(self.gallery.id,)), post_data
|
|
|
|
|
)
|
2013-11-23 18:50:20 +00:00
|
|
|
|
self.assertContains(response, b"Currently")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-05-09 11:40:13 +00:00
|
|
|
|
class AdminInlineTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.post_data = {
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"name": "Test Name",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
"widget_set-TOTAL_FORMS": "3",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"widget_set-INITIAL_FORMS": "0",
|
|
|
|
|
"widget_set-MAX_NUM_FORMS": "0",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
"widget_set-0-id": "",
|
|
|
|
|
"widget_set-0-owner": "1",
|
|
|
|
|
"widget_set-0-name": "",
|
|
|
|
|
"widget_set-1-id": "",
|
|
|
|
|
"widget_set-1-owner": "1",
|
|
|
|
|
"widget_set-1-name": "",
|
|
|
|
|
"widget_set-2-id": "",
|
|
|
|
|
"widget_set-2-owner": "1",
|
|
|
|
|
"widget_set-2-name": "",
|
|
|
|
|
|
|
|
|
|
"doohickey_set-TOTAL_FORMS": "3",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"doohickey_set-INITIAL_FORMS": "0",
|
|
|
|
|
"doohickey_set-MAX_NUM_FORMS": "0",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
"doohickey_set-0-owner": "1",
|
|
|
|
|
"doohickey_set-0-code": "",
|
|
|
|
|
"doohickey_set-0-name": "",
|
|
|
|
|
"doohickey_set-1-owner": "1",
|
|
|
|
|
"doohickey_set-1-code": "",
|
|
|
|
|
"doohickey_set-1-name": "",
|
|
|
|
|
"doohickey_set-2-owner": "1",
|
|
|
|
|
"doohickey_set-2-code": "",
|
|
|
|
|
"doohickey_set-2-name": "",
|
|
|
|
|
|
|
|
|
|
"grommet_set-TOTAL_FORMS": "3",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"grommet_set-INITIAL_FORMS": "0",
|
|
|
|
|
"grommet_set-MAX_NUM_FORMS": "0",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
"grommet_set-0-code": "",
|
|
|
|
|
"grommet_set-0-owner": "1",
|
|
|
|
|
"grommet_set-0-name": "",
|
|
|
|
|
"grommet_set-1-code": "",
|
|
|
|
|
"grommet_set-1-owner": "1",
|
|
|
|
|
"grommet_set-1-name": "",
|
|
|
|
|
"grommet_set-2-code": "",
|
|
|
|
|
"grommet_set-2-owner": "1",
|
|
|
|
|
"grommet_set-2-name": "",
|
|
|
|
|
|
|
|
|
|
"whatsit_set-TOTAL_FORMS": "3",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"whatsit_set-INITIAL_FORMS": "0",
|
|
|
|
|
"whatsit_set-MAX_NUM_FORMS": "0",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
"whatsit_set-0-owner": "1",
|
|
|
|
|
"whatsit_set-0-index": "",
|
|
|
|
|
"whatsit_set-0-name": "",
|
|
|
|
|
"whatsit_set-1-owner": "1",
|
|
|
|
|
"whatsit_set-1-index": "",
|
|
|
|
|
"whatsit_set-1-name": "",
|
|
|
|
|
"whatsit_set-2-owner": "1",
|
|
|
|
|
"whatsit_set-2-index": "",
|
|
|
|
|
"whatsit_set-2-name": "",
|
|
|
|
|
|
|
|
|
|
"fancydoodad_set-TOTAL_FORMS": "3",
|
2012-06-07 16:08:47 +00:00
|
|
|
|
"fancydoodad_set-INITIAL_FORMS": "0",
|
|
|
|
|
"fancydoodad_set-MAX_NUM_FORMS": "0",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
"fancydoodad_set-0-doodad_ptr": "",
|
|
|
|
|
"fancydoodad_set-0-owner": "1",
|
|
|
|
|
"fancydoodad_set-0-name": "",
|
|
|
|
|
"fancydoodad_set-0-expensive": "on",
|
|
|
|
|
"fancydoodad_set-1-doodad_ptr": "",
|
|
|
|
|
"fancydoodad_set-1-owner": "1",
|
|
|
|
|
"fancydoodad_set-1-name": "",
|
|
|
|
|
"fancydoodad_set-1-expensive": "on",
|
|
|
|
|
"fancydoodad_set-2-doodad_ptr": "",
|
|
|
|
|
"fancydoodad_set-2-owner": "1",
|
|
|
|
|
"fancydoodad_set-2-name": "",
|
|
|
|
|
"fancydoodad_set-2-expensive": "on",
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
|
|
|
|
"category_set-TOTAL_FORMS": "3",
|
|
|
|
|
"category_set-INITIAL_FORMS": "0",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"category_set-MAX_NUM_FORMS": "0",
|
2009-07-03 03:05:17 +00:00
|
|
|
|
"category_set-0-order": "",
|
|
|
|
|
"category_set-0-id": "",
|
|
|
|
|
"category_set-0-collector": "1",
|
|
|
|
|
"category_set-1-order": "",
|
|
|
|
|
"category_set-1-id": "",
|
|
|
|
|
"category_set-1-collector": "1",
|
|
|
|
|
"category_set-2-order": "",
|
|
|
|
|
"category_set-2-id": "",
|
|
|
|
|
"category_set-2-collector": "1",
|
2009-05-09 11:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.collector = Collector(pk=1, name='John Fowles')
|
2009-07-03 03:05:17 +00:00
|
|
|
|
self.collector.save()
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
def test_simple_inline(self):
|
|
|
|
|
"A simple model can be saved as inlines"
|
|
|
|
|
# First add a new inline
|
|
|
|
|
self.post_data['widget_set-0-name'] = "Widget 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
|
2011-03-09 00:39:35 +00:00
|
|
|
|
widget_id = Widget.objects.all()[0].id
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The PK link exists on the rendered form
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.get(collector_url)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.assertContains(response, 'name="widget_set-0-id"')
|
|
|
|
|
|
2017-11-08 00:06:32 +00:00
|
|
|
|
# No file or image fields, no enctype on the forms
|
|
|
|
|
self.assertIs(response.context['has_file_field'], False)
|
|
|
|
|
self.assertNotContains(response, MULTIPART_ENCTYPE)
|
|
|
|
|
|
2009-05-09 11:40:13 +00:00
|
|
|
|
# Now resave that inline
|
|
|
|
|
self.post_data['widget_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['widget_set-0-id'] = str(widget_id)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['widget_set-0-name'] = "Widget 1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
# Now modify that inline
|
|
|
|
|
self.post_data['widget_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['widget_set-0-id'] = str(widget_id)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['widget_set-0-name'] = "Widget 1 Updated"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.all()[0].name, "Widget 1 Updated")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2018-05-02 08:39:12 +00:00
|
|
|
|
def test_simple_inline_permissions(self):
|
|
|
|
|
"""
|
|
|
|
|
Changes aren't allowed without change permissions for the inline object.
|
|
|
|
|
"""
|
|
|
|
|
# User who can view Articles
|
|
|
|
|
permissionuser = User.objects.create_user(
|
|
|
|
|
username='permissionuser', password='secret',
|
|
|
|
|
email='vuser@example.com', is_staff=True,
|
|
|
|
|
)
|
|
|
|
|
permissionuser.user_permissions.add(get_perm(Collector, get_permission_codename('view', Collector._meta)))
|
|
|
|
|
permissionuser.user_permissions.add(get_perm(Widget, get_permission_codename('view', Widget._meta)))
|
|
|
|
|
self.client.force_login(permissionuser)
|
|
|
|
|
# Without add permission, a new inline can't be added.
|
|
|
|
|
self.post_data['widget_set-0-name'] = 'Widget 1'
|
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 0)
|
|
|
|
|
# But after adding the permisson it can.
|
|
|
|
|
permissionuser.user_permissions.add(get_perm(Widget, get_permission_codename('add', Widget._meta)))
|
|
|
|
|
self.post_data['widget_set-0-name'] = "Widget 1"
|
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.first().name, 'Widget 1')
|
|
|
|
|
widget_id = Widget.objects.first().id
|
|
|
|
|
# Without the change permission, a POST doesn't change the object.
|
|
|
|
|
self.post_data['widget_set-INITIAL_FORMS'] = '1'
|
|
|
|
|
self.post_data['widget_set-0-id'] = str(widget_id)
|
|
|
|
|
self.post_data['widget_set-0-name'] = 'Widget 1 Updated'
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.first().name, 'Widget 1')
|
|
|
|
|
# Now adding the change permission and editing works.
|
|
|
|
|
permissionuser.user_permissions.remove(get_perm(Widget, get_permission_codename('add', Widget._meta)))
|
|
|
|
|
permissionuser.user_permissions.add(get_perm(Widget, get_permission_codename('change', Widget._meta)))
|
|
|
|
|
self.post_data['widget_set-INITIAL_FORMS'] = '1'
|
|
|
|
|
self.post_data['widget_set-0-id'] = str(widget_id)
|
|
|
|
|
self.post_data['widget_set-0-name'] = 'Widget 1 Updated'
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Widget.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Widget.objects.first().name, 'Widget 1 Updated')
|
|
|
|
|
|
2009-05-09 11:40:13 +00:00
|
|
|
|
def test_explicit_autofield_inline(self):
|
|
|
|
|
"A model with an explicit autofield primary key can be saved as inlines. Regression for #8093"
|
|
|
|
|
# First add a new inline
|
|
|
|
|
self.post_data['grommet_set-0-name'] = "Grommet 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Grommet.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The PK link exists on the rendered form
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.get(collector_url)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.assertContains(response, 'name="grommet_set-0-code"')
|
|
|
|
|
|
|
|
|
|
# Now resave that inline
|
|
|
|
|
self.post_data['grommet_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['grommet_set-0-name'] = "Grommet 1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Grommet.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
# Now modify that inline
|
|
|
|
|
self.post_data['grommet_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['grommet_set-0-name'] = "Grommet 1 Updated"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Grommet.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
def test_char_pk_inline(self):
|
|
|
|
|
"A model with a character PK can be saved as inlines. Regression for #10992"
|
|
|
|
|
# First add a new inline
|
|
|
|
|
self.post_data['doohickey_set-0-code'] = "DH1"
|
|
|
|
|
self.post_data['doohickey_set-0-name'] = "Doohickey 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(DooHickey.objects.count(), 1)
|
|
|
|
|
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The PK link exists on the rendered form
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.get(collector_url)
|
2009-05-14 02:23:53 +00:00
|
|
|
|
self.assertContains(response, 'name="doohickey_set-0-code"')
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
# Now resave that inline
|
|
|
|
|
self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
|
|
|
|
|
self.post_data['doohickey_set-0-code'] = "DH1"
|
|
|
|
|
self.post_data['doohickey_set-0-name'] = "Doohickey 1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(DooHickey.objects.count(), 1)
|
|
|
|
|
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
# Now modify that inline
|
|
|
|
|
self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
|
|
|
|
|
self.post_data['doohickey_set-0-code'] = "DH1"
|
|
|
|
|
self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(DooHickey.objects.count(), 1)
|
|
|
|
|
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
def test_integer_pk_inline(self):
|
|
|
|
|
"A model with an integer PK can be saved as inlines. Regression for #10992"
|
|
|
|
|
# First add a new inline
|
|
|
|
|
self.post_data['whatsit_set-0-index'] = "42"
|
|
|
|
|
self.post_data['whatsit_set-0-name'] = "Whatsit 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Whatsit.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The PK link exists on the rendered form
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(collector_url)
|
2009-05-14 02:23:53 +00:00
|
|
|
|
self.assertContains(response, 'name="whatsit_set-0-index"')
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
# Now resave that inline
|
|
|
|
|
self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
|
|
|
|
|
self.post_data['whatsit_set-0-index'] = "42"
|
|
|
|
|
self.post_data['whatsit_set-0-name'] = "Whatsit 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Whatsit.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
|
2009-05-15 15:01:40 +00:00
|
|
|
|
|
2009-05-14 02:23:53 +00:00
|
|
|
|
# Now modify that inline
|
|
|
|
|
self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
|
|
|
|
|
self.post_data['whatsit_set-0-index'] = "42"
|
|
|
|
|
self.post_data['whatsit_set-0-name'] = "Whatsit 1 Updated"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Whatsit.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1 Updated")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
def test_inherited_inline(self):
|
|
|
|
|
"An inherited model can be saved as inlines. Regression for #11042"
|
|
|
|
|
# First add a new inline
|
|
|
|
|
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
|
2011-03-09 00:39:35 +00:00
|
|
|
|
doodad_pk = FancyDoodad.objects.all()[0].pk
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The PK link exists on the rendered form
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.get(collector_url)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.assertContains(response, 'name="fancydoodad_set-0-doodad_ptr"')
|
|
|
|
|
|
|
|
|
|
# Now resave that inline
|
|
|
|
|
self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
|
2009-05-09 11:40:13 +00:00
|
|
|
|
|
|
|
|
|
# Now modify that inline
|
|
|
|
|
self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
|
2009-05-09 11:40:13 +00:00
|
|
|
|
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1 Updated"
|
2011-03-09 00:39:35 +00:00
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.count(), 1)
|
|
|
|
|
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
|
|
|
|
def test_ordered_inline(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""
|
|
|
|
|
An inline with an editable ordering fields is updated correctly.
|
|
|
|
|
"""
|
2009-07-03 03:05:17 +00:00
|
|
|
|
# Create some objects with an initial ordering
|
|
|
|
|
Category.objects.create(id=1, order=1, collector=self.collector)
|
|
|
|
|
Category.objects.create(id=2, order=2, collector=self.collector)
|
|
|
|
|
Category.objects.create(id=3, order=0, collector=self.collector)
|
|
|
|
|
Category.objects.create(id=4, order=0, collector=self.collector)
|
|
|
|
|
|
|
|
|
|
# NB: The order values must be changed so that the items are reordered.
|
|
|
|
|
self.post_data.update({
|
|
|
|
|
"name": "Frederick Clegg",
|
|
|
|
|
|
|
|
|
|
"category_set-TOTAL_FORMS": "7",
|
|
|
|
|
"category_set-INITIAL_FORMS": "4",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"category_set-MAX_NUM_FORMS": "0",
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
|
|
|
|
"category_set-0-order": "14",
|
|
|
|
|
"category_set-0-id": "1",
|
|
|
|
|
"category_set-0-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-1-order": "13",
|
|
|
|
|
"category_set-1-id": "2",
|
|
|
|
|
"category_set-1-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-2-order": "1",
|
|
|
|
|
"category_set-2-id": "3",
|
|
|
|
|
"category_set-2-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-3-order": "0",
|
|
|
|
|
"category_set-3-id": "4",
|
|
|
|
|
"category_set-3-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-4-order": "",
|
|
|
|
|
"category_set-4-id": "",
|
|
|
|
|
"category_set-4-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-5-order": "",
|
|
|
|
|
"category_set-5-id": "",
|
|
|
|
|
"category_set-5-collector": "1",
|
|
|
|
|
|
|
|
|
|
"category_set-6-order": "",
|
|
|
|
|
"category_set-6-id": "",
|
|
|
|
|
"category_set-6-collector": "1",
|
|
|
|
|
})
|
2015-02-06 22:25:15 +00:00
|
|
|
|
collector_url = reverse('admin:admin_views_collector_change', args=(self.collector.pk,))
|
|
|
|
|
response = self.client.post(collector_url, self.post_data)
|
2009-07-03 03:05:17 +00:00
|
|
|
|
# Successful post will redirect
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
2009-07-03 03:05:17 +00:00
|
|
|
|
|
2016-10-27 07:53:39 +00:00
|
|
|
|
# The order values have been applied to the right objects
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(self.collector.category_set.count(), 4)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=1).order, 14)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=2).order, 13)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=3).order, 1)
|
|
|
|
|
self.assertEqual(Category.objects.get(id=4).order, 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2009-07-13 13:46:31 +00:00
|
|
|
|
class NeverCacheTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_admin_index(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of the main index"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_index(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of an application index"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_model_index(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of a model index"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_fabric_changelist'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_model_add(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of a model add page"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_fabric_add'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_model_view(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of a model edit page"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_change', args=(self.s1.pk,)))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_model_history(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of a model history page"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_history', args=(self.s1.pk,)))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_model_delete(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of a model delete page"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_delete', args=(self.s1.pk,)))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_login(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of login views"
|
|
|
|
|
self.client.logout()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_logout(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of logout view"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:logout'))
|
2010-12-04 07:28:12 +00:00
|
|
|
|
self.assertEqual(get_max_age(response), 0)
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_password_change(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of the password change view"
|
|
|
|
|
self.client.logout()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:password_change'))
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIsNone(get_max_age(response))
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_password_change_done(self):
|
2009-07-13 13:46:31 +00:00
|
|
|
|
"Check the never-cache status of the password change done view"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:password_change_done'))
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIsNone(get_max_age(response))
|
2009-07-13 13:46:31 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_JS_i18n(self):
|
2012-03-02 17:16:52 +00:00
|
|
|
|
"Check the never-cache status of the JavaScript i18n view"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:jsi18n'))
|
2016-06-16 18:19:18 +00:00
|
|
|
|
self.assertIsNone(get_max_age(response))
|
2009-12-22 18:29:00 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-04-22 12:02:25 +00:00
|
|
|
|
class PrePopulatedTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
2011-04-22 12:02:25 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-04-22 12:02:25 +00:00
|
|
|
|
|
|
|
|
|
def test_prepopulated_on(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_prepopulatedpost_add'))
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, ""id": "#id_slug"")
|
|
|
|
|
self.assertContains(response, ""dependency_ids": ["#id_title"]")
|
|
|
|
|
self.assertContains(response, ""id": "#id_prepopulatedsubpost_set-0-subslug"")
|
2011-04-22 12:02:25 +00:00
|
|
|
|
|
|
|
|
|
def test_prepopulated_off(self):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_prepopulatedpost_change', args=(self.p1.pk,)))
|
2011-04-22 12:02:25 +00:00
|
|
|
|
self.assertContains(response, "A Long Title")
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertNotContains(response, ""id": "#id_slug"")
|
|
|
|
|
self.assertNotContains(response, ""dependency_ids": ["#id_title"]")
|
|
|
|
|
self.assertNotContains(
|
|
|
|
|
response,
|
|
|
|
|
""id": "#id_prepopulatedsubpost_set-0-subslug""
|
|
|
|
|
)
|
2011-11-22 09:14:09 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
@override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
|
2011-10-26 05:33:17 +00:00
|
|
|
|
def test_prepopulated_maxlength_localized(self):
|
|
|
|
|
"""
|
|
|
|
|
Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure
|
2012-03-02 17:16:52 +00:00
|
|
|
|
that maxLength (in the JavaScript) is rendered without separators.
|
2011-10-26 05:33:17 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_prepopulatedpostlargeslug_add'))
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, ""maxLength": 1000") # instead of 1,000
|
2011-04-22 12:02:25 +00:00
|
|
|
|
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2016-02-07 02:24:36 +00:00
|
|
|
|
class SeleniumTests(AdminSeleniumTestCase):
|
2013-06-10 10:11:46 +00:00
|
|
|
|
|
2016-02-07 02:24:36 +00:00
|
|
|
|
available_apps = ['admin_views'] + AdminSeleniumTestCase.available_apps
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
2015-03-05 13:21:29 +00:00
|
|
|
|
def setUp(self):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
self.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-03-05 13:21:29 +00:00
|
|
|
|
self.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
2013-02-19 16:01:29 +00:00
|
|
|
|
def test_prepopulated_fields(self):
|
2012-02-19 16:42:12 +00:00
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The JavaScript-automated prepopulated fields work with the main form
|
|
|
|
|
and with stacked and tabular inlines.
|
2012-02-19 16:42:12 +00:00
|
|
|
|
Refs #13068, #9264, #9983, #9784.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_mainprepopulated_add'))
|
2017-05-10 12:48:57 +00:00
|
|
|
|
self.wait_for('.select2')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
|
|
|
|
# Main form ----------------------------------------------------------
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_pubdate').send_keys('2012-02-18')
|
2012-02-23 08:07:07 +00:00
|
|
|
|
self.get_select_option('#id_status', 'option two').click()
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_name').send_keys(' this is the mAin nÀMë and it\'s awεšomeııı')
|
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
|
|
|
|
|
slug3 = self.selenium.find_element_by_id('id_slug3').get_attribute('value')
|
2015-04-15 22:28:49 +00:00
|
|
|
|
self.assertEqual(slug1, 'main-name-and-its-awesomeiii-2012-02-18')
|
|
|
|
|
self.assertEqual(slug2, 'option-two-main-name-and-its-awesomeiii')
|
2017-10-24 14:58:07 +00:00
|
|
|
|
self.assertEqual(slug3, 'this-is-the-main-n\xe0m\xeb-and-its-aw\u03b5\u0161ome\u0131\u0131\u0131')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
|
|
|
|
# Stacked inlines ----------------------------------------------------
|
|
|
|
|
# Initial inline
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-pubdate').send_keys('2011-12-17')
|
2012-02-23 08:07:07 +00:00
|
|
|
|
self.get_select_option('#id_relatedprepopulated_set-0-status', 'option one').click()
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-name').send_keys(
|
|
|
|
|
' here is a sŤāÇkeð inline ! '
|
|
|
|
|
)
|
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-0-slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-0-slug2').get_attribute('value')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
self.assertEqual(slug1, 'here-stacked-inline-2011-12-17')
|
|
|
|
|
self.assertEqual(slug2, 'option-one-here-stacked-inline')
|
2017-05-10 12:48:57 +00:00
|
|
|
|
initial_select2_inputs = self.selenium.find_elements_by_class_name('select2-selection')
|
|
|
|
|
# Inline formsets have empty/invisible forms.
|
2017-12-02 14:54:31 +00:00
|
|
|
|
# Only the 4 visible select2 inputs are initialized.
|
2017-05-10 12:48:57 +00:00
|
|
|
|
num_initial_select2_inputs = len(initial_select2_inputs)
|
2017-12-02 14:54:31 +00:00
|
|
|
|
self.assertEqual(num_initial_select2_inputs, 4)
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
|
|
|
|
# Add an inline
|
2013-10-23 14:04:02 +00:00
|
|
|
|
self.selenium.find_elements_by_link_text('Add another Related prepopulated')[0].click()
|
2017-05-10 12:48:57 +00:00
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(self.selenium.find_elements_by_class_name('select2-selection')),
|
|
|
|
|
num_initial_select2_inputs + 2
|
|
|
|
|
)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25')
|
2012-02-23 08:07:07 +00:00
|
|
|
|
self.get_select_option('#id_relatedprepopulated_set-1-status', 'option two').click()
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-name').send_keys(
|
2015-09-11 23:33:12 +00:00
|
|
|
|
' now you haVe anöther sŤāÇkeð inline with a very ... '
|
|
|
|
|
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... '
|
|
|
|
|
)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-1-slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-1-slug2').get_attribute('value')
|
2015-09-11 23:33:12 +00:00
|
|
|
|
# 50 characters maximum for slug1 field
|
|
|
|
|
self.assertEqual(slug1, 'now-you-have-another-stacked-inline-very-loooooooo')
|
|
|
|
|
# 60 characters maximum for slug2 field
|
|
|
|
|
self.assertEqual(slug2, 'option-two-now-you-have-another-stacked-inline-very-looooooo')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
|
|
|
|
|
# Tabular inlines ----------------------------------------------------
|
|
|
|
|
# Initial inline
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-pubdate').send_keys('1234-12-07')
|
2012-02-23 08:07:07 +00:00
|
|
|
|
self.get_select_option('#id_relatedprepopulated_set-2-0-status', 'option two').click()
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-name').send_keys(
|
|
|
|
|
'And now, with a tÃbűlaŘ inline !!!'
|
|
|
|
|
)
|
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-slug2').get_attribute('value')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
self.assertEqual(slug1, 'and-now-tabular-inline-1234-12-07')
|
|
|
|
|
self.assertEqual(slug2, 'option-two-and-now-tabular-inline')
|
|
|
|
|
|
|
|
|
|
# Add an inline
|
2013-10-23 14:04:02 +00:00
|
|
|
|
self.selenium.find_elements_by_link_text('Add another Related prepopulated')[1].click()
|
2017-05-10 12:48:57 +00:00
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(self.selenium.find_elements_by_class_name('select2-selection')),
|
|
|
|
|
num_initial_select2_inputs + 4
|
|
|
|
|
)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22')
|
2012-02-23 08:07:07 +00:00
|
|
|
|
self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option one').click()
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-name').send_keys(
|
2016-09-16 16:15:00 +00:00
|
|
|
|
r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters'
|
2015-09-11 23:33:12 +00:00
|
|
|
|
)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug2').get_attribute('value')
|
2012-02-19 16:42:12 +00:00
|
|
|
|
self.assertEqual(slug1, 'tabular-inline-ignored-characters-1981-08-22')
|
|
|
|
|
self.assertEqual(slug2, 'option-one-tabular-inline-ignored-characters')
|
2017-05-10 12:48:57 +00:00
|
|
|
|
# Add an inline without an initial inline.
|
|
|
|
|
# The button is outside of the browser frame.
|
|
|
|
|
self.selenium.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
|
|
|
|
self.selenium.find_elements_by_link_text('Add another Related prepopulated')[2].click()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(self.selenium.find_elements_by_class_name('select2-selection')),
|
|
|
|
|
num_initial_select2_inputs + 6
|
|
|
|
|
)
|
2012-02-19 16:42:12 +00:00
|
|
|
|
# Save and check that everything is properly stored in the database
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
2013-02-20 01:08:55 +00:00
|
|
|
|
self.wait_page_loaded()
|
2012-02-19 16:42:12 +00:00
|
|
|
|
self.assertEqual(MainPrepopulated.objects.all().count(), 1)
|
|
|
|
|
MainPrepopulated.objects.get(
|
2015-04-15 22:28:49 +00:00
|
|
|
|
name=' this is the mAin nÀMë and it\'s awεšomeııı',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
pubdate='2012-02-18',
|
|
|
|
|
status='option two',
|
2015-04-15 22:28:49 +00:00
|
|
|
|
slug1='main-name-and-its-awesomeiii-2012-02-18',
|
|
|
|
|
slug2='option-two-main-name-and-its-awesomeiii',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertEqual(RelatedPrepopulated.objects.all().count(), 4)
|
|
|
|
|
RelatedPrepopulated.objects.get(
|
2012-06-07 16:08:47 +00:00
|
|
|
|
name=' here is a sŤāÇkeð inline ! ',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
pubdate='2011-12-17',
|
|
|
|
|
status='option one',
|
|
|
|
|
slug1='here-stacked-inline-2011-12-17',
|
|
|
|
|
slug2='option-one-here-stacked-inline',
|
|
|
|
|
)
|
|
|
|
|
RelatedPrepopulated.objects.get(
|
2015-09-11 23:33:12 +00:00
|
|
|
|
# 75 characters in name field
|
|
|
|
|
name=' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooo',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
pubdate='1999-01-25',
|
|
|
|
|
status='option two',
|
|
|
|
|
slug1='now-you-have-another-stacked-inline-very-loooooooo',
|
|
|
|
|
slug2='option-two-now-you-have-another-stacked-inline-very-looooooo',
|
|
|
|
|
)
|
|
|
|
|
RelatedPrepopulated.objects.get(
|
2012-06-07 16:08:47 +00:00
|
|
|
|
name='And now, with a tÃbűlaŘ inline !!!',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
pubdate='1234-12-07',
|
|
|
|
|
status='option two',
|
|
|
|
|
slug1='and-now-tabular-inline-1234-12-07',
|
|
|
|
|
slug2='option-two-and-now-tabular-inline',
|
|
|
|
|
)
|
|
|
|
|
RelatedPrepopulated.objects.get(
|
2016-09-16 16:15:00 +00:00
|
|
|
|
name=r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters',
|
2012-02-19 16:42:12 +00:00
|
|
|
|
pubdate='1981-08-22',
|
|
|
|
|
status='option one',
|
|
|
|
|
slug1='tabular-inline-ignored-characters-1981-08-22',
|
|
|
|
|
slug2='option-one-tabular-inline-ignored-characters',
|
|
|
|
|
)
|
|
|
|
|
|
2013-07-30 07:21:08 +00:00
|
|
|
|
def test_populate_existing_object(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The prepopulation works for existing objects too, as long as
|
|
|
|
|
the original field is empty (#19082).
|
2013-07-30 07:21:08 +00:00
|
|
|
|
"""
|
|
|
|
|
# Slugs are empty to start with.
|
|
|
|
|
item = MainPrepopulated.objects.create(
|
|
|
|
|
name=' this is the mAin nÀMë',
|
|
|
|
|
pubdate='2012-02-18',
|
|
|
|
|
status='option two',
|
|
|
|
|
slug1='',
|
|
|
|
|
slug2='',
|
|
|
|
|
)
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2013-07-30 07:21:08 +00:00
|
|
|
|
|
2016-04-08 02:04:45 +00:00
|
|
|
|
object_url = self.live_server_url + reverse('admin:admin_views_mainprepopulated_change', args=(item.id,))
|
2013-07-30 07:21:08 +00:00
|
|
|
|
|
|
|
|
|
self.selenium.get(object_url)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_name').send_keys(' the best')
|
2013-07-30 07:21:08 +00:00
|
|
|
|
|
|
|
|
|
# The slugs got prepopulated since they were originally empty
|
2016-01-11 14:16:23 +00:00
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
|
2013-07-30 07:21:08 +00:00
|
|
|
|
self.assertEqual(slug1, 'main-name-best-2012-02-18')
|
|
|
|
|
self.assertEqual(slug2, 'option-two-main-name-best')
|
|
|
|
|
|
|
|
|
|
# Save the object
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
|
|
|
|
self.wait_page_loaded()
|
|
|
|
|
|
|
|
|
|
self.selenium.get(object_url)
|
2016-01-11 14:16:23 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_name').send_keys(' hello')
|
2013-07-30 07:21:08 +00:00
|
|
|
|
|
|
|
|
|
# The slugs got prepopulated didn't change since they were originally not empty
|
2016-01-11 14:16:23 +00:00
|
|
|
|
slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
|
|
|
|
|
slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
|
2013-07-30 07:21:08 +00:00
|
|
|
|
self.assertEqual(slug1, 'main-name-best-2012-02-18')
|
|
|
|
|
self.assertEqual(slug2, 'option-two-main-name-best')
|
|
|
|
|
|
2013-02-19 16:01:29 +00:00
|
|
|
|
def test_collapsible_fieldset(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
The 'collapse' class in fieldsets definition allows to
|
2013-02-19 16:01:29 +00:00
|
|
|
|
show/hide the appropriate field section.
|
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_article_add'))
|
2013-02-19 16:01:29 +00:00
|
|
|
|
self.assertFalse(self.selenium.find_element_by_id('id_title').is_displayed())
|
|
|
|
|
self.selenium.find_elements_by_link_text('Show')[0].click()
|
|
|
|
|
self.assertTrue(self.selenium.find_element_by_id('id_title').is_displayed())
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertEqual(self.selenium.find_element_by_id('fieldsetcollapser0').text, "Hide")
|
2013-02-19 16:01:29 +00:00
|
|
|
|
|
2013-09-01 18:02:30 +00:00
|
|
|
|
def test_first_field_focus(self):
|
|
|
|
|
"""JavaScript-assisted auto-focus on first usable form field."""
|
|
|
|
|
# First form field has a single widget
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_picture_add'))
|
2013-09-01 18:02:30 +00:00
|
|
|
|
self.assertEqual(
|
2014-07-24 12:25:15 +00:00
|
|
|
|
self.selenium.switch_to.active_element,
|
2013-09-01 18:02:30 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_name')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# First form field has a MultiWidget
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_reservation_add'))
|
2013-09-01 18:02:30 +00:00
|
|
|
|
self.assertEqual(
|
2014-07-24 12:25:15 +00:00
|
|
|
|
self.selenium.switch_to.active_element,
|
2013-09-01 18:02:30 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_start_date_0')
|
|
|
|
|
)
|
|
|
|
|
|
2014-07-28 16:29:33 +00:00
|
|
|
|
def test_cancel_delete_confirmation(self):
|
|
|
|
|
"Cancelling the deletion of an object takes the user back one page."
|
2014-12-01 20:47:41 +00:00
|
|
|
|
pizza = Pizza.objects.create(name="Double Cheese")
|
2014-07-28 16:29:33 +00:00
|
|
|
|
url = reverse('admin:admin_views_pizza_change', args=(pizza.id,))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
full_url = self.live_server_url + url
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.selenium.get(full_url)
|
|
|
|
|
self.selenium.find_element_by_class_name('deletelink').click()
|
2016-01-11 16:28:03 +00:00
|
|
|
|
# Click 'cancel' on the delete page.
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.selenium.find_element_by_class_name('cancel-link').click()
|
2015-08-20 00:43:27 +00:00
|
|
|
|
# Wait until we're back on the change page.
|
|
|
|
|
self.wait_for_text('#content h1', 'Change pizza')
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.assertEqual(self.selenium.current_url, full_url)
|
|
|
|
|
self.assertEqual(Pizza.objects.count(), 1)
|
|
|
|
|
|
|
|
|
|
def test_cancel_delete_related_confirmation(self):
|
|
|
|
|
"""
|
|
|
|
|
Cancelling the deletion of an object with relations takes the user back
|
|
|
|
|
one page.
|
|
|
|
|
"""
|
2014-12-01 20:47:41 +00:00
|
|
|
|
pizza = Pizza.objects.create(name="Double Cheese")
|
2014-07-28 16:29:33 +00:00
|
|
|
|
topping1 = Topping.objects.create(name="Cheddar")
|
|
|
|
|
topping2 = Topping.objects.create(name="Mozzarella")
|
|
|
|
|
pizza.toppings.add(topping1, topping2)
|
|
|
|
|
url = reverse('admin:admin_views_pizza_change', args=(pizza.id,))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
full_url = self.live_server_url + url
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.selenium.get(full_url)
|
|
|
|
|
self.selenium.find_element_by_class_name('deletelink').click()
|
2016-01-11 16:28:03 +00:00
|
|
|
|
# Click 'cancel' on the delete page.
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.selenium.find_element_by_class_name('cancel-link').click()
|
2015-08-20 00:43:27 +00:00
|
|
|
|
# Wait until we're back on the change page.
|
|
|
|
|
self.wait_for_text('#content h1', 'Change pizza')
|
2014-07-28 16:29:33 +00:00
|
|
|
|
self.assertEqual(self.selenium.current_url, full_url)
|
|
|
|
|
self.assertEqual(Pizza.objects.count(), 1)
|
|
|
|
|
self.assertEqual(Topping.objects.count(), 2)
|
|
|
|
|
|
2015-12-21 13:36:41 +00:00
|
|
|
|
def test_list_editable_popups(self):
|
|
|
|
|
"""
|
|
|
|
|
list_editable foreign keys have add/change popups.
|
|
|
|
|
"""
|
2016-01-08 15:21:27 +00:00
|
|
|
|
from selenium.webdriver.support.ui import Select
|
2015-12-21 13:36:41 +00:00
|
|
|
|
s1 = Section.objects.create(name='Test section')
|
|
|
|
|
Article.objects.create(
|
2016-01-08 15:21:27 +00:00
|
|
|
|
title='foo',
|
2015-12-21 13:36:41 +00:00
|
|
|
|
content='<p>Middle content</p>',
|
|
|
|
|
date=datetime.datetime(2008, 3, 18, 11, 54, 58),
|
|
|
|
|
section=s1,
|
|
|
|
|
)
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_article_changelist'))
|
|
|
|
|
# Change popup
|
|
|
|
|
self.selenium.find_element_by_id('change_id_form-0-section').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.wait_for_text('#content h1', 'Change section')
|
2016-01-08 15:21:27 +00:00
|
|
|
|
name_input = self.selenium.find_element_by_id('id_name')
|
|
|
|
|
name_input.clear()
|
2016-07-06 19:41:06 +00:00
|
|
|
|
name_input.send_keys('<i>edited section</i>')
|
2016-01-08 15:21:27 +00:00
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
2015-12-21 13:36:41 +00:00
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
2016-01-08 15:21:27 +00:00
|
|
|
|
select = Select(self.selenium.find_element_by_id('id_form-0-section'))
|
2016-07-06 19:41:06 +00:00
|
|
|
|
self.assertEqual(select.first_selected_option.text, '<i>edited section</i>')
|
2017-05-10 12:48:57 +00:00
|
|
|
|
# Rendered select2 input.
|
|
|
|
|
select2_display = self.selenium.find_element_by_class_name('select2-selection__rendered')
|
|
|
|
|
# Clear button (×\n) is included in text.
|
|
|
|
|
self.assertEqual(select2_display.text, '×\n<i>edited section</i>')
|
2015-12-21 13:36:41 +00:00
|
|
|
|
|
|
|
|
|
# Add popup
|
|
|
|
|
self.selenium.find_element_by_id('add_id_form-0-section').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.wait_for_text('#content h1', 'Add section')
|
2016-01-08 15:21:27 +00:00
|
|
|
|
self.selenium.find_element_by_id('id_name').send_keys('new section')
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
2015-12-21 13:36:41 +00:00
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
2016-01-08 15:21:27 +00:00
|
|
|
|
select = Select(self.selenium.find_element_by_id('id_form-0-section'))
|
|
|
|
|
self.assertEqual(select.first_selected_option.text, 'new section')
|
2017-05-10 12:48:57 +00:00
|
|
|
|
select2_display = self.selenium.find_element_by_class_name('select2-selection__rendered')
|
|
|
|
|
# Clear button (×\n) is included in text.
|
|
|
|
|
self.assertEqual(select2_display.text, '×\nnew section')
|
2015-12-21 13:36:41 +00:00
|
|
|
|
|
2016-01-07 09:07:15 +00:00
|
|
|
|
def test_inline_uuid_pk_edit_with_popup(self):
|
|
|
|
|
from selenium.webdriver.support.ui import Select
|
|
|
|
|
parent = ParentWithUUIDPK.objects.create(title='test')
|
|
|
|
|
related_with_parent = RelatedWithUUIDPKModel.objects.create(parent=parent)
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_change', args=(related_with_parent.id,))
|
|
|
|
|
self.selenium.get(self.live_server_url + change_url)
|
|
|
|
|
self.selenium.find_element_by_id('change_id_parent').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
|
|
|
|
select = Select(self.selenium.find_element_by_id('id_parent'))
|
|
|
|
|
self.assertEqual(select.first_selected_option.text, str(parent.id))
|
|
|
|
|
self.assertEqual(select.first_selected_option.get_attribute('value'), str(parent.id))
|
|
|
|
|
|
2016-01-08 23:49:03 +00:00
|
|
|
|
def test_inline_uuid_pk_add_with_popup(self):
|
|
|
|
|
from selenium.webdriver.support.ui import Select
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
self.selenium.get(self.live_server_url + reverse('admin:admin_views_relatedwithuuidpkmodel_add'))
|
|
|
|
|
self.selenium.find_element_by_id('add_id_parent').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.selenium.find_element_by_id('id_title').send_keys('test')
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
|
|
|
|
select = Select(self.selenium.find_element_by_id('id_parent'))
|
|
|
|
|
uuid_id = str(ParentWithUUIDPK.objects.first().id)
|
|
|
|
|
self.assertEqual(select.first_selected_option.text, uuid_id)
|
|
|
|
|
self.assertEqual(select.first_selected_option.get_attribute('value'), uuid_id)
|
|
|
|
|
|
2016-01-09 00:39:05 +00:00
|
|
|
|
def test_inline_uuid_pk_delete_with_popup(self):
|
|
|
|
|
from selenium.webdriver.support.ui import Select
|
|
|
|
|
parent = ParentWithUUIDPK.objects.create(title='test')
|
|
|
|
|
related_with_parent = RelatedWithUUIDPKModel.objects.create(parent=parent)
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_change', args=(related_with_parent.id,))
|
|
|
|
|
self.selenium.get(self.live_server_url + change_url)
|
|
|
|
|
self.selenium.find_element_by_id('delete_id_parent').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.selenium.find_element_by_xpath('//input[@value="Yes, I\'m sure"]').click()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
|
|
|
|
select = Select(self.selenium.find_element_by_id('id_parent'))
|
|
|
|
|
self.assertEqual(ParentWithUUIDPK.objects.count(), 0)
|
|
|
|
|
self.assertEqual(select.first_selected_option.text, '---------')
|
|
|
|
|
self.assertEqual(select.first_selected_option.get_attribute('value'), '')
|
|
|
|
|
|
2018-03-06 07:04:06 +00:00
|
|
|
|
def test_inline_with_popup_cancel_delete(self):
|
|
|
|
|
"""Clicking ""No, take me back" on a delete popup closes the window."""
|
|
|
|
|
parent = ParentWithUUIDPK.objects.create(title='test')
|
|
|
|
|
related_with_parent = RelatedWithUUIDPKModel.objects.create(parent=parent)
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_change', args=(related_with_parent.id,))
|
|
|
|
|
self.selenium.get(self.live_server_url + change_url)
|
|
|
|
|
self.selenium.find_element_by_id('delete_id_parent').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
self.selenium.find_element_by_xpath('//a[text()="No, take me back"]').click()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
|
|
|
|
self.assertEqual(len(self.selenium.window_handles), 1)
|
|
|
|
|
|
2016-03-24 20:22:35 +00:00
|
|
|
|
def test_list_editable_raw_id_fields(self):
|
|
|
|
|
parent = ParentWithUUIDPK.objects.create(title='test')
|
|
|
|
|
parent2 = ParentWithUUIDPK.objects.create(title='test2')
|
|
|
|
|
RelatedWithUUIDPKModel.objects.create(parent=parent)
|
|
|
|
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
|
|
|
|
change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_changelist', current_app=site2.name)
|
|
|
|
|
self.selenium.get(self.live_server_url + change_url)
|
|
|
|
|
self.selenium.find_element_by_id('lookup_id_form-0-parent').click()
|
|
|
|
|
self.wait_for_popup()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
|
|
|
|
# Select "parent2" in the popup.
|
|
|
|
|
self.selenium.find_element_by_link_text(str(parent2.pk)).click()
|
|
|
|
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
|
|
|
|
# The newly selected pk should appear in the raw id input.
|
|
|
|
|
value = self.selenium.find_element_by_id('id_form-0-parent').get_attribute('value')
|
|
|
|
|
self.assertEqual(value, str(parent2.pk))
|
|
|
|
|
|
2012-02-22 07:14:10 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2016-01-09 20:15:21 +00:00
|
|
|
|
class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2009-12-22 18:29:00 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2009-12-22 18:29:00 +00:00
|
|
|
|
|
|
|
|
|
def test_readonly_get(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_post_add'))
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertNotContains(response, 'name="posted"')
|
2013-05-24 06:02:07 +00:00
|
|
|
|
# 3 fields + 2 submit buttons + 5 inline management form fields, + 2
|
2010-02-01 14:14:56 +00:00
|
|
|
|
# hidden fields for inlines + 1 field for the inline + 2 empty form
|
2013-05-24 06:02:07 +00:00
|
|
|
|
self.assertContains(response, "<input", count=15)
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertContains(response, formats.localize(datetime.date.today()))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(response, "<label>Awesomeness level:</label>")
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertContains(response, "Very awesome.")
|
2014-04-26 17:18:45 +00:00
|
|
|
|
self.assertContains(response, "Unknown coolness.")
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertContains(response, "foo")
|
2012-11-17 16:06:24 +00:00
|
|
|
|
|
2018-01-21 07:09:10 +00:00
|
|
|
|
# Multiline text in a readonly field gets <br> tags
|
|
|
|
|
self.assertContains(response, 'Multiline<br>test<br>string')
|
|
|
|
|
self.assertContains(response, '<div class="readonly">Multiline<br>html<br>content</div>', html=True)
|
|
|
|
|
self.assertContains(response, 'InlineMultiline<br>test<br>string')
|
2012-11-17 16:06:24 +00:00
|
|
|
|
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(response, formats.localize(datetime.date.today() - datetime.timedelta(days=7)))
|
2009-12-22 18:29:00 +00:00
|
|
|
|
|
2011-10-10 12:35:06 +00:00
|
|
|
|
self.assertContains(response, '<div class="form-row field-coolness">')
|
|
|
|
|
self.assertContains(response, '<div class="form-row field-awesomeness_level">')
|
|
|
|
|
self.assertContains(response, '<div class="form-row field-posted">')
|
|
|
|
|
self.assertContains(response, '<div class="form-row field-value">')
|
|
|
|
|
self.assertContains(response, '<div class="form-row">')
|
2016-04-14 17:10:55 +00:00
|
|
|
|
self.assertContains(response, '<div class="help">', 3)
|
2015-09-11 23:33:12 +00:00
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2016-04-14 17:10:55 +00:00
|
|
|
|
'<div class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</div>',
|
2015-09-11 23:33:12 +00:00
|
|
|
|
html=True
|
|
|
|
|
)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2016-04-14 17:10:55 +00:00
|
|
|
|
'<div class="help">Some help text for the content (with unicode ŠĐĆŽćžšđ)</div>',
|
2015-09-11 23:33:12 +00:00
|
|
|
|
html=True
|
|
|
|
|
)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
2016-04-14 17:10:55 +00:00
|
|
|
|
'<div class="help">Some help text for the date (with unicode ŠĐĆŽćžšđ)</div>',
|
2015-09-11 23:33:12 +00:00
|
|
|
|
html=True
|
|
|
|
|
)
|
2010-04-05 15:37:43 +00:00
|
|
|
|
|
2009-12-22 18:29:00 +00:00
|
|
|
|
p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertContains(response, "%d amount of cool" % p.pk)
|
|
|
|
|
|
2015-12-24 21:32:53 +00:00
|
|
|
|
def test_readonly_text_field(self):
|
|
|
|
|
p = Post.objects.create(
|
|
|
|
|
title="Readonly test", content="test",
|
|
|
|
|
readonly_content='test\r\n\r\ntest\r\n\r\ntest\r\n\r\ntest',
|
|
|
|
|
)
|
|
|
|
|
Link.objects.create(
|
|
|
|
|
url="http://www.djangoproject.com", post=p,
|
|
|
|
|
readonly_link_content="test\r\nlink",
|
|
|
|
|
)
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
|
|
|
|
|
# Checking readonly field.
|
2018-01-21 07:09:10 +00:00
|
|
|
|
self.assertContains(response, 'test<br><br>test<br><br>test<br><br>test')
|
2015-12-24 21:32:53 +00:00
|
|
|
|
# Checking readonly field in inline.
|
2018-01-21 07:09:10 +00:00
|
|
|
|
self.assertContains(response, 'test<br>link')
|
2015-12-24 21:32:53 +00:00
|
|
|
|
|
2009-12-22 18:29:00 +00:00
|
|
|
|
def test_readonly_post(self):
|
|
|
|
|
data = {
|
|
|
|
|
"title": "Django Got Readonly Fields",
|
|
|
|
|
"content": "This is an incredible development.",
|
|
|
|
|
"link_set-TOTAL_FORMS": "1",
|
|
|
|
|
"link_set-INITIAL_FORMS": "0",
|
2010-02-01 14:14:56 +00:00
|
|
|
|
"link_set-MAX_NUM_FORMS": "0",
|
2009-12-22 18:29:00 +00:00
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_post_add'), data)
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Post.objects.count(), 1)
|
|
|
|
|
p = Post.objects.get()
|
|
|
|
|
self.assertEqual(p.posted, datetime.date.today())
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
data["posted"] = "10-8-1990" # some date that's not today
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_post_add'), data)
|
2009-12-22 18:29:00 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
self.assertEqual(Post.objects.count(), 2)
|
|
|
|
|
p = Post.objects.order_by('-id')[0]
|
|
|
|
|
self.assertEqual(p.posted, datetime.date.today())
|
2010-01-12 02:29:45 +00:00
|
|
|
|
|
2010-03-21 14:23:25 +00:00
|
|
|
|
def test_readonly_manytomany(self):
|
|
|
|
|
"Regression test for #13004"
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_pizza_add'))
|
2010-03-21 14:23:25 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2012-02-09 18:57:40 +00:00
|
|
|
|
def test_user_password_change_limited_queryset(self):
|
|
|
|
|
su = User.objects.filter(is_superuser=True)[0]
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin2:auth_user_password_change', args=(su.pk,)))
|
2012-05-03 14:39:16 +00:00
|
|
|
|
self.assertEqual(response.status_code, 404)
|
2012-02-09 18:57:40 +00:00
|
|
|
|
|
2012-11-25 22:13:22 +00:00
|
|
|
|
def test_change_form_renders_correct_null_choice_value(self):
|
|
|
|
|
"""
|
|
|
|
|
Regression test for #17911.
|
|
|
|
|
"""
|
|
|
|
|
choice = Choice.objects.create(choice=None)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_choice_change', args=(choice.pk,)))
|
2016-11-05 11:47:12 +00:00
|
|
|
|
self.assertContains(response, '<div class="readonly">No opinion</div>', html=True)
|
2012-11-25 22:13:22 +00:00
|
|
|
|
|
2016-01-09 20:15:21 +00:00
|
|
|
|
def test_readonly_manytomany_backwards_ref(self):
|
2013-08-29 13:39:31 +00:00
|
|
|
|
"""
|
|
|
|
|
Regression test for #16433 - backwards references for related objects
|
|
|
|
|
broke if the related field is read-only due to the help_text attribute
|
|
|
|
|
"""
|
|
|
|
|
topping = Topping.objects.create(name='Salami')
|
|
|
|
|
pizza = Pizza.objects.create(name='Americano')
|
|
|
|
|
pizza.toppings.add(topping)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_topping_add'))
|
2013-08-29 13:39:31 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2016-09-11 15:19:56 +00:00
|
|
|
|
def test_readonly_manytomany_forwards_ref(self):
|
|
|
|
|
topping = Topping.objects.create(name='Salami')
|
|
|
|
|
pizza = Pizza.objects.create(name='Americano')
|
|
|
|
|
pizza.toppings.add(topping)
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_pizza_change', args=(pizza.pk,)))
|
|
|
|
|
self.assertContains(response, '<label>Toppings:</label>', html=True)
|
2016-11-05 11:47:12 +00:00
|
|
|
|
self.assertContains(response, '<div class="readonly">Salami</div>', html=True)
|
2016-09-11 15:19:56 +00:00
|
|
|
|
|
2016-01-09 20:15:21 +00:00
|
|
|
|
def test_readonly_onetoone_backwards_ref(self):
|
|
|
|
|
"""
|
|
|
|
|
Can reference a reverse OneToOneField in ModelAdmin.readonly_fields.
|
|
|
|
|
"""
|
|
|
|
|
v1 = Villain.objects.create(name='Adam')
|
|
|
|
|
pl = Plot.objects.create(name='Test Plot', team_leader=v1, contact=v1)
|
|
|
|
|
pd = PlotDetails.objects.create(details='Brand New Plot', plot=pl)
|
|
|
|
|
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_plotproxy_change', args=(pl.pk,)))
|
|
|
|
|
field = self.get_admin_readonly_field(response, 'plotdetails')
|
|
|
|
|
self.assertEqual(field.contents(), 'Brand New Plot')
|
|
|
|
|
|
|
|
|
|
# The reverse relation also works if the OneToOneField is null.
|
|
|
|
|
pd.plot = None
|
|
|
|
|
pd.save()
|
|
|
|
|
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_plotproxy_change', args=(pl.pk,)))
|
|
|
|
|
field = self.get_admin_readonly_field(response, 'plotdetails')
|
|
|
|
|
self.assertEqual(field.contents(), '-') # default empty value
|
|
|
|
|
|
2014-02-18 22:44:33 +00:00
|
|
|
|
def test_readonly_field_overrides(self):
|
|
|
|
|
"""
|
|
|
|
|
Regression test for #22087 - ModelForm Meta overrides are ignored by
|
|
|
|
|
AdminReadonlyField
|
|
|
|
|
"""
|
|
|
|
|
p = FieldOverridePost.objects.create(title="Test Post", content="Test Content")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_fieldoverridepost_change', args=(p.pk,)))
|
2016-04-14 17:10:55 +00:00
|
|
|
|
self.assertContains(response, '<div class="help">Overridden help text for the date</div>')
|
2014-02-18 22:44:33 +00:00
|
|
|
|
self.assertContains(response, '<label for="id_public">Overridden public label:</label>', html=True)
|
|
|
|
|
self.assertNotContains(response, "Some help text for the date (with unicode ŠĐĆŽćžšđ)")
|
|
|
|
|
|
2015-03-08 10:50:32 +00:00
|
|
|
|
def test_correct_autoescaping(self):
|
|
|
|
|
"""
|
|
|
|
|
Make sure that non-field readonly elements are properly autoescaped (#24461)
|
|
|
|
|
"""
|
|
|
|
|
section = Section.objects.create(name='<a>evil</a>')
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_change', args=(section.pk,)))
|
|
|
|
|
self.assertNotContains(response, "<a>evil</a>", status_code=200)
|
|
|
|
|
self.assertContains(response, "<a>evil</a>", status_code=200)
|
|
|
|
|
|
2011-01-28 14:08:42 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2014-02-01 19:23:31 +00:00
|
|
|
|
class LimitChoicesToInAdminTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2014-02-01 19:23:31 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2014-02-01 19:23:31 +00:00
|
|
|
|
|
|
|
|
|
def test_limit_choices_to_as_callable(self):
|
|
|
|
|
"""Test for ticket 2445 changes to admin."""
|
|
|
|
|
threepwood = Character.objects.create(
|
|
|
|
|
username='threepwood',
|
|
|
|
|
last_action=datetime.datetime.today() + datetime.timedelta(days=1),
|
|
|
|
|
)
|
|
|
|
|
marley = Character.objects.create(
|
|
|
|
|
username='marley',
|
|
|
|
|
last_action=datetime.datetime.today() - datetime.timedelta(days=1),
|
|
|
|
|
)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_stumpjoke_add'))
|
2014-02-01 19:23:31 +00:00
|
|
|
|
# The allowed option should appear twice; the limited option should not appear.
|
|
|
|
|
self.assertContains(response, threepwood.username, count=2)
|
|
|
|
|
self.assertNotContains(response, marley.username)
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-01-28 14:08:42 +00:00
|
|
|
|
class RawIdFieldsTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2011-01-28 14:08:42 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-01-28 14:08:42 +00:00
|
|
|
|
|
|
|
|
|
def test_limit_choices_to(self):
|
|
|
|
|
"""Regression test for 14880"""
|
|
|
|
|
actor = Actor.objects.create(name="Palin", age=27)
|
2013-09-08 19:20:01 +00:00
|
|
|
|
Inquisition.objects.create(expected=True,
|
|
|
|
|
leader=actor,
|
|
|
|
|
country="England")
|
|
|
|
|
Inquisition.objects.create(expected=False,
|
|
|
|
|
leader=actor,
|
|
|
|
|
country="Spain")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_sketch_add'))
|
2011-01-28 14:08:42 +00:00
|
|
|
|
# Find the link
|
2012-08-14 12:36:11 +00:00
|
|
|
|
m = re.search(br'<a href="([^"]*)"[^>]* id="lookup_id_inquisition"', response.content)
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertTrue(m) # Got a match
|
2012-08-14 12:36:11 +00:00
|
|
|
|
popup_url = m.groups()[0].decode().replace("&", "&")
|
2011-01-28 14:08:42 +00:00
|
|
|
|
|
|
|
|
|
# Handle relative links
|
2012-07-20 13:36:52 +00:00
|
|
|
|
popup_url = urljoin(response.request['PATH_INFO'], popup_url)
|
2013-05-27 16:31:49 +00:00
|
|
|
|
# Get the popup and verify the correct objects show up in the resulting
|
|
|
|
|
# page. This step also tests integers, strings and booleans in the
|
|
|
|
|
# lookup query string; in model we define inquisition field to have a
|
|
|
|
|
# limit_choices_to option that includes a filter on a string field
|
|
|
|
|
# (inquisition__actor__name), a filter on an integer field
|
|
|
|
|
# (inquisition__actor__age), and a filter on a boolean field
|
|
|
|
|
# (inquisition__expected).
|
2011-01-28 14:08:42 +00:00
|
|
|
|
response2 = self.client.get(popup_url)
|
|
|
|
|
self.assertContains(response2, "Spain")
|
|
|
|
|
self.assertNotContains(response2, "England")
|
|
|
|
|
|
2013-05-27 16:31:49 +00:00
|
|
|
|
def test_limit_choices_to_isnull_false(self):
|
|
|
|
|
"""Regression test for 20182"""
|
|
|
|
|
Actor.objects.create(name="Palin", age=27)
|
|
|
|
|
Actor.objects.create(name="Kilbraken", age=50, title="Judge")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_sketch_add'))
|
2013-05-27 16:31:49 +00:00
|
|
|
|
# Find the link
|
|
|
|
|
m = re.search(br'<a href="([^"]*)"[^>]* id="lookup_id_defendant0"', response.content)
|
|
|
|
|
self.assertTrue(m) # Got a match
|
|
|
|
|
popup_url = m.groups()[0].decode().replace("&", "&")
|
|
|
|
|
|
|
|
|
|
# Handle relative links
|
|
|
|
|
popup_url = urljoin(response.request['PATH_INFO'], popup_url)
|
|
|
|
|
# Get the popup and verify the correct objects show up in the resulting
|
|
|
|
|
# page. This step tests field__isnull=0 gets parsed correctly from the
|
|
|
|
|
# lookup query string; in model we define defendant0 field to have a
|
|
|
|
|
# limit_choices_to option that includes "actor__title__isnull=False".
|
|
|
|
|
response2 = self.client.get(popup_url)
|
|
|
|
|
self.assertContains(response2, "Kilbraken")
|
|
|
|
|
self.assertNotContains(response2, "Palin")
|
|
|
|
|
|
|
|
|
|
def test_limit_choices_to_isnull_true(self):
|
|
|
|
|
"""Regression test for 20182"""
|
|
|
|
|
Actor.objects.create(name="Palin", age=27)
|
|
|
|
|
Actor.objects.create(name="Kilbraken", age=50, title="Judge")
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_sketch_add'))
|
2013-05-27 16:31:49 +00:00
|
|
|
|
# Find the link
|
|
|
|
|
m = re.search(br'<a href="([^"]*)"[^>]* id="lookup_id_defendant1"', response.content)
|
|
|
|
|
self.assertTrue(m) # Got a match
|
|
|
|
|
popup_url = m.groups()[0].decode().replace("&", "&")
|
|
|
|
|
|
|
|
|
|
# Handle relative links
|
|
|
|
|
popup_url = urljoin(response.request['PATH_INFO'], popup_url)
|
|
|
|
|
# Get the popup and verify the correct objects show up in the resulting
|
|
|
|
|
# page. This step tests field__isnull=1 gets parsed correctly from the
|
|
|
|
|
# lookup query string; in model we define defendant1 field to have a
|
|
|
|
|
# limit_choices_to option that includes "actor__title__isnull=True".
|
|
|
|
|
response2 = self.client.get(popup_url)
|
|
|
|
|
self.assertNotContains(response2, "Kilbraken")
|
|
|
|
|
self.assertContains(response2, "Palin")
|
|
|
|
|
|
2015-08-24 15:52:58 +00:00
|
|
|
|
def test_list_display_method_same_name_as_reverse_accessor(self):
|
|
|
|
|
"""
|
|
|
|
|
Should be able to use a ModelAdmin method in list_display that has the
|
|
|
|
|
same name as a reverse model field ("sketch" in this case).
|
|
|
|
|
"""
|
|
|
|
|
actor = Actor.objects.create(name="Palin", age=27)
|
|
|
|
|
Inquisition.objects.create(expected=True, leader=actor, country="England")
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_inquisition_changelist'))
|
|
|
|
|
self.assertContains(response, 'list-display-sketch')
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2010-08-06 14:58:05 +00:00
|
|
|
|
class UserAdminTest(TestCase):
|
2010-01-12 02:29:45 +00:00
|
|
|
|
"""
|
2010-08-06 14:58:05 +00:00
|
|
|
|
Tests user CRUD functionality.
|
2010-01-12 02:29:45 +00:00
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
|
|
|
|
cls.adduser = User.objects.create_user(username='adduser', password='secret', is_staff=True)
|
|
|
|
|
cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
|
|
|
|
|
|
|
|
|
cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True)
|
|
|
|
|
cls.per2 = Person.objects.create(name='Grace Hopper', gender=1, alive=False)
|
|
|
|
|
cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True)
|
2010-01-12 02:29:45 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2010-01-12 02:29:45 +00:00
|
|
|
|
|
2010-11-19 22:45:51 +00:00
|
|
|
|
def test_save_button(self):
|
|
|
|
|
user_count = User.objects.count()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_user_add'), {
|
2010-11-19 22:45:51 +00:00
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'newpassword',
|
|
|
|
|
})
|
2015-02-23 00:53:57 +00:00
|
|
|
|
new_user = User.objects.get(username='newuser')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:auth_user_change', args=(new_user.pk,)))
|
2010-11-19 22:45:51 +00:00
|
|
|
|
self.assertEqual(User.objects.count(), user_count + 1)
|
2013-06-18 18:02:00 +00:00
|
|
|
|
self.assertTrue(new_user.has_usable_password())
|
2010-11-19 22:45:51 +00:00
|
|
|
|
|
|
|
|
|
def test_save_continue_editing_button(self):
|
2010-08-06 16:08:40 +00:00
|
|
|
|
user_count = User.objects.count()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_user_add'), {
|
2010-01-12 23:35:29 +00:00
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'newpassword',
|
|
|
|
|
'_continue': '1',
|
|
|
|
|
})
|
2015-02-23 00:53:57 +00:00
|
|
|
|
new_user = User.objects.get(username='newuser')
|
2018-05-14 13:33:35 +00:00
|
|
|
|
new_user_url = reverse('admin:auth_user_change', args=(new_user.pk,))
|
|
|
|
|
self.assertRedirects(response, new_user_url, fetch_redirect_response=False)
|
2010-11-19 22:45:51 +00:00
|
|
|
|
self.assertEqual(User.objects.count(), user_count + 1)
|
2013-06-18 18:02:00 +00:00
|
|
|
|
self.assertTrue(new_user.has_usable_password())
|
2018-05-14 13:33:35 +00:00
|
|
|
|
response = self.client.get(new_user_url)
|
|
|
|
|
self.assertContains(
|
|
|
|
|
response,
|
|
|
|
|
'<li class="success">The user "<a href="%s">'
|
|
|
|
|
'%s</a>" was added successfully. You may edit it again below.</li>'
|
|
|
|
|
% (new_user_url, new_user),
|
|
|
|
|
html=True,
|
|
|
|
|
)
|
2010-01-12 02:29:45 +00:00
|
|
|
|
|
|
|
|
|
def test_password_mismatch(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_user_add'), {
|
2010-01-12 23:35:29 +00:00
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'mismatch',
|
|
|
|
|
})
|
2010-11-19 22:45:51 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2016-09-27 13:56:19 +00:00
|
|
|
|
self.assertFormError(response, 'adminform', 'password', [])
|
|
|
|
|
self.assertFormError(response, 'adminform', 'password2', ["The two password fields didn't match."])
|
2010-08-06 14:58:05 +00:00
|
|
|
|
|
2013-11-17 22:26:20 +00:00
|
|
|
|
def test_user_fk_add_popup(self):
|
|
|
|
|
"""User addition through a FK popup should return the appropriate JavaScript response."""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_album_add'))
|
|
|
|
|
self.assertContains(response, reverse('admin:auth_user_add'))
|
2013-11-17 22:26:20 +00:00
|
|
|
|
self.assertContains(response, 'class="related-widget-wrapper-link add-related" id="add_id_owner"')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_user_add') + '?_popup=1')
|
2010-08-06 14:58:05 +00:00
|
|
|
|
self.assertNotContains(response, 'name="_continue"')
|
2010-11-19 22:45:51 +00:00
|
|
|
|
self.assertNotContains(response, 'name="_addanother"')
|
2011-02-24 01:00:57 +00:00
|
|
|
|
data = {
|
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'newpassword',
|
|
|
|
|
'_popup': '1',
|
|
|
|
|
'_save': '1',
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_user_add') + '?_popup=1', data, follow=True)
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, '"obj": "newuser"')
|
2013-11-17 22:26:20 +00:00
|
|
|
|
|
|
|
|
|
def test_user_fk_change_popup(self):
|
|
|
|
|
"""User change through a FK popup should return the appropriate JavaScript response."""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_album_add'))
|
|
|
|
|
self.assertContains(response, reverse('admin:auth_user_change', args=('__fk__',)))
|
2013-11-17 22:26:20 +00:00
|
|
|
|
self.assertContains(response, 'class="related-widget-wrapper-link change-related" id="change_id_owner"')
|
|
|
|
|
user = User.objects.get(username='changeuser')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
url = reverse('admin:auth_user_change', args=(user.pk,)) + '?_popup=1'
|
2013-11-17 22:26:20 +00:00
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertNotContains(response, 'name="_continue"')
|
|
|
|
|
self.assertNotContains(response, 'name="_addanother"')
|
|
|
|
|
data = {
|
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'newpassword',
|
|
|
|
|
'last_login_0': '2007-05-30',
|
|
|
|
|
'last_login_1': '13:20:10',
|
|
|
|
|
'date_joined_0': '2007-05-30',
|
|
|
|
|
'date_joined_1': '13:20:10',
|
|
|
|
|
'_popup': '1',
|
|
|
|
|
'_save': '1',
|
|
|
|
|
}
|
|
|
|
|
response = self.client.post(url, data, follow=True)
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, '"obj": "newuser"')
|
|
|
|
|
self.assertContains(response, '"action": "change"')
|
2013-11-17 22:26:20 +00:00
|
|
|
|
|
|
|
|
|
def test_user_fk_delete_popup(self):
|
|
|
|
|
"""User deletion through a FK popup should return the appropriate JavaScript response."""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_album_add'))
|
|
|
|
|
self.assertContains(response, reverse('admin:auth_user_delete', args=('__fk__',)))
|
2013-11-17 22:26:20 +00:00
|
|
|
|
self.assertContains(response, 'class="related-widget-wrapper-link change-related" id="change_id_owner"')
|
|
|
|
|
user = User.objects.get(username='changeuser')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
url = reverse('admin:auth_user_delete', args=(user.pk,)) + '?_popup=1'
|
2013-11-17 22:26:20 +00:00
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
data = {
|
|
|
|
|
'post': 'yes',
|
|
|
|
|
'_popup': '1',
|
|
|
|
|
}
|
|
|
|
|
response = self.client.post(url, data, follow=True)
|
2015-11-23 10:46:19 +00:00
|
|
|
|
self.assertContains(response, '"action": "delete"')
|
2010-08-06 16:08:40 +00:00
|
|
|
|
|
2010-11-19 22:45:51 +00:00
|
|
|
|
def test_save_add_another_button(self):
|
2010-08-06 16:08:40 +00:00
|
|
|
|
user_count = User.objects.count()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_user_add'), {
|
2010-08-06 16:08:40 +00:00
|
|
|
|
'username': 'newuser',
|
|
|
|
|
'password1': 'newpassword',
|
|
|
|
|
'password2': 'newpassword',
|
|
|
|
|
'_addanother': '1',
|
|
|
|
|
})
|
|
|
|
|
new_user = User.objects.order_by('-id')[0]
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:auth_user_add'))
|
2010-11-19 22:45:51 +00:00
|
|
|
|
self.assertEqual(User.objects.count(), user_count + 1)
|
2013-06-18 18:02:00 +00:00
|
|
|
|
self.assertTrue(new_user.has_usable_password())
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2011-08-15 09:01:12 +00:00
|
|
|
|
def test_user_permission_performance(self):
|
|
|
|
|
u = User.objects.all()[0]
|
|
|
|
|
|
2011-12-11 12:04:37 +00:00
|
|
|
|
# Don't depend on a warm cache, see #17377.
|
|
|
|
|
ContentType.objects.clear_cache()
|
2013-05-10 14:56:42 +00:00
|
|
|
|
|
2014-06-08 20:42:12 +00:00
|
|
|
|
with self.assertNumQueries(10):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_user_change', args=(u.pk,)))
|
2011-08-15 09:01:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
2012-02-09 18:56:32 +00:00
|
|
|
|
def test_form_url_present_in_context(self):
|
|
|
|
|
u = User.objects.all()[0]
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin3:auth_user_password_change', args=(u.pk,)))
|
2012-02-09 18:56:32 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.context['form_url'], 'pony')
|
|
|
|
|
|
2011-08-15 09:01:12 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-08-15 09:01:12 +00:00
|
|
|
|
class GroupAdminTest(TestCase):
|
|
|
|
|
"""
|
|
|
|
|
Tests group CRUD functionality.
|
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2011-08-15 09:01:12 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-08-15 09:01:12 +00:00
|
|
|
|
|
|
|
|
|
def test_save_button(self):
|
|
|
|
|
group_count = Group.objects.count()
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:auth_group_add'), {
|
2011-08-15 09:01:12 +00:00
|
|
|
|
'name': 'newgroup',
|
|
|
|
|
})
|
|
|
|
|
|
2013-09-08 19:20:01 +00:00
|
|
|
|
Group.objects.order_by('-id')[0]
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertRedirects(response, reverse('admin:auth_group_changelist'))
|
2011-08-15 09:01:12 +00:00
|
|
|
|
self.assertEqual(Group.objects.count(), group_count + 1)
|
|
|
|
|
|
|
|
|
|
def test_group_permission_performance(self):
|
|
|
|
|
g = Group.objects.create(name="test_group")
|
2014-11-24 19:10:23 +00:00
|
|
|
|
|
|
|
|
|
# Ensure no queries are skipped due to cached content type for Group.
|
|
|
|
|
ContentType.objects.clear_cache()
|
|
|
|
|
|
2014-06-08 20:42:12 +00:00
|
|
|
|
with self.assertNumQueries(8):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:auth_group_change', args=(g.pk,)))
|
2011-08-15 09:01:12 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-10-10 12:35:06 +00:00
|
|
|
|
class CSSTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
cls.s1 = Section.objects.create(name='Test section')
|
|
|
|
|
cls.a1 = Article.objects.create(
|
|
|
|
|
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a2 = Article.objects.create(
|
|
|
|
|
content='<p>Oldest content</p>', date=datetime.datetime(2000, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.a3 = Article.objects.create(
|
|
|
|
|
content='<p>Newest content</p>', date=datetime.datetime(2009, 3, 18, 11, 54, 58), section=cls.s1
|
|
|
|
|
)
|
|
|
|
|
cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
|
2011-10-10 12:35:06 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-10-10 12:35:06 +00:00
|
|
|
|
|
2012-12-03 04:54:34 +00:00
|
|
|
|
def test_field_prefix_css_classes(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Fields have a CSS class name with a 'field-' prefix.
|
2012-12-03 04:54:34 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_post_add'))
|
2011-10-10 12:35:06 +00:00
|
|
|
|
|
|
|
|
|
# The main form
|
|
|
|
|
self.assertContains(response, 'class="form-row field-title"')
|
|
|
|
|
self.assertContains(response, 'class="form-row field-content"')
|
|
|
|
|
self.assertContains(response, 'class="form-row field-public"')
|
|
|
|
|
self.assertContains(response, 'class="form-row field-awesomeness_level"')
|
|
|
|
|
self.assertContains(response, 'class="form-row field-coolness"')
|
|
|
|
|
self.assertContains(response, 'class="form-row field-value"')
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
self.assertContains(response, 'class="form-row"') # The lambda function
|
2011-10-10 12:35:06 +00:00
|
|
|
|
|
|
|
|
|
# The tabular inline
|
|
|
|
|
self.assertContains(response, '<td class="field-url">')
|
|
|
|
|
self.assertContains(response, '<td class="field-posted">')
|
|
|
|
|
|
2012-12-03 04:54:34 +00:00
|
|
|
|
def test_index_css_classes(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
CSS class names are used for each app and model on the admin index
|
|
|
|
|
pages (#17050).
|
2012-12-03 04:54:34 +00:00
|
|
|
|
"""
|
|
|
|
|
# General index page
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:index'))
|
2012-12-03 04:54:34 +00:00
|
|
|
|
self.assertContains(response, '<div class="app-admin_views module">')
|
|
|
|
|
self.assertContains(response, '<tr class="model-actor">')
|
|
|
|
|
self.assertContains(response, '<tr class="model-album">')
|
|
|
|
|
|
|
|
|
|
# App index page
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2012-12-03 04:54:34 +00:00
|
|
|
|
self.assertContains(response, '<div class="app-admin_views module">')
|
|
|
|
|
self.assertContains(response, '<tr class="model-actor">')
|
|
|
|
|
self.assertContains(response, '<tr class="model-album">')
|
2011-10-10 12:35:06 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_model_in_form_body_class(self):
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Ensure app and model tag are correctly read by change_form template
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_add'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(response, '<body class=" app-admin_views model-section ')
|
2013-07-21 09:02:36 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_model_in_list_body_class(self):
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Ensure app and model tag are correctly read by change_list template
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_changelist'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(response, '<body class=" app-admin_views model-section ')
|
2013-07-21 09:02:36 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_model_in_delete_confirmation_body_class(self):
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Ensure app and model tag are correctly read by delete_confirmation
|
2013-07-21 09:02:36 +00:00
|
|
|
|
template
|
|
|
|
|
"""
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_section_delete', args=(self.s1.pk,)))
|
|
|
|
|
self.assertContains(response, '<body class=" app-admin_views model-section ')
|
2013-07-21 09:02:36 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_model_in_app_index_body_class(self):
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Ensure app and model tag are correctly read by app_index template
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2014-01-08 16:48:43 +00:00
|
|
|
|
self.assertContains(response, '<body class=" dashboard app-admin_views')
|
2013-07-21 09:02:36 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_app_model_in_delete_selected_confirmation_body_class(self):
|
2013-07-21 09:02:36 +00:00
|
|
|
|
"""
|
2014-03-02 14:25:53 +00:00
|
|
|
|
Ensure app and model tag are correctly read by
|
2013-07-21 09:02:36 +00:00
|
|
|
|
delete_selected_confirmation template
|
|
|
|
|
"""
|
|
|
|
|
action_data = {
|
2017-06-02 14:01:41 +00:00
|
|
|
|
ACTION_CHECKBOX_NAME: [self.s1.pk],
|
2013-07-21 09:02:36 +00:00
|
|
|
|
'action': 'delete_selected',
|
|
|
|
|
'index': 0,
|
|
|
|
|
}
|
2016-04-08 02:04:45 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_section_changelist'), action_data)
|
|
|
|
|
self.assertContains(response, '<body class=" app-admin_views model-section ')
|
2013-07-21 09:02:36 +00:00
|
|
|
|
|
2013-07-28 02:50:02 +00:00
|
|
|
|
def test_changelist_field_classes(self):
|
|
|
|
|
"""
|
|
|
|
|
Cells of the change list table should contain the field name in their class attribute
|
|
|
|
|
Refs #11195.
|
|
|
|
|
"""
|
2016-04-08 02:04:45 +00:00
|
|
|
|
Podcast.objects.create(name="Django Dose", release_date=datetime.date.today())
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_podcast_changelist'))
|
2016-04-08 02:04:45 +00:00
|
|
|
|
self.assertContains(response, '<th class="field-name">')
|
|
|
|
|
self.assertContains(response, '<td class="field-release_date nowrap">')
|
|
|
|
|
self.assertContains(response, '<td class="action-checkbox">')
|
2013-07-28 02:50:02 +00:00
|
|
|
|
|
|
|
|
|
|
2010-08-19 13:11:24 +00:00
|
|
|
|
try:
|
|
|
|
|
import docutils
|
2010-10-11 12:55:17 +00:00
|
|
|
|
except ImportError:
|
|
|
|
|
docutils = None
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2012-03-30 09:08:29 +00:00
|
|
|
|
@unittest.skipUnless(docutils, "no docutils installed.")
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2014-06-21 16:27:46 +00:00
|
|
|
|
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.admindocs', 'django.contrib.flatpages']})
|
2010-10-11 12:55:17 +00:00
|
|
|
|
class AdminDocsTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2010-08-19 13:11:24 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
def test_tags(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('django-admindocs-tags'))
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# The builtin tag group exists
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, "<h2>Built-in tags</h2>", count=2, html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# A builtin tag exists in both the index and detail
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, '<h3 id="built_in-autoescape">autoescape</h3>', html=True)
|
|
|
|
|
self.assertContains(response, '<li><a href="#built_in-autoescape">autoescape</a></li>', html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# An app tag exists in both the index and detail
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, '<h3 id="flatpages-get_flatpages">get_flatpages</h3>', html=True)
|
|
|
|
|
self.assertContains(response, '<li><a href="#flatpages-get_flatpages">get_flatpages</a></li>', html=True)
|
2010-09-11 00:02:33 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# The admin list tag group exists
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, "<h2>admin_list</h2>", count=2, html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# An admin list tag exists in both the index and detail
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, '<h3 id="admin_list-admin_actions">admin_actions</h3>', html=True)
|
|
|
|
|
self.assertContains(response, '<li><a href="#admin_list-admin_actions">admin_actions</a></li>', html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
def test_filters(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('django-admindocs-filters'))
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# The builtin filter group exists
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, "<h2>Built-in filters</h2>", count=2, html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
|
# A builtin filter exists in both the index and detail
|
2012-01-31 20:36:11 +00:00
|
|
|
|
self.assertContains(response, '<h3 id="built_in-add">add</h3>', html=True)
|
|
|
|
|
self.assertContains(response, '<li><a href="#built_in-add">add</a></li>', html=True)
|
2010-08-14 13:41:56 +00:00
|
|
|
|
|
2010-10-10 01:57:56 +00:00
|
|
|
|
|
2014-12-17 22:36:32 +00:00
|
|
|
|
@override_settings(
|
2016-02-05 20:56:52 +00:00
|
|
|
|
ROOT_URLCONF='admin_views.urls',
|
2014-12-17 22:36:32 +00:00
|
|
|
|
TEMPLATES=[{
|
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
|
'APP_DIRS': True,
|
|
|
|
|
'OPTIONS': {
|
|
|
|
|
'context_processors': [
|
|
|
|
|
'django.template.context_processors.debug',
|
2015-01-12 21:31:44 +00:00
|
|
|
|
'django.template.context_processors.request',
|
2014-12-17 22:36:32 +00:00
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}],
|
|
|
|
|
USE_I18N=False,
|
|
|
|
|
)
|
2010-10-10 01:57:56 +00:00
|
|
|
|
class ValidXHTMLTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2010-10-10 01:57:56 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2010-10-10 01:57:56 +00:00
|
|
|
|
|
2014-07-07 23:08:42 +00:00
|
|
|
|
def test_lang_name_present(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:app_list', args=('admin_views',)))
|
2012-04-14 13:35:25 +00:00
|
|
|
|
self.assertNotContains(response, ' lang=""')
|
|
|
|
|
self.assertNotContains(response, ' xml:lang=""')
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls', USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
class DateHierarchyTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-02-08 12:00:01 +00:00
|
|
|
|
|
2011-02-08 12:20:18 +00:00
|
|
|
|
def assert_non_localized_year(self, response, year):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"""
|
|
|
|
|
The year is not localized with USE_THOUSAND_SEPARATOR (#15234).
|
2011-02-08 12:00:01 +00:00
|
|
|
|
"""
|
|
|
|
|
self.assertNotContains(response, formats.number_format(year))
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def assert_contains_year_link(self, response, date):
|
|
|
|
|
self.assertContains(response, '?release_date__year=%d"' % (date.year,))
|
|
|
|
|
|
|
|
|
|
def assert_contains_month_link(self, response, date):
|
|
|
|
|
self.assertContains(
|
2012-12-24 01:32:04 +00:00
|
|
|
|
response, '?release_date__month=%d&release_date__year=%d"' % (
|
|
|
|
|
date.month, date.year))
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def assert_contains_day_link(self, response, date):
|
|
|
|
|
self.assertContains(
|
2012-12-24 01:32:04 +00:00
|
|
|
|
response, '?release_date__day=%d&'
|
|
|
|
|
'release_date__month=%d&release_date__year=%d"' % (
|
|
|
|
|
date.day, date.month, date.year))
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def test_empty(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
No date hierarchy links display with empty changelist.
|
2010-12-12 22:54:50 +00:00
|
|
|
|
"""
|
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_podcast_changelist'))
|
|
|
|
|
self.assertNotContains(response, 'release_date__year=')
|
|
|
|
|
self.assertNotContains(response, 'release_date__month=')
|
|
|
|
|
self.assertNotContains(response, 'release_date__day=')
|
|
|
|
|
|
|
|
|
|
def test_single(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
Single day-level date hierarchy appears for single object.
|
2010-12-12 22:54:50 +00:00
|
|
|
|
"""
|
|
|
|
|
DATE = datetime.date(2000, 6, 30)
|
|
|
|
|
Podcast.objects.create(release_date=DATE)
|
2011-02-08 12:00:01 +00:00
|
|
|
|
url = reverse('admin:admin_views_podcast_changelist')
|
|
|
|
|
response = self.client.get(url)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
self.assert_contains_day_link(response, DATE)
|
2011-02-08 12:20:18 +00:00
|
|
|
|
self.assert_non_localized_year(response, 2000)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def test_within_month(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
day-level links appear for changelist within single month.
|
2010-12-12 22:54:50 +00:00
|
|
|
|
"""
|
|
|
|
|
DATES = (datetime.date(2000, 6, 30),
|
|
|
|
|
datetime.date(2000, 6, 15),
|
|
|
|
|
datetime.date(2000, 6, 3))
|
|
|
|
|
for date in DATES:
|
|
|
|
|
Podcast.objects.create(release_date=date)
|
2011-02-08 12:00:01 +00:00
|
|
|
|
url = reverse('admin:admin_views_podcast_changelist')
|
|
|
|
|
response = self.client.get(url)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
for date in DATES:
|
|
|
|
|
self.assert_contains_day_link(response, date)
|
2011-02-08 12:20:18 +00:00
|
|
|
|
self.assert_non_localized_year(response, 2000)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def test_within_year(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
month-level links appear for changelist within single year.
|
2010-12-12 22:54:50 +00:00
|
|
|
|
"""
|
|
|
|
|
DATES = (datetime.date(2000, 1, 30),
|
|
|
|
|
datetime.date(2000, 3, 15),
|
|
|
|
|
datetime.date(2000, 5, 3))
|
|
|
|
|
for date in DATES:
|
|
|
|
|
Podcast.objects.create(release_date=date)
|
2011-02-08 12:00:01 +00:00
|
|
|
|
url = reverse('admin:admin_views_podcast_changelist')
|
|
|
|
|
response = self.client.get(url)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
# no day-level links
|
|
|
|
|
self.assertNotContains(response, 'release_date__day=')
|
|
|
|
|
for date in DATES:
|
|
|
|
|
self.assert_contains_month_link(response, date)
|
2011-02-08 12:20:18 +00:00
|
|
|
|
self.assert_non_localized_year(response, 2000)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
|
|
|
|
|
def test_multiple_years(self):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
year-level links appear for year-spanning changelist.
|
2010-12-12 22:54:50 +00:00
|
|
|
|
"""
|
|
|
|
|
DATES = (datetime.date(2001, 1, 30),
|
|
|
|
|
datetime.date(2003, 3, 15),
|
|
|
|
|
datetime.date(2005, 5, 3))
|
|
|
|
|
for date in DATES:
|
|
|
|
|
Podcast.objects.create(release_date=date)
|
|
|
|
|
response = self.client.get(
|
|
|
|
|
reverse('admin:admin_views_podcast_changelist'))
|
|
|
|
|
# no day/month-level links
|
|
|
|
|
self.assertNotContains(response, 'release_date__day=')
|
|
|
|
|
self.assertNotContains(response, 'release_date__month=')
|
|
|
|
|
for date in DATES:
|
|
|
|
|
self.assert_contains_year_link(response, date)
|
|
|
|
|
|
|
|
|
|
# and make sure GET parameters still behave correctly
|
|
|
|
|
for date in DATES:
|
2011-02-08 12:00:01 +00:00
|
|
|
|
url = '%s?release_date__year=%d' % (
|
|
|
|
|
reverse('admin:admin_views_podcast_changelist'),
|
|
|
|
|
date.year)
|
|
|
|
|
response = self.client.get(url)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
self.assert_contains_month_link(response, date)
|
2011-02-08 12:20:18 +00:00
|
|
|
|
self.assert_non_localized_year(response, 2000)
|
|
|
|
|
self.assert_non_localized_year(response, 2003)
|
|
|
|
|
self.assert_non_localized_year(response, 2005)
|
2011-02-08 12:00:01 +00:00
|
|
|
|
|
|
|
|
|
url = '%s?release_date__year=%d&release_date__month=%d' % (
|
|
|
|
|
reverse('admin:admin_views_podcast_changelist'),
|
|
|
|
|
date.year, date.month)
|
|
|
|
|
response = self.client.get(url)
|
2010-12-12 22:54:50 +00:00
|
|
|
|
self.assert_contains_day_link(response, date)
|
2011-02-08 12:20:18 +00:00
|
|
|
|
self.assert_non_localized_year(response, 2000)
|
|
|
|
|
self.assert_non_localized_year(response, 2003)
|
|
|
|
|
self.assert_non_localized_year(response, 2005)
|
2011-07-03 17:56:43 +00:00
|
|
|
|
|
2016-05-05 17:52:54 +00:00
|
|
|
|
def test_related_field(self):
|
|
|
|
|
questions_data = (
|
|
|
|
|
# (posted data, number of answers),
|
|
|
|
|
(datetime.date(2001, 1, 30), 0),
|
|
|
|
|
(datetime.date(2003, 3, 15), 1),
|
|
|
|
|
(datetime.date(2005, 5, 3), 2),
|
|
|
|
|
)
|
|
|
|
|
for date, answer_count in questions_data:
|
|
|
|
|
question = Question.objects.create(posted=date)
|
|
|
|
|
for i in range(answer_count):
|
|
|
|
|
question.answer_set.create()
|
|
|
|
|
|
|
|
|
|
response = self.client.get(reverse('admin:admin_views_answer_changelist'))
|
|
|
|
|
for date, answer_count in questions_data:
|
|
|
|
|
link = '?question__posted__year=%d"' % (date.year,)
|
|
|
|
|
if answer_count > 0:
|
|
|
|
|
self.assertContains(response, link)
|
|
|
|
|
else:
|
|
|
|
|
self.assertNotContains(response, link)
|
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 10:48:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2011-07-03 17:56:43 +00:00
|
|
|
|
class AdminCustomSaveRelatedTests(TestCase):
|
|
|
|
|
"""
|
2016-10-27 07:53:39 +00:00
|
|
|
|
One can easily customize the way related objects are saved.
|
2011-07-03 17:56:43 +00:00
|
|
|
|
Refs #16115.
|
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2011-07-03 17:56:43 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2011-07-03 17:56:43 +00:00
|
|
|
|
|
|
|
|
|
def test_should_be_able_to_edit_related_objects_on_add_view(self):
|
|
|
|
|
post = {
|
|
|
|
|
'child_set-TOTAL_FORMS': '3',
|
|
|
|
|
'child_set-INITIAL_FORMS': '0',
|
|
|
|
|
'name': 'Josh Stone',
|
|
|
|
|
'child_set-0-name': 'Paul',
|
|
|
|
|
'child_set-1-name': 'Catherine',
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_parent_add'), post)
|
2011-07-03 17:56:43 +00:00
|
|
|
|
self.assertEqual(1, Parent.objects.count())
|
|
|
|
|
self.assertEqual(2, Child.objects.count())
|
|
|
|
|
|
|
|
|
|
children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
|
|
|
|
|
|
|
|
|
|
self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
|
2012-06-07 16:08:47 +00:00
|
|
|
|
self.assertEqual(['Catherine Stone', 'Paul Stone'], children_names)
|
2011-07-03 17:56:43 +00:00
|
|
|
|
|
|
|
|
|
def test_should_be_able_to_edit_related_objects_on_change_view(self):
|
|
|
|
|
parent = Parent.objects.create(name='Josh Stone')
|
|
|
|
|
paul = Child.objects.create(parent=parent, name='Paul')
|
|
|
|
|
catherine = Child.objects.create(parent=parent, name='Catherine')
|
|
|
|
|
post = {
|
|
|
|
|
'child_set-TOTAL_FORMS': '5',
|
|
|
|
|
'child_set-INITIAL_FORMS': '2',
|
|
|
|
|
'name': 'Josh Stone',
|
|
|
|
|
'child_set-0-name': 'Paul',
|
|
|
|
|
'child_set-0-id': paul.id,
|
|
|
|
|
'child_set-1-name': 'Catherine',
|
|
|
|
|
'child_set-1-id': catherine.id,
|
|
|
|
|
}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_parent_change', args=(parent.id,)), post)
|
2011-07-03 17:56:43 +00:00
|
|
|
|
|
|
|
|
|
children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
|
|
|
|
|
|
|
|
|
|
self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
|
2012-06-07 16:08:47 +00:00
|
|
|
|
self.assertEqual(['Catherine Stone', 'Paul Stone'], children_names)
|
2011-08-12 14:14:24 +00:00
|
|
|
|
|
|
|
|
|
def test_should_be_able_to_edit_related_objects_on_changelist_view(self):
|
|
|
|
|
parent = Parent.objects.create(name='Josh Rock')
|
2013-09-08 19:20:01 +00:00
|
|
|
|
Child.objects.create(parent=parent, name='Paul')
|
|
|
|
|
Child.objects.create(parent=parent, name='Catherine')
|
2011-08-12 14:14:24 +00:00
|
|
|
|
post = {
|
|
|
|
|
'form-TOTAL_FORMS': '1',
|
|
|
|
|
'form-INITIAL_FORMS': '1',
|
|
|
|
|
'form-MAX_NUM_FORMS': '0',
|
|
|
|
|
'form-0-id': parent.id,
|
|
|
|
|
'form-0-name': 'Josh Stone',
|
|
|
|
|
'_save': 'Save'
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.client.post(reverse('admin:admin_views_parent_changelist'), post)
|
2011-08-12 14:14:24 +00:00
|
|
|
|
children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
|
|
|
|
|
|
|
|
|
|
self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
|
2012-06-07 16:08:47 +00:00
|
|
|
|
self.assertEqual(['Catherine Stone', 'Paul Stone'], children_names)
|
2012-02-09 18:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2016-01-05 11:29:09 +00:00
|
|
|
|
class AdminViewLogoutTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2012-02-09 18:56:23 +00:00
|
|
|
|
|
2016-01-05 11:29:09 +00:00
|
|
|
|
def test_logout(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:logout'))
|
2012-02-09 18:56:23 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2013-04-10 08:16:15 +00:00
|
|
|
|
self.assertTemplateUsed(response, 'registration/logged_out.html')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertEqual(response.request['PATH_INFO'], reverse('admin:logout'))
|
2016-01-05 11:29:09 +00:00
|
|
|
|
self.assertFalse(response.context['has_permission'])
|
|
|
|
|
self.assertNotContains(response, 'user-tools') # user-tools div shouldn't visible.
|
2012-02-09 18:56:23 +00:00
|
|
|
|
|
2016-01-05 11:29:09 +00:00
|
|
|
|
def test_client_logout_url_can_be_used_to_login(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:logout'))
|
2012-02-09 18:56:23 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302) # we should be redirected to the login page.
|
|
|
|
|
|
|
|
|
|
# follow the redirect and test results.
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:logout'), follow=True)
|
2012-02-09 18:56:23 +00:00
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2013-04-10 08:16:15 +00:00
|
|
|
|
self.assertTemplateUsed(response, 'admin/login.html')
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertEqual(response.request['PATH_INFO'], reverse('admin:login'))
|
2018-01-21 07:09:10 +00:00
|
|
|
|
self.assertContains(response, '<input type="hidden" name="next" value="%s">' % reverse('admin:index'))
|
2012-11-17 21:53:31 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2012-11-17 21:53:31 +00:00
|
|
|
|
class AdminUserMessageTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2012-11-17 21:53:31 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2012-11-17 21:53:31 +00:00
|
|
|
|
|
|
|
|
|
def send_message(self, level):
|
|
|
|
|
"""
|
|
|
|
|
Helper that sends a post to the dummy test methods and asserts that a
|
|
|
|
|
message with the level has appeared in the response.
|
|
|
|
|
"""
|
|
|
|
|
action_data = {
|
|
|
|
|
ACTION_CHECKBOX_NAME: [1],
|
|
|
|
|
'action': 'message_%s' % level,
|
|
|
|
|
'index': 0,
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_usermessenger_changelist'),
|
2012-11-17 21:53:31 +00:00
|
|
|
|
action_data, follow=True)
|
|
|
|
|
self.assertContains(response,
|
|
|
|
|
'<li class="%s">Test %s</li>' % (level, level),
|
|
|
|
|
html=True)
|
|
|
|
|
|
|
|
|
|
@override_settings(MESSAGE_LEVEL=10) # Set to DEBUG for this request
|
|
|
|
|
def test_message_debug(self):
|
|
|
|
|
self.send_message('debug')
|
|
|
|
|
|
|
|
|
|
def test_message_info(self):
|
|
|
|
|
self.send_message('info')
|
|
|
|
|
|
|
|
|
|
def test_message_success(self):
|
|
|
|
|
self.send_message('success')
|
|
|
|
|
|
|
|
|
|
def test_message_warning(self):
|
|
|
|
|
self.send_message('warning')
|
|
|
|
|
|
|
|
|
|
def test_message_error(self):
|
|
|
|
|
self.send_message('error')
|
|
|
|
|
|
|
|
|
|
def test_message_extra_tags(self):
|
|
|
|
|
action_data = {
|
|
|
|
|
ACTION_CHECKBOX_NAME: [1],
|
|
|
|
|
'action': 'message_extra_tags',
|
|
|
|
|
'index': 0,
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_usermessenger_changelist'),
|
2012-11-17 21:53:31 +00:00
|
|
|
|
action_data, follow=True)
|
|
|
|
|
self.assertContains(response,
|
|
|
|
|
'<li class="extra_tag info">Test tags</li>',
|
|
|
|
|
html=True)
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2013-06-18 19:41:36 +00:00
|
|
|
|
class AdminKeepChangeListFiltersTests(TestCase):
|
2013-07-18 19:17:40 +00:00
|
|
|
|
admin_site = site
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
|
|
|
|
cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
2013-06-18 19:41:36 +00:00
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
2018-06-20 18:08:56 +00:00
|
|
|
|
def assertURLEqual(self, url1, url2, msg_prefix=''):
|
2014-03-31 09:54:17 +00:00
|
|
|
|
"""
|
|
|
|
|
Assert that two URLs are equal despite the ordering
|
|
|
|
|
of their querystring. Refs #22360.
|
|
|
|
|
"""
|
|
|
|
|
parsed_url1 = urlparse(url1)
|
|
|
|
|
path1 = parsed_url1.path
|
|
|
|
|
parsed_qs1 = dict(parse_qsl(parsed_url1.query))
|
|
|
|
|
|
|
|
|
|
parsed_url2 = urlparse(url2)
|
|
|
|
|
path2 = parsed_url2.path
|
|
|
|
|
parsed_qs2 = dict(parse_qsl(parsed_url2.query))
|
|
|
|
|
|
|
|
|
|
for parsed_qs in [parsed_qs1, parsed_qs2]:
|
|
|
|
|
if '_changelist_filters' in parsed_qs:
|
|
|
|
|
changelist_filters = parsed_qs['_changelist_filters']
|
|
|
|
|
parsed_filters = dict(parse_qsl(changelist_filters))
|
|
|
|
|
parsed_qs['_changelist_filters'] = parsed_filters
|
|
|
|
|
|
|
|
|
|
self.assertEqual(path1, path2)
|
|
|
|
|
self.assertEqual(parsed_qs1, parsed_qs2)
|
|
|
|
|
|
|
|
|
|
def test_assert_url_equal(self):
|
|
|
|
|
# Test equality.
|
2015-11-20 17:02:38 +00:00
|
|
|
|
change_user_url = reverse('admin:auth_user_change', args=(self.joepublicuser.pk,))
|
2014-03-31 09:54:17 +00:00
|
|
|
|
self.assertURLEqual(
|
2015-09-11 23:33:12 +00:00
|
|
|
|
'http://testserver{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(
|
|
|
|
|
change_user_url
|
|
|
|
|
),
|
|
|
|
|
'http://testserver{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(
|
|
|
|
|
change_user_url
|
|
|
|
|
)
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Test inequality.
|
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
|
self.assertURLEqual(
|
2015-09-11 23:33:12 +00:00
|
|
|
|
'http://testserver{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(
|
|
|
|
|
change_user_url
|
|
|
|
|
),
|
|
|
|
|
'http://testserver{}?_changelist_filters=is_staff__exact%3D1%26is_superuser__exact%3D1'.format(
|
|
|
|
|
change_user_url
|
|
|
|
|
)
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Ignore scheme and host.
|
|
|
|
|
self.assertURLEqual(
|
2015-09-11 23:33:12 +00:00
|
|
|
|
'http://testserver{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(
|
|
|
|
|
change_user_url
|
|
|
|
|
),
|
2015-02-06 22:25:15 +00:00
|
|
|
|
'{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(change_user_url)
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Ignore ordering of querystring.
|
|
|
|
|
self.assertURLEqual(
|
2015-02-06 22:25:15 +00:00
|
|
|
|
'{}?is_staff__exact=0&is_superuser__exact=0'.format(reverse('admin:auth_user_changelist')),
|
|
|
|
|
'{}?is_superuser__exact=0&is_staff__exact=0'.format(reverse('admin:auth_user_changelist'))
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Ignore ordering of _changelist_filters.
|
|
|
|
|
self.assertURLEqual(
|
2015-02-06 22:25:15 +00:00
|
|
|
|
'{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format(change_user_url),
|
|
|
|
|
'{}?_changelist_filters=is_superuser__exact%3D0%26is_staff__exact%3D0'.format(change_user_url)
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
2014-03-28 14:42:58 +00:00
|
|
|
|
def get_changelist_filters(self):
|
|
|
|
|
return {
|
2013-06-18 19:41:36 +00:00
|
|
|
|
'is_superuser__exact': 0,
|
|
|
|
|
'is_staff__exact': 0,
|
2014-03-28 14:42:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def get_changelist_filters_querystring(self):
|
|
|
|
|
return urlencode(self.get_changelist_filters())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
def get_preserved_filters_querystring(self):
|
|
|
|
|
return urlencode({
|
|
|
|
|
'_changelist_filters': self.get_changelist_filters_querystring()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def get_sample_user_id(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
return self.joepublicuser.pk
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
def get_changelist_url(self):
|
|
|
|
|
return '%s?%s' % (
|
2013-07-18 19:17:40 +00:00
|
|
|
|
reverse('admin:auth_user_changelist',
|
|
|
|
|
current_app=self.admin_site.name),
|
2013-06-18 19:41:36 +00:00
|
|
|
|
self.get_changelist_filters_querystring(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_add_url(self):
|
|
|
|
|
return '%s?%s' % (
|
2013-07-18 19:17:40 +00:00
|
|
|
|
reverse('admin:auth_user_add',
|
|
|
|
|
current_app=self.admin_site.name),
|
2013-06-18 19:41:36 +00:00
|
|
|
|
self.get_preserved_filters_querystring(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_change_url(self, user_id=None):
|
|
|
|
|
if user_id is None:
|
|
|
|
|
user_id = self.get_sample_user_id()
|
|
|
|
|
return "%s?%s" % (
|
2013-07-18 19:17:40 +00:00
|
|
|
|
reverse('admin:auth_user_change', args=(user_id,),
|
|
|
|
|
current_app=self.admin_site.name),
|
2013-06-18 19:41:36 +00:00
|
|
|
|
self.get_preserved_filters_querystring(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_history_url(self, user_id=None):
|
|
|
|
|
if user_id is None:
|
|
|
|
|
user_id = self.get_sample_user_id()
|
|
|
|
|
return "%s?%s" % (
|
2013-07-18 19:17:40 +00:00
|
|
|
|
reverse('admin:auth_user_history', args=(user_id,),
|
|
|
|
|
current_app=self.admin_site.name),
|
2013-06-18 19:41:36 +00:00
|
|
|
|
self.get_preserved_filters_querystring(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_delete_url(self, user_id=None):
|
|
|
|
|
if user_id is None:
|
|
|
|
|
user_id = self.get_sample_user_id()
|
|
|
|
|
return "%s?%s" % (
|
2013-07-18 19:17:40 +00:00
|
|
|
|
reverse('admin:auth_user_delete', args=(user_id,),
|
|
|
|
|
current_app=self.admin_site.name),
|
2013-06-18 19:41:36 +00:00
|
|
|
|
self.get_preserved_filters_querystring(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_changelist_view(self):
|
|
|
|
|
response = self.client.get(self.get_changelist_url())
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
# Check the `change_view` link has the correct querystring.
|
2014-03-31 09:54:17 +00:00
|
|
|
|
detail_link = re.search(
|
2015-11-20 17:02:38 +00:00
|
|
|
|
'<a href="(.*?)">{}</a>'.format(self.joepublicuser.username),
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.decode()
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertURLEqual(detail_link.group(1), self.get_change_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
def test_change_view(self):
|
|
|
|
|
# Get the `change_view`.
|
|
|
|
|
response = self.client.get(self.get_change_url())
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
# Check the form action.
|
2014-03-31 09:54:17 +00:00
|
|
|
|
form_action = re.search(
|
2017-11-08 00:06:32 +00:00
|
|
|
|
'<form action="(.*?)" method="post" id="user_form".*?>',
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.decode()
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
# Check the history link.
|
2014-03-31 09:54:17 +00:00
|
|
|
|
history_link = re.search(
|
|
|
|
|
'<a href="(.*?)" class="historylink">History</a>',
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.decode()
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertURLEqual(history_link.group(1), self.get_history_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
# Check the delete link.
|
2014-03-31 09:54:17 +00:00
|
|
|
|
delete_link = re.search(
|
|
|
|
|
'<a href="(.*?)" class="deletelink">Delete</a>',
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.decode()
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertURLEqual(delete_link.group(1), self.get_delete_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
# Test redirect on "Save".
|
|
|
|
|
post_data = {
|
|
|
|
|
'username': 'joepublic',
|
|
|
|
|
'last_login_0': '2007-05-30',
|
|
|
|
|
'last_login_1': '13:20:10',
|
|
|
|
|
'date_joined_0': '2007-05-30',
|
|
|
|
|
'date_joined_1': '13:20:10',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
post_data['_save'] = 1
|
|
|
|
|
response = self.client.post(self.get_change_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_changelist_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_save')
|
|
|
|
|
|
|
|
|
|
# Test redirect on "Save and continue".
|
|
|
|
|
post_data['_continue'] = 1
|
|
|
|
|
response = self.client.post(self.get_change_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_change_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_continue')
|
|
|
|
|
|
|
|
|
|
# Test redirect on "Save and add new".
|
|
|
|
|
post_data['_addanother'] = 1
|
|
|
|
|
response = self.client.post(self.get_change_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_add_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_addanother')
|
|
|
|
|
|
|
|
|
|
def test_add_view(self):
|
|
|
|
|
# Get the `add_view`.
|
|
|
|
|
response = self.client.get(self.get_add_url())
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2013-02-26 03:27:52 +00:00
|
|
|
|
|
2013-06-18 19:41:36 +00:00
|
|
|
|
# Check the form action.
|
2014-03-31 09:54:17 +00:00
|
|
|
|
form_action = re.search(
|
2017-11-08 00:06:32 +00:00
|
|
|
|
'<form action="(.*?)" method="post" id="user_form".*?>',
|
2018-02-07 19:20:04 +00:00
|
|
|
|
response.content.decode()
|
2014-03-31 09:54:17 +00:00
|
|
|
|
)
|
|
|
|
|
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
|
|
|
|
|
post_data = {
|
|
|
|
|
'username': 'dummy',
|
|
|
|
|
'password1': 'test',
|
|
|
|
|
'password2': 'test',
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 09:54:17 +00:00
|
|
|
|
# Test redirect on "Save".
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data['_save'] = 1
|
|
|
|
|
response = self.client.post(self.get_add_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_change_url(User.objects.get(username='dummy').pk))
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_save')
|
|
|
|
|
|
|
|
|
|
# Test redirect on "Save and continue".
|
|
|
|
|
post_data['username'] = 'dummy2'
|
|
|
|
|
post_data['_continue'] = 1
|
|
|
|
|
response = self.client.post(self.get_add_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_change_url(User.objects.get(username='dummy2').pk))
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_continue')
|
|
|
|
|
|
|
|
|
|
# Test redirect on "Save and add new".
|
|
|
|
|
post_data['username'] = 'dummy3'
|
|
|
|
|
post_data['_addanother'] = 1
|
|
|
|
|
response = self.client.post(self.get_add_url(), data=post_data)
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_add_url())
|
2013-06-18 19:41:36 +00:00
|
|
|
|
post_data.pop('_addanother')
|
|
|
|
|
|
|
|
|
|
def test_delete_view(self):
|
|
|
|
|
# Test redirect on "Delete".
|
|
|
|
|
response = self.client.post(self.get_delete_url(), {'post': 'yes'})
|
2018-06-20 18:08:56 +00:00
|
|
|
|
self.assertRedirects(response, self.get_changelist_url())
|
2013-07-18 19:17:40 +00:00
|
|
|
|
|
2014-03-28 14:42:58 +00:00
|
|
|
|
def test_url_prefix(self):
|
|
|
|
|
context = {
|
|
|
|
|
'preserved_filters': self.get_preserved_filters_querystring(),
|
|
|
|
|
'opts': User._meta,
|
|
|
|
|
}
|
2018-02-08 09:21:10 +00:00
|
|
|
|
prefixes = ('', '/prefix/', '/後台/')
|
|
|
|
|
for prefix in prefixes:
|
|
|
|
|
with self.subTest(prefix=prefix), override_script_prefix(prefix):
|
|
|
|
|
url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name)
|
|
|
|
|
self.assertURLEqual(
|
|
|
|
|
self.get_changelist_url(),
|
|
|
|
|
add_preserved_filters(context, url),
|
|
|
|
|
)
|
2014-03-28 14:42:58 +00:00
|
|
|
|
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
2013-07-18 19:17:40 +00:00
|
|
|
|
class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
|
|
|
|
|
admin_site = site2
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2013-02-23 17:57:48 +00:00
|
|
|
|
class TestLabelVisibility(TestCase):
|
|
|
|
|
""" #11277 -Labels of hidden fields in admin were not hidden. """
|
|
|
|
|
|
2015-02-23 00:53:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
|
|
|
|
def test_all_fields_visible(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_emptymodelvisible_add'))
|
2013-02-23 17:57:48 +00:00
|
|
|
|
self.assert_fieldline_visible(response)
|
|
|
|
|
self.assert_field_visible(response, 'first')
|
|
|
|
|
self.assert_field_visible(response, 'second')
|
|
|
|
|
|
|
|
|
|
def test_all_fields_hidden(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_emptymodelhidden_add'))
|
2013-02-23 17:57:48 +00:00
|
|
|
|
self.assert_fieldline_hidden(response)
|
|
|
|
|
self.assert_field_hidden(response, 'first')
|
|
|
|
|
self.assert_field_hidden(response, 'second')
|
|
|
|
|
|
|
|
|
|
def test_mixin(self):
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_emptymodelmixin_add'))
|
2013-02-23 17:57:48 +00:00
|
|
|
|
self.assert_fieldline_visible(response)
|
|
|
|
|
self.assert_field_hidden(response, 'first')
|
|
|
|
|
self.assert_field_visible(response, 'second')
|
|
|
|
|
|
|
|
|
|
def assert_field_visible(self, response, field_name):
|
2018-04-05 14:55:36 +00:00
|
|
|
|
self.assertContains(response, '<div class="fieldBox field-%s">' % field_name)
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
|
|
|
|
def assert_field_hidden(self, response, field_name):
|
2018-04-05 14:55:36 +00:00
|
|
|
|
self.assertContains(response, '<div class="fieldBox field-%s hidden">' % field_name)
|
2013-02-23 17:57:48 +00:00
|
|
|
|
|
|
|
|
|
def assert_fieldline_visible(self, response):
|
|
|
|
|
self.assertContains(response, '<div class="form-row field-first field-second">')
|
|
|
|
|
|
|
|
|
|
def assert_fieldline_hidden(self, response):
|
|
|
|
|
self.assertContains(response, '<div class="form-row hidden')
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2013-11-15 02:26:19 +00:00
|
|
|
|
class AdminViewOnSiteTests(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
cls.s1 = State.objects.create(name='New York')
|
|
|
|
|
cls.s2 = State.objects.create(name='Illinois')
|
|
|
|
|
cls.s3 = State.objects.create(name='California')
|
|
|
|
|
cls.c1 = City.objects.create(state=cls.s1, name='New York')
|
|
|
|
|
cls.c2 = City.objects.create(state=cls.s2, name='Chicago')
|
|
|
|
|
cls.c3 = City.objects.create(state=cls.s3, name='San Francisco')
|
|
|
|
|
cls.r1 = Restaurant.objects.create(city=cls.c1, name='Italian Pizza')
|
|
|
|
|
cls.r2 = Restaurant.objects.create(city=cls.c1, name='Boulevard')
|
|
|
|
|
cls.r3 = Restaurant.objects.create(city=cls.c2, name='Chinese Dinner')
|
|
|
|
|
cls.r4 = Restaurant.objects.create(city=cls.c2, name='Angels')
|
|
|
|
|
cls.r5 = Restaurant.objects.create(city=cls.c2, name='Take Away')
|
|
|
|
|
cls.r6 = Restaurant.objects.create(city=cls.c3, name='The Unknown Restaurant')
|
|
|
|
|
cls.w1 = Worker.objects.create(work_at=cls.r1, name='Mario', surname='Rossi')
|
|
|
|
|
cls.w2 = Worker.objects.create(work_at=cls.r1, name='Antonio', surname='Bianchi')
|
|
|
|
|
cls.w3 = Worker.objects.create(work_at=cls.r1, name='John', surname='Doe')
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
2013-11-15 02:26:19 +00:00
|
|
|
|
def test_add_view_form_and_formsets_run_validation(self):
|
|
|
|
|
"""
|
|
|
|
|
Issue #20522
|
|
|
|
|
Verifying that if the parent form fails validation, the inlines also
|
2016-09-27 13:56:19 +00:00
|
|
|
|
run validation even if validation is contingent on parent form data.
|
|
|
|
|
Also, assertFormError() and assertFormsetError() is usable for admin
|
|
|
|
|
forms and formsets.
|
2013-11-15 02:26:19 +00:00
|
|
|
|
"""
|
|
|
|
|
# The form validation should fail because 'some_required_info' is
|
|
|
|
|
# not included on the parent form, and the family_name of the parent
|
|
|
|
|
# does not match that of the child
|
|
|
|
|
post_data = {"family_name": "Test1",
|
|
|
|
|
"dependentchild_set-TOTAL_FORMS": "1",
|
|
|
|
|
"dependentchild_set-INITIAL_FORMS": "0",
|
|
|
|
|
"dependentchild_set-MAX_NUM_FORMS": "1",
|
|
|
|
|
"dependentchild_set-0-id": "",
|
|
|
|
|
"dependentchild_set-0-parent": "",
|
|
|
|
|
"dependentchild_set-0-family_name": "Test2"}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_parentwithdependentchildren_add'),
|
2013-11-15 02:26:19 +00:00
|
|
|
|
post_data)
|
2016-09-27 13:56:19 +00:00
|
|
|
|
self.assertFormError(response, 'adminform', 'some_required_info', ['This field is required.'])
|
|
|
|
|
msg = "The form 'adminform' in context 0 does not contain the non-field error 'Error'"
|
|
|
|
|
with self.assertRaisesMessage(AssertionError, msg):
|
|
|
|
|
self.assertFormError(response, 'adminform', None, ['Error'])
|
|
|
|
|
self.assertFormsetError(
|
|
|
|
|
response, 'inline_admin_formset', 0, None,
|
|
|
|
|
['Children must share a family name with their parents in this contrived test case']
|
|
|
|
|
)
|
2016-12-27 22:00:56 +00:00
|
|
|
|
msg = "The formset 'inline_admin_formset' in context 10 does not contain any non-form errors."
|
2016-09-27 13:56:19 +00:00
|
|
|
|
with self.assertRaisesMessage(AssertionError, msg):
|
|
|
|
|
self.assertFormsetError(response, 'inline_admin_formset', None, None, ['Error'])
|
2013-11-15 02:26:19 +00:00
|
|
|
|
|
|
|
|
|
def test_change_view_form_and_formsets_run_validation(self):
|
|
|
|
|
"""
|
|
|
|
|
Issue #20522
|
|
|
|
|
Verifying that if the parent form fails validation, the inlines also
|
|
|
|
|
run validation even if validation is contingent on parent form data
|
|
|
|
|
"""
|
|
|
|
|
pwdc = ParentWithDependentChildren.objects.create(some_required_info=6,
|
|
|
|
|
family_name="Test1")
|
|
|
|
|
# The form validation should fail because 'some_required_info' is
|
|
|
|
|
# not included on the parent form, and the family_name of the parent
|
|
|
|
|
# does not match that of the child
|
|
|
|
|
post_data = {"family_name": "Test2",
|
|
|
|
|
"dependentchild_set-TOTAL_FORMS": "1",
|
|
|
|
|
"dependentchild_set-INITIAL_FORMS": "0",
|
|
|
|
|
"dependentchild_set-MAX_NUM_FORMS": "1",
|
|
|
|
|
"dependentchild_set-0-id": "",
|
|
|
|
|
"dependentchild_set-0-parent": str(pwdc.id),
|
|
|
|
|
"dependentchild_set-0-family_name": "Test1"}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(
|
|
|
|
|
reverse('admin:admin_views_parentwithdependentchildren_change', args=(pwdc.id,)), post_data
|
|
|
|
|
)
|
2016-09-27 13:56:19 +00:00
|
|
|
|
self.assertFormError(response, 'adminform', 'some_required_info', ['This field is required.'])
|
|
|
|
|
self.assertFormsetError(
|
|
|
|
|
response, 'inline_admin_formset', 0, None,
|
|
|
|
|
['Children must share a family name with their parents in this contrived test case']
|
|
|
|
|
)
|
2013-11-15 02:26:19 +00:00
|
|
|
|
|
2014-01-20 02:45:21 +00:00
|
|
|
|
def test_check(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The view_on_site value is either a boolean or a callable"
|
2014-01-20 02:45:21 +00:00
|
|
|
|
try:
|
2015-09-10 13:05:31 +00:00
|
|
|
|
admin = CityAdmin(City, AdminSite())
|
2014-01-20 02:45:21 +00:00
|
|
|
|
CityAdmin.view_on_site = True
|
2015-09-10 13:05:31 +00:00
|
|
|
|
self.assertEqual(admin.check(), [])
|
2014-01-20 02:45:21 +00:00
|
|
|
|
CityAdmin.view_on_site = False
|
2015-09-10 13:05:31 +00:00
|
|
|
|
self.assertEqual(admin.check(), [])
|
2014-01-20 02:45:21 +00:00
|
|
|
|
CityAdmin.view_on_site = lambda obj: obj.get_absolute_url()
|
2015-09-10 13:05:31 +00:00
|
|
|
|
self.assertEqual(admin.check(), [])
|
2014-01-20 02:45:21 +00:00
|
|
|
|
CityAdmin.view_on_site = []
|
2015-09-10 13:05:31 +00:00
|
|
|
|
self.assertEqual(admin.check(), [
|
2014-01-20 02:45:21 +00:00
|
|
|
|
Error(
|
2014-03-03 05:27:17 +00:00
|
|
|
|
"The value of 'view_on_site' must be a callable or a boolean value.",
|
2014-01-20 02:45:21 +00:00
|
|
|
|
obj=CityAdmin,
|
|
|
|
|
id='admin.E025',
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
finally:
|
|
|
|
|
# Restore the original values for the benefit of other tests.
|
|
|
|
|
CityAdmin.view_on_site = True
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_false(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The 'View on site' button is not displayed if view_on_site is False"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_restaurant_change', args=(self.r1.pk,)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
content_type_pk = ContentType.objects.get_for_model(Restaurant).pk
|
2015-02-06 22:25:15 +00:00
|
|
|
|
self.assertNotContains(response, reverse('admin:view_on_site', args=(content_type_pk, 1)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_true(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The default behavior is followed if view_on_site is True"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_city_change', args=(self.c1.pk,)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
content_type_pk = ContentType.objects.get_for_model(City).pk
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.c1.pk)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_callable(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The right link is displayed if view_on_site is a callable"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_worker_change', args=(self.w1.pk,)))
|
|
|
|
|
self.assertContains(response, '"/worker/%s/%s/"' % (self.w1.surname, self.w1.name))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
2013-11-21 09:26:49 +00:00
|
|
|
|
def test_missing_get_absolute_url(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"None is returned if model doesn't have get_absolute_url"
|
2013-11-21 09:26:49 +00:00
|
|
|
|
model_admin = ModelAdmin(Worker, None)
|
|
|
|
|
self.assertIsNone(model_admin.get_view_on_site_url(Worker()))
|
|
|
|
|
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2013-10-24 15:28:09 +00:00
|
|
|
|
class InlineAdminViewOnSiteTest(TestCase):
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
cls.s1 = State.objects.create(name='New York')
|
|
|
|
|
cls.s2 = State.objects.create(name='Illinois')
|
|
|
|
|
cls.s3 = State.objects.create(name='California')
|
|
|
|
|
cls.c1 = City.objects.create(state=cls.s1, name='New York')
|
|
|
|
|
cls.c2 = City.objects.create(state=cls.s2, name='Chicago')
|
|
|
|
|
cls.c3 = City.objects.create(state=cls.s3, name='San Francisco')
|
|
|
|
|
cls.r1 = Restaurant.objects.create(city=cls.c1, name='Italian Pizza')
|
|
|
|
|
cls.r2 = Restaurant.objects.create(city=cls.c1, name='Boulevard')
|
|
|
|
|
cls.r3 = Restaurant.objects.create(city=cls.c2, name='Chinese Dinner')
|
|
|
|
|
cls.r4 = Restaurant.objects.create(city=cls.c2, name='Angels')
|
|
|
|
|
cls.r5 = Restaurant.objects.create(city=cls.c2, name='Take Away')
|
|
|
|
|
cls.r6 = Restaurant.objects.create(city=cls.c3, name='The Unknown Restaurant')
|
|
|
|
|
cls.w1 = Worker.objects.create(work_at=cls.r1, name='Mario', surname='Rossi')
|
|
|
|
|
cls.w2 = Worker.objects.create(work_at=cls.r1, name='Antonio', surname='Bianchi')
|
|
|
|
|
cls.w3 = Worker.objects.create(work_at=cls.r1, name='John', surname='Doe')
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_false(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The 'View on site' button is not displayed if view_on_site is False"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_state_change', args=(self.s1.pk,)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
content_type_pk = ContentType.objects.get_for_model(City).pk
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertNotContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.c1.pk)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_true(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The 'View on site' button is displayed if view_on_site is True"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_city_change', args=(self.c1.pk,)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
content_type_pk = ContentType.objects.get_for_model(Restaurant).pk
|
2015-02-23 00:53:57 +00:00
|
|
|
|
self.assertContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.r1.pk)))
|
2013-10-24 15:28:09 +00:00
|
|
|
|
|
|
|
|
|
def test_callable(self):
|
2016-10-27 07:53:39 +00:00
|
|
|
|
"The right link is displayed if view_on_site is a callable"
|
2015-02-23 00:53:57 +00:00
|
|
|
|
response = self.client.get(reverse('admin:admin_views_restaurant_change', args=(self.r1.pk,)))
|
|
|
|
|
self.assertContains(response, '"/worker_inline/%s/%s/"' % (self.w1.surname, self.w1.name))
|
2013-11-21 12:11:57 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
|
@override_settings(ROOT_URLCONF='admin_views.urls')
|
2014-11-27 18:34:14 +00:00
|
|
|
|
class GetFormsetsWithInlinesArgumentTest(TestCase):
|
|
|
|
|
"""
|
|
|
|
|
#23934 - When adding a new model instance in the admin, the 'obj' argument
|
|
|
|
|
of get_formsets_with_inlines() should be None. When changing, it should be
|
|
|
|
|
equal to the existing model instance.
|
|
|
|
|
The GetFormsetsArgumentCheckingAdmin ModelAdmin throws an exception
|
|
|
|
|
if obj is not None during add_view or obj is None during change_view.
|
|
|
|
|
"""
|
2015-02-23 00:53:57 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpTestData(cls):
|
2016-02-05 20:56:52 +00:00
|
|
|
|
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
|
2014-11-27 18:34:14 +00:00
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-11-20 17:02:38 +00:00
|
|
|
|
self.client.force_login(self.superuser)
|
2014-11-27 18:34:14 +00:00
|
|
|
|
|
|
|
|
|
def test_explicitly_provided_pk(self):
|
|
|
|
|
post_data = {'name': '1'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_explicitlyprovidedpk_add'), post_data)
|
2014-11-27 18:34:14 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
|
|
|
|
|
post_data = {'name': '2'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_explicitlyprovidedpk_change', args=(1,)), post_data)
|
2014-11-27 18:34:14 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
|
|
|
|
|
def test_implicitly_generated_pk(self):
|
|
|
|
|
post_data = {'name': '1'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_implicitlygeneratedpk_add'), post_data)
|
2014-11-27 18:34:14 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
|
|
|
|
|
post_data = {'name': '2'}
|
2015-02-06 22:25:15 +00:00
|
|
|
|
response = self.client.post(reverse('admin:admin_views_implicitlygeneratedpk_change', args=(1,)), post_data)
|
2014-11-27 18:34:14 +00:00
|
|
|
|
self.assertEqual(response.status_code, 302)
|