summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-02-24 05:02:00 -0800
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-24 05:02:00 -0800
commit7106a1e594dc28108e7e4f83af3ffb25289d3bb0 (patch)
tree146415347270d1db0f4eeb7b88beee71e2bcbea3 /tests
parentdeb4e097ae2a495480a2907028fc3c76eed0cbb7 (diff)
parentade992c61e15fbc83d87bfc688c0f844b6ef19fd (diff)
Merge pull request #819 from erikr/master
Fixed #16302 -- Ensured contrib.comments is IPv6 capable.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/comment_tests/tests/comment_view_tests.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/regressiontests/comment_tests/tests/comment_view_tests.py b/tests/regressiontests/comment_tests/tests/comment_view_tests.py
index 5c1954026d..0d994d3af8 100644
--- a/tests/regressiontests/comment_tests/tests/comment_view_tests.py
+++ b/tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -101,13 +101,43 @@ class CommentViewTests(CommentTestCase):
settings.DEBUG = olddebug
def testCreateValidComment(self):
+ address = "1.2.3.4"
a = Article.objects.get(pk=1)
data = self.getValidData(a)
- self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
+ self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
self.assertEqual(self.response.status_code, 302)
self.assertEqual(Comment.objects.count(), 1)
c = Comment.objects.all()[0]
- self.assertEqual(c.ip_address, "1.2.3.4")
+ self.assertEqual(c.ip_address, address)
+ self.assertEqual(c.comment, "This is my comment")
+
+ def testCreateValidCommentIPv6(self):
+ """
+ Test creating a valid comment with a long IPv6 address.
+ Note that this test should fail when Comment.ip_address is an IPAddress instead of a GenericIPAddress,
+ but does not do so on SQLite or PostgreSQL, because they use the TEXT and INET types, which already
+ allow storing an IPv6 address internally.
+ """
+ address = "2a02::223:6cff:fe8a:2e8a"
+ a = Article.objects.get(pk=1)
+ data = self.getValidData(a)
+ self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
+ self.assertEqual(self.response.status_code, 302)
+ self.assertEqual(Comment.objects.count(), 1)
+ c = Comment.objects.all()[0]
+ self.assertEqual(c.ip_address, address)
+ self.assertEqual(c.comment, "This is my comment")
+
+ def testCreateValidCommentIPv6Unpack(self):
+ address = "::ffff:18.52.18.52"
+ a = Article.objects.get(pk=1)
+ data = self.getValidData(a)
+ self.response = self.client.post("/post/", data, REMOTE_ADDR=address)
+ self.assertEqual(self.response.status_code, 302)
+ self.assertEqual(Comment.objects.count(), 1)
+ c = Comment.objects.all()[0]
+ # We trim the '::ffff:' bit off because it is an IPv4 addr
+ self.assertEqual(c.ip_address, address[7:])
self.assertEqual(c.comment, "This is my comment")
def testPostAsAuthenticatedUser(self):