Code

Ticket #10523: 10523.logentry-200-chars-repr.diff

File 10523.logentry-200-chars-repr.diff, 2.4 KB (added by julien, 3 years ago)

Passing test case

Line 
1diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
2index bb8d026..4f18743 100644
3--- a/tests/regressiontests/admin_views/models.py
4+++ b/tests/regressiontests/admin_views/models.py
5@@ -23,7 +23,7 @@ class Article(models.Model):
6     """
7     A simple article to test admin views. Test backwards compatibility.
8     """
9-    title = models.CharField(max_length=100)
10+    title = models.CharField(max_length=255)
11     content = models.TextField()
12     date = models.DateTimeField()
13     section = models.ForeignKey(Section, null=True, blank=True)
14diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
15index b6e7b9e..07b569c 100644
16--- a/tests/regressiontests/admin_views/tests.py
17+++ b/tests/regressiontests/admin_views/tests.py
18@@ -1064,6 +1064,31 @@ class AdminViewPermissionsTest(TestCase):
19         self.assertContains(response, 'id="login-form"')
20 
21 
22+    def testLongUnicodeLogEntry(self):
23+        # Add an article
24+        add_dict = {'title' : ''.join([u'ä' for x in range(255)]),
25+                    'content': '<p>great article</p>',
26+                    'date_0': '2008-03-18', 'date_1': '10:54:39',
27+                    'section': 1}
28+        self.client.post('/test_admin/admin/', self.adduser_login)
29+        post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
30+        self.assertRedirects(post, '/test_admin/admin/')
31+        article = Article.objects.order_by('-id')[0]
32+        self.assertEqual(LogEntry.objects.all().count(), 1)
33+        logentry = LogEntry.objects.order_by('-id')[0]
34+        self.assertEqual(logentry.object_repr, ''.join([u'ä' for x in range(200)]))
35+        self.client.get('/test_admin/admin/logout/')
36+
37+        # Delete the article
38+        delete_dict = {'post': 'yes'}
39+        self.client.post('/test_admin/admin/', self.deleteuser_login)
40+        post = self.client.post('/test_admin/admin/admin_views/article/%s/delete/' % article.id, delete_dict)
41+        self.assertRedirects(post, '/test_admin/admin/')
42+        self.assertEqual(LogEntry.objects.all().count(), 2)
43+        logentry = LogEntry.objects.order_by('-id')[0]
44+        self.assertEqual(logentry.object_repr, ''.join([u'ä' for x in range(200)]))
45+        self.client.get('/test_admin/admin/logout/')
46+
47 class AdminViewDeletedObjectsTest(TestCase):
48     urls = "regressiontests.admin_views.urls"
49     fixtures = ['admin-views-users.xml', 'deleted-objects.xml']