summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_views/tests.py
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2012-12-24 16:17:16 -0300
committerRamiro Morales <cramm0@gmail.com>2012-12-24 18:13:38 -0300
commit3b32e5cc2d4b6db22148cd7e51cdb735aeb25b13 (patch)
tree6ac4049dd2a72bb76ceda6ba5d69d2a7e30c59fd /tests/regressiontests/admin_views/tests.py
parent3ad34c231bb6e13c29dd268f9557a9cb241280fa (diff)
[1.5.x] Expanded tests added when fixing #14529.
To make sure changes in 35d1cd0 don't break anything. Refs #19505. ad769efa85e0296033572315025fed9fa9aefade from master.
Diffstat (limited to 'tests/regressiontests/admin_views/tests.py')
-rw-r--r--tests/regressiontests/admin_views/tests.py163
1 files changed, 152 insertions, 11 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index a091785530..1eddb4b743 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -47,7 +47,7 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
- Simple, UndeletableObject, Choice)
+ Simple, UndeletableObject, Choice, ShortMessage, Telegram)
ERROR_MESSAGE = "Please enter the correct username and password \
@@ -2505,27 +2505,93 @@ class AdminCustomQuerysetTest(TestCase):
else:
self.assertEqual(response.status_code, 404)
+ def test_add_model_modeladmin_defer_qs(self):
+ # Test for #14529. defer() is used in ModelAdmin.queryset()
+
+ # model has __unicode__ method
+ self.assertEqual(CoverLetter.objects.count(), 0)
+ # Emulate model instance creation via the admin
+ post_data = {
+ "author": "Candidate, Best",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/coverletter/add/',
+ post_data, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(CoverLetter.objects.count(), 1)
+ # Message should contain non-ugly model verbose name
+ self.assertContains(
+ response,
+ '<li class="info">The cover letter &quot;Candidate, Best&quot; was added successfully.</li>',
+ html=True
+ )
+
+ # model has no __unicode__ method
+ self.assertEqual(ShortMessage.objects.count(), 0)
+ # Emulate model instance creation via the admin
+ post_data = {
+ "content": "What's this SMS thing?",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/shortmessage/add/',
+ post_data, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(ShortMessage.objects.count(), 1)
+ # Message should contain non-ugly model verbose name
+ self.assertContains(
+ response,
+ '<li class="info">The short message &quot;ShortMessage object&quot; was added successfully.</li>',
+ html=True
+ )
+
def test_add_model_modeladmin_only_qs(self):
- # only() is used in ModelAdmin.queryset()
- p = Paper.objects.create(title="My Paper Title")
- self.assertEqual(Paper.objects.count(), 1)
- response = self.client.get('/test_admin/admin/admin_views/paper/%s/' % p.pk)
+ # Test for #14529. only() is used in ModelAdmin.queryset()
+
+ # model has __unicode__ method
+ self.assertEqual(Telegram.objects.count(), 0)
+ # Emulate model instance creation via the admin
+ post_data = {
+ "title": "Urgent telegram",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/telegram/add/',
+ post_data, follow=True)
self.assertEqual(response.status_code, 200)
+ self.assertEqual(Telegram.objects.count(), 1)
+ # Message should contain non-ugly model verbose name
+ self.assertContains(
+ response,
+ '<li class="info">The telegram &quot;Urgent telegram&quot; was added successfully.</li>',
+ html=True
+ )
+
+ # model has no __unicode__ method
+ self.assertEqual(Paper.objects.count(), 0)
+ # Emulate model instance creation via the admin
post_data = {
"title": "My Modified Paper Title",
"_save": "Save",
}
- response = self.client.post('/test_admin/admin/admin_views/paper/%s/' % p.pk,
+ response = self.client.post('/test_admin/admin/admin_views/paper/add/',
post_data, follow=True)
self.assertEqual(response.status_code, 200)
- # Message should contain non-ugly model name. Instance representation is set by six.text_type() (ugly)
- self.assertContains(response, '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
+ self.assertEqual(Paper.objects.count(), 1)
+ # Message should contain non-ugly model verbose name
+ self.assertContains(
+ response,
+ '<li class="info">The paper &quot;Paper object&quot; was added successfully.</li>',
+ html=True
+ )
+
+ def test_edit_model_modeladmin_defer_qs(self):
+ # Test for #14529. defer() is used in ModelAdmin.queryset()
- # defer() is used in ModelAdmin.queryset()
+ # model has __unicode__ method
cl = CoverLetter.objects.create(author="John Doe")
self.assertEqual(CoverLetter.objects.count(), 1)
response = self.client.get('/test_admin/admin/admin_views/coverletter/%s/' % cl.pk)
self.assertEqual(response.status_code, 200)
+ # Emulate model instance edit via the admin
post_data = {
"author": "John Doe II",
"_save": "Save",
@@ -2533,8 +2599,83 @@ class AdminCustomQuerysetTest(TestCase):
response = self.client.post('/test_admin/admin/admin_views/coverletter/%s/' % cl.pk,
post_data, follow=True)
self.assertEqual(response.status_code, 200)
- # Message should contain non-ugly model name. Instance representation is set by model's __unicode__()
- self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
+ self.assertEqual(CoverLetter.objects.count(), 1)
+ # Message should contain non-ugly model verbose name. Instance
+ # representation is set by model's __unicode__()
+ self.assertContains(
+ response,
+ '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>',
+ html=True
+ )
+
+ # model has no __unicode__ method
+ sm = ShortMessage.objects.create(content="This is expensive")
+ self.assertEqual(ShortMessage.objects.count(), 1)
+ response = self.client.get('/test_admin/admin/admin_views/shortmessage/%s/' % sm.pk)
+ self.assertEqual(response.status_code, 200)
+ # Emulate model instance edit via the admin
+ post_data = {
+ "content": "Too expensive",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/shortmessage/%s/' % sm.pk,
+ post_data, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(ShortMessage.objects.count(), 1)
+ # Message should contain non-ugly model verbose name. The ugly(!)
+ # instance representation is set by six.text_type()
+ self.assertContains(
+ response,
+ '<li class="info">The short message &quot;ShortMessage_Deferred_timestamp object&quot; was changed successfully.</li>',
+ html=True
+ )
+
+ def test_edit_model_modeladmin_only_qs(self):
+ # Test for #14529. only() is used in ModelAdmin.queryset()
+
+ # model has __unicode__ method
+ t = Telegram.objects.create(title="Frist Telegram")
+ self.assertEqual(Telegram.objects.count(), 1)
+ response = self.client.get('/test_admin/admin/admin_views/telegram/%s/' % t.pk)
+ self.assertEqual(response.status_code, 200)
+ # Emulate model instance edit via the admin
+ post_data = {
+ "title": "Telegram without typo",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/telegram/%s/' % t.pk,
+ post_data, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(Telegram.objects.count(), 1)
+ # Message should contain non-ugly model verbose name. The instance
+ # representation is set by model's __unicode__()
+ self.assertContains(
+ response,
+ '<li class="info">The telegram &quot;Telegram without typo&quot; was changed successfully.</li>',
+ html=True
+ )
+
+ # model has no __unicode__ method
+ p = Paper.objects.create(title="My Paper Title")
+ self.assertEqual(Paper.objects.count(), 1)
+ response = self.client.get('/test_admin/admin/admin_views/paper/%s/' % p.pk)
+ self.assertEqual(response.status_code, 200)
+ # Emulate model instance edit via the admin
+ post_data = {
+ "title": "My Modified Paper Title",
+ "_save": "Save",
+ }
+ response = self.client.post('/test_admin/admin/admin_views/paper/%s/' % p.pk,
+ post_data, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(Paper.objects.count(), 1)
+ # Message should contain non-ugly model verbose name. The ugly(!)
+ # instance representation is set by six.text_type()
+ self.assertContains(
+ response,
+ '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>',
+ html=True
+ )
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))