summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_views
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-06-08 01:48:41 -0700
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-06-08 01:48:41 -0700
commit23d230f05833a63e951b8f451ff6c9f570eb3208 (patch)
tree7bfba5d08ef494684df6ce6d19958dce9d56674f /tests/regressiontests/admin_views
parentc1729510aae7eb9e534ef62dfd54c37a6f89c193 (diff)
parente1643e3535c4160c1a56c80f4d4db9848dc65e7a (diff)
Merge pull request #123 from apollo13/ticket18381
Fixed #18381 -- Stopped escaping object ids when passing them to the contenttypes.shortcut view. Thanks apollo13 for the patch and dhepper for the review.
Diffstat (limited to 'tests/regressiontests/admin_views')
-rw-r--r--tests/regressiontests/admin_views/fixtures/string-primary-key.xml6
-rw-r--r--tests/regressiontests/admin_views/models.py7
-rw-r--r--tests/regressiontests/admin_views/tests.py14
3 files changed, 19 insertions, 8 deletions
diff --git a/tests/regressiontests/admin_views/fixtures/string-primary-key.xml b/tests/regressiontests/admin_views/fixtures/string-primary-key.xml
index 8e1dbf047f..1792cb2d7e 100644
--- a/tests/regressiontests/admin_views/fixtures/string-primary-key.xml
+++ b/tests/regressiontests/admin_views/fixtures/string-primary-key.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="1" model="admin_views.modelwithstringprimarykey">
- <field type="CharField" name="id"><![CDATA[abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 -_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`]]></field>
- </object>
-</django-objects> \ No newline at end of file
+ <field type="CharField" name="string_pk"><![CDATA[abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 -_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`]]></field>
+ </object>
+</django-objects>
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 5aa775656b..ebb637ac6b 100644
--- a/tests/regressiontests/admin_views/models.py
+++ b/tests/regressiontests/admin_views/models.py
@@ -95,10 +95,13 @@ class CustomArticle(models.Model):
class ModelWithStringPrimaryKey(models.Model):
- id = models.CharField(max_length=255, primary_key=True)
+ string_pk = models.CharField(max_length=255, primary_key=True)
def __unicode__(self):
- return self.id
+ return self.string_pk
+
+ def get_absolute_url(self):
+ return u'/dummy/%s/' % self.string_pk
class Color(models.Model):
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index e220011fdc..f074d77b11 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -1402,7 +1402,7 @@ class AdminViewStringPrimaryKeyTest(TestCase):
def test_url_conflicts_with_add(self):
"A model with a primary key that ends with add should be visible"
- add_model = ModelWithStringPrimaryKey(id="i have something to add")
+ add_model = ModelWithStringPrimaryKey(pk="i have something to add")
add_model.save()
response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk))
should_contain = """<h1>Change model with string primary key</h1>"""
@@ -1410,7 +1410,7 @@ class AdminViewStringPrimaryKeyTest(TestCase):
def test_url_conflicts_with_delete(self):
"A model with a primary key that ends with delete should be visible"
- delete_model = ModelWithStringPrimaryKey(id="delete")
+ delete_model = ModelWithStringPrimaryKey(pk="delete")
delete_model.save()
response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk))
should_contain = """<h1>Change model with string primary key</h1>"""
@@ -1418,12 +1418,20 @@ class AdminViewStringPrimaryKeyTest(TestCase):
def test_url_conflicts_with_history(self):
"A model with a primary key that ends with history should be visible"
- history_model = ModelWithStringPrimaryKey(id="history")
+ history_model = ModelWithStringPrimaryKey(pk="history")
history_model.save()
response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk))
should_contain = """<h1>Change model with string primary key</h1>"""
self.assertContains(response, should_contain)
+ def test_shortcut_view_with_escaping(self):
+ "'View on site should' work properly with char fields"
+ model = ModelWithStringPrimaryKey(pk='abc_123')
+ model.save()
+ response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(model.pk))
+ should_contain = '/%s/" class="viewsitelink">' % model.pk
+ self.assertContains(response, should_contain)
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SecureViewTests(TestCase):