Showing
14 changed files
with
60 additions
and
112 deletions
| 1 | language: python | 1 | language: python |
| 2 | env: | 2 | env: |
| 3 | -- TOXENV=py27-django18 | ||
| 4 | -- TOXENV=py34-django18 | ||
| 5 | -- TOXENV=py27-django19 | ||
| 6 | -- TOXENV=py34-django19 | ||
| 7 | -- TOXENV=py27-django110 | ||
| 8 | -- TOXENV=py34-django110 | ||
| 9 | - TOXENV=py27-django111 | 3 | - TOXENV=py27-django111 |
| 10 | - TOXENV=py34-django111 | 4 | - TOXENV=py34-django111 |
| 11 | - TOXENV=py34-django20 | 5 | - TOXENV=py34-django20 |
| 12 | matrix: | 6 | matrix: |
| 13 | include: | 7 | include: |
| 14 | - python: 3.5 | 8 | - python: 3.5 |
| 15 | - env: TOXENV=py35-django-18 | ||
| 16 | - - python: 3.5 | ||
| 17 | - env: TOXENV=py35-django-19 | ||
| 18 | - - python: 3.5 | ||
| 19 | - env: TOXENV=py35-django-110 | ||
| 20 | - - python: 3.5 | ||
| 21 | env: TOXENV=py35-django-111 | 9 | env: TOXENV=py35-django-111 |
| 22 | - python: 3.5 | 10 | - python: 3.5 |
| 23 | env: TOXENV=py35-django-20 | 11 | env: TOXENV=py35-django-20 |
| @@ -8,6 +8,7 @@ X.Y.Z (YYYY-MM-DD) | @@ -8,6 +8,7 @@ X.Y.Z (YYYY-MM-DD) | ||
| 8 | 8 | ||
| 9 | * Added testing for Python 3.6. | 9 | * Added testing for Python 3.6. |
| 10 | * Confirmed support for Django 2.0. | 10 | * Confirmed support for Django 2.0. |
| 11 | +* Dropped support for Django < 1.11. | ||
| 11 | 12 | ||
| 12 | 1.8.0 (2017-02-03) | 13 | 1.8.0 (2017-02-03) |
| 13 | ------------------ | 14 | ------------------ |
| @@ -3,10 +3,7 @@ from importlib import import_module | @@ -3,10 +3,7 @@ from importlib import import_module | ||
| 3 | from django.apps import apps | 3 | from django.apps import apps |
| 4 | from django.conf import settings | 4 | from django.conf import settings |
| 5 | from django.core.exceptions import ImproperlyConfigured | 5 | from django.core.exceptions import ImproperlyConfigured |
| 6 | -try: | ||
| 7 | - from django.urls import reverse | ||
| 8 | -except ImportError: | ||
| 9 | - from django.core.urlresolvers import reverse # Django < 1.10 | 6 | +from django.urls import reverse |
| 10 | 7 | ||
| 11 | 8 | ||
| 12 | DEFAULT_COMMENTS_APP = 'django_comments' | 9 | DEFAULT_COMMENTS_APP = 'django_comments' |
| @@ -5,13 +5,10 @@ from django.contrib.contenttypes.fields import GenericForeignKey | @@ -5,13 +5,10 @@ from django.contrib.contenttypes.fields import GenericForeignKey | ||
| 5 | from django.contrib.contenttypes.models import ContentType | 5 | from django.contrib.contenttypes.models import ContentType |
| 6 | from django.contrib.sites.models import Site | 6 | from django.contrib.sites.models import Site |
| 7 | from django.db import models | 7 | from django.db import models |
| 8 | +from django.urls import reverse | ||
| 8 | from django.utils import timezone | 9 | from django.utils import timezone |
| 9 | from django.utils.encoding import python_2_unicode_compatible | 10 | from django.utils.encoding import python_2_unicode_compatible |
| 10 | from django.utils.translation import ugettext_lazy as _ | 11 | from django.utils.translation import ugettext_lazy as _ |
| 11 | -try: | ||
| 12 | - from django.urls import reverse | ||
| 13 | -except ImportError: | ||
| 14 | - from django.core.urlresolvers import reverse # Django < 1.10 | ||
| 15 | 12 | ||
| 16 | from .managers import CommentManager | 13 | from .managers import CommentManager |
| 17 | 14 | ||
| @@ -61,9 +58,7 @@ class CommentAbstractModel(BaseCommentAbstractModel): | @@ -61,9 +58,7 @@ class CommentAbstractModel(BaseCommentAbstractModel): | ||
| 61 | blank=True, null=True, related_name="%(class)s_comments", | 58 | blank=True, null=True, related_name="%(class)s_comments", |
| 62 | on_delete=models.SET_NULL) | 59 | on_delete=models.SET_NULL) |
| 63 | user_name = models.CharField(_("user's name"), max_length=50, blank=True) | 60 | user_name = models.CharField(_("user's name"), max_length=50, blank=True) |
| 64 | - # Explicit `max_length` to apply both to Django 1.7 and 1.8+. | ||
| 65 | - user_email = models.EmailField(_("user's email address"), max_length=254, | ||
| 66 | - blank=True) | 61 | + user_email = models.EmailField(_("user's email address"), blank=True) |
| 67 | user_url = models.URLField(_("user's URL"), blank=True) | 62 | user_url = models.URLField(_("user's URL"), blank=True) |
| 68 | 63 | ||
| 69 | comment = models.TextField(_('comment'), max_length=COMMENT_MAX_LENGTH) | 64 | comment = models.TextField(_('comment'), max_length=COMMENT_MAX_LENGTH) |
| @@ -40,11 +40,7 @@ def post_comment(request, next=None, using=None): | @@ -40,11 +40,7 @@ def post_comment(request, next=None, using=None): | ||
| 40 | """ | 40 | """ |
| 41 | # Fill out some initial data fields from an authenticated user, if present | 41 | # Fill out some initial data fields from an authenticated user, if present |
| 42 | data = request.POST.copy() | 42 | data = request.POST.copy() |
| 43 | - try: | ||
| 44 | - user_is_authenticated = request.user.is_authenticated() | ||
| 45 | - except TypeError: # Django >= 1.11 | ||
| 46 | - user_is_authenticated = request.user.is_authenticated | ||
| 47 | - if user_is_authenticated: | 43 | + if request.user.is_authenticated: |
| 48 | if not data.get('name', ''): | 44 | if not data.get('name', ''): |
| 49 | data["name"] = request.user.get_full_name() or request.user.get_username() | 45 | data["name"] = request.user.get_full_name() or request.user.get_username() |
| 50 | if not data.get('email', ''): | 46 | if not data.get('email', ''): |
| @@ -107,7 +103,7 @@ def post_comment(request, next=None, using=None): | @@ -107,7 +103,7 @@ def post_comment(request, next=None, using=None): | ||
| 107 | # Otherwise create the comment | 103 | # Otherwise create the comment |
| 108 | comment = form.get_comment_object(site_id=get_current_site(request).id) | 104 | comment = form.get_comment_object(site_id=get_current_site(request).id) |
| 109 | comment.ip_address = request.META.get("REMOTE_ADDR", None) or None | 105 | comment.ip_address = request.META.get("REMOTE_ADDR", None) or None |
| 110 | - if user_is_authenticated: | 106 | + if request.user.is_authenticated: |
| 111 | comment.user = request.user | 107 | comment.user = request.user |
| 112 | 108 | ||
| 113 | # Signal that the comment is about to be saved | 109 | # Signal that the comment is about to be saved |
| @@ -28,7 +28,7 @@ def next_redirect(request, fallback, **get_kwargs): | @@ -28,7 +28,7 @@ def next_redirect(request, fallback, **get_kwargs): | ||
| 28 | Returns an ``HttpResponseRedirect``. | 28 | Returns an ``HttpResponseRedirect``. |
| 29 | """ | 29 | """ |
| 30 | next = request.POST.get('next') | 30 | next = request.POST.get('next') |
| 31 | - if not is_safe_url(url=next, host=request.get_host()): | 31 | + if not is_safe_url(url=next, allowed_hosts={request.get_host()}): |
| 32 | next = resolve_url(fallback) | 32 | next = resolve_url(fallback) |
| 33 | 33 | ||
| 34 | if get_kwargs: | 34 | if get_kwargs: |
| @@ -23,9 +23,6 @@ setup( | @@ -23,9 +23,6 @@ setup( | ||
| 23 | 'Development Status :: 5 - Production/Stable', | 23 | 'Development Status :: 5 - Production/Stable', |
| 24 | 'Environment :: Web Environment', | 24 | 'Environment :: Web Environment', |
| 25 | 'Framework :: Django', | 25 | 'Framework :: Django', |
| 26 | - 'Framework :: Django :: 1.8', | ||
| 27 | - 'Framework :: Django :: 1.9', | ||
| 28 | - 'Framework :: Django :: 1.10', | ||
| 29 | 'Framework :: Django :: 1.11', | 26 | 'Framework :: Django :: 1.11', |
| 30 | 'Framework :: Django :: 2.0', | 27 | 'Framework :: Django :: 2.0', |
| 31 | 'Intended Audience :: Developers', | 28 | 'Intended Audience :: Developers', |
| @@ -42,5 +39,5 @@ setup( | @@ -42,5 +39,5 @@ setup( | ||
| 42 | packages=find_packages(exclude=['tests', 'tests.*']), | 39 | packages=find_packages(exclude=['tests', 'tests.*']), |
| 43 | include_package_data=True, | 40 | include_package_data=True, |
| 44 | test_suite='tests.runtests.main', | 41 | test_suite='tests.runtests.main', |
| 45 | - install_requires=['Django>=1.8'] | 42 | + install_requires=['Django>=1.11'] |
| 46 | ) | 43 | ) |
| @@ -30,11 +30,6 @@ settings.configure( | @@ -30,11 +30,6 @@ settings.configure( | ||
| 30 | 'django.contrib.auth.middleware.AuthenticationMiddleware', | 30 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 31 | 'django.contrib.messages.middleware.MessageMiddleware', | 31 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 32 | ), | 32 | ), |
| 33 | - MIDDLEWARE_CLASSES=( | ||
| 34 | - 'django.contrib.sessions.middleware.SessionMiddleware', | ||
| 35 | - 'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
| 36 | - 'django.contrib.messages.middleware.MessageMiddleware', | ||
| 37 | - ), # Django < 1.10 | ||
| 38 | ROOT_URLCONF='testapp.urls', | 33 | ROOT_URLCONF='testapp.urls', |
| 39 | TEMPLATES=[ | 34 | TEMPLATES=[ |
| 40 | { | 35 | { |
| 1 | from __future__ import absolute_import | 1 | from __future__ import absolute_import |
| 2 | 2 | ||
| 3 | -from django import VERSION | ||
| 4 | from django.contrib.auth.models import User | 3 | from django.contrib.auth.models import User |
| 5 | from django.contrib.contenttypes.models import ContentType | 4 | from django.contrib.contenttypes.models import ContentType |
| 6 | from django.contrib.sites.models import Site | 5 | from django.contrib.sites.models import Site |
| @@ -91,12 +90,3 @@ class CommentTestCase(TestCase): | @@ -91,12 +90,3 @@ class CommentTestCase(TestCase): | ||
| 91 | d = self.getData() | 90 | d = self.getData() |
| 92 | d.update(f.initial) | 91 | d.update(f.initial) |
| 93 | return d | 92 | return d |
| 94 | - | ||
| 95 | - def assertRedirects(self, response, expected_url, **kwargs): | ||
| 96 | - """ | ||
| 97 | - Wrapper for assertRedirects to handle Django pre-1.9. | ||
| 98 | - """ | ||
| 99 | - if VERSION >= (1, 9) and expected_url.startswith('http://testserver'): | ||
| 100 | - expected_url = expected_url[len('http://testserver'):] | ||
| 101 | - return super(CommentTestCase, self).assertRedirects( | ||
| 102 | - response, expected_url, **kwargs) |
| 1 | from __future__ import absolute_import, unicode_literals | 1 | from __future__ import absolute_import, unicode_literals |
| 2 | 2 | ||
| 3 | -import re | ||
| 4 | - | ||
| 5 | from django.conf import settings | 3 | from django.conf import settings |
| 6 | from django.contrib.auth.models import User | 4 | from django.contrib.auth.models import User |
| 7 | 5 | ||
| @@ -12,10 +10,6 @@ from . import CommentTestCase | @@ -12,10 +10,6 @@ from . import CommentTestCase | ||
| 12 | from testapp.models import Article, Book | 10 | from testapp.models import Article, Book |
| 13 | 11 | ||
| 14 | 12 | ||
| 15 | -# Before Django 1.9, the response contained the scheme/netloc parts | ||
| 16 | -post_redirect_re = re.compile(r'^(http://testserver)?/posted/\?c=(?P<pk>\d+$)') | ||
| 17 | - | ||
| 18 | - | ||
| 19 | class CommentViewTests(CommentTestCase): | 13 | class CommentViewTests(CommentTestCase): |
| 20 | 14 | ||
| 21 | def testPostCommentHTTPMethods(self): | 15 | def testPostCommentHTTPMethods(self): |
| @@ -263,35 +257,38 @@ class CommentViewTests(CommentTestCase): | @@ -263,35 +257,38 @@ class CommentViewTests(CommentTestCase): | ||
| 263 | a = Article.objects.get(pk=1) | 257 | a = Article.objects.get(pk=1) |
| 264 | data = self.getValidData(a) | 258 | data = self.getValidData(a) |
| 265 | response = self.client.post("/post/", data) | 259 | response = self.client.post("/post/", data) |
| 266 | - location = response["Location"] | ||
| 267 | - match = post_redirect_re.match(location) | ||
| 268 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | ||
| 269 | - | 260 | + self.assertRedirects( |
| 261 | + response, | ||
| 262 | + '/posted/?c=%s' % Comment.objects.latest('id').pk, | ||
| 263 | + fetch_redirect_response=False, | ||
| 264 | + ) | ||
| 270 | data["next"] = "/somewhere/else/" | 265 | data["next"] = "/somewhere/else/" |
| 271 | data["comment"] = "This is another comment" | 266 | data["comment"] = "This is another comment" |
| 272 | response = self.client.post("/post/", data) | 267 | response = self.client.post("/post/", data) |
| 273 | - location = response["Location"] | ||
| 274 | - match = re.search(r"^(http://testserver)?/somewhere/else/\?c=\d+$", location) | ||
| 275 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | ||
| 276 | - | 268 | + self.assertRedirects( |
| 269 | + response, | ||
| 270 | + '/somewhere/else/?c=%s' % Comment.objects.latest('id').pk, | ||
| 271 | + fetch_redirect_response=False, | ||
| 272 | + ) | ||
| 277 | data["next"] = "http://badserver/somewhere/else/" | 273 | data["next"] = "http://badserver/somewhere/else/" |
| 278 | data["comment"] = "This is another comment with an unsafe next url" | 274 | data["comment"] = "This is another comment with an unsafe next url" |
| 279 | response = self.client.post("/post/", data) | 275 | response = self.client.post("/post/", data) |
| 280 | - location = response["Location"] | ||
| 281 | - match = post_redirect_re.match(location) | ||
| 282 | - self.assertIsNotNone(match, "Unsafe redirection to: %s" % location) | 276 | + self.assertRedirects( |
| 277 | + response, | ||
| 278 | + '/posted/?c=%s' % Comment.objects.latest('id').pk, | ||
| 279 | + fetch_redirect_response=False, | ||
| 280 | + ) | ||
| 283 | 281 | ||
| 284 | def testCommentDoneView(self): | 282 | def testCommentDoneView(self): |
| 285 | a = Article.objects.get(pk=1) | 283 | a = Article.objects.get(pk=1) |
| 286 | data = self.getValidData(a) | 284 | data = self.getValidData(a) |
| 287 | response = self.client.post("/post/", data) | 285 | response = self.client.post("/post/", data) |
| 288 | - location = response["Location"] | ||
| 289 | - match = post_redirect_re.match(location) | ||
| 290 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | ||
| 291 | - pk = int(match.group('pk')) | 286 | + comment = Comment.objects.latest('id') |
| 287 | + location = '/posted/?c=%s' % comment.pk | ||
| 288 | + self.assertRedirects(response, location, fetch_redirect_response=False) | ||
| 292 | response = self.client.get(location) | 289 | response = self.client.get(location) |
| 293 | self.assertTemplateUsed(response, "comments/posted.html") | 290 | self.assertTemplateUsed(response, "comments/posted.html") |
| 294 | - self.assertEqual(response.context["comment"], Comment.objects.get(pk=pk)) | 291 | + self.assertEqual(response.context["comment"], comment) |
| 295 | 292 | ||
| 296 | def testCommentNextWithQueryString(self): | 293 | def testCommentNextWithQueryString(self): |
| 297 | """ | 294 | """ |
| @@ -302,9 +299,11 @@ class CommentViewTests(CommentTestCase): | @@ -302,9 +299,11 @@ class CommentViewTests(CommentTestCase): | ||
| 302 | data["next"] = "/somewhere/else/?foo=bar" | 299 | data["next"] = "/somewhere/else/?foo=bar" |
| 303 | data["comment"] = "This is another comment" | 300 | data["comment"] = "This is another comment" |
| 304 | response = self.client.post("/post/", data) | 301 | response = self.client.post("/post/", data) |
| 305 | - location = response["Location"] | ||
| 306 | - match = re.search(r"^(http://testserver)?/somewhere/else/\?foo=bar&c=\d+$", location) | ||
| 307 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | 302 | + self.assertRedirects( |
| 303 | + response, | ||
| 304 | + '/somewhere/else/?foo=bar&c=%s' % Comment.objects.latest('id').pk, | ||
| 305 | + fetch_redirect_response=False, | ||
| 306 | + ) | ||
| 308 | 307 | ||
| 309 | def testCommentPostRedirectWithInvalidIntegerPK(self): | 308 | def testCommentPostRedirectWithInvalidIntegerPK(self): |
| 310 | """ | 309 | """ |
| @@ -331,9 +330,11 @@ class CommentViewTests(CommentTestCase): | @@ -331,9 +330,11 @@ class CommentViewTests(CommentTestCase): | ||
| 331 | data["next"] = "/somewhere/else/?foo=bar#baz" | 330 | data["next"] = "/somewhere/else/?foo=bar#baz" |
| 332 | data["comment"] = "This is another comment" | 331 | data["comment"] = "This is another comment" |
| 333 | response = self.client.post("/post/", data) | 332 | response = self.client.post("/post/", data) |
| 334 | - location = response["Location"] | ||
| 335 | - match = re.search(r"^(http://testserver)?/somewhere/else/\?foo=bar&c=\d+#baz$", location) | ||
| 336 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | 333 | + self.assertRedirects( |
| 334 | + response, | ||
| 335 | + '/somewhere/else/?foo=bar&c=%s#baz' % Comment.objects.latest('id').pk, | ||
| 336 | + fetch_redirect_response=False, | ||
| 337 | + ) | ||
| 337 | 338 | ||
| 338 | # Without a query string | 339 | # Without a query string |
| 339 | a = Article.objects.get(pk=1) | 340 | a = Article.objects.get(pk=1) |
| @@ -341,6 +342,8 @@ class CommentViewTests(CommentTestCase): | @@ -341,6 +342,8 @@ class CommentViewTests(CommentTestCase): | ||
| 341 | data["next"] = "/somewhere/else/#baz" | 342 | data["next"] = "/somewhere/else/#baz" |
| 342 | data["comment"] = "This is another comment" | 343 | data["comment"] = "This is another comment" |
| 343 | response = self.client.post("/post/", data) | 344 | response = self.client.post("/post/", data) |
| 344 | - location = response["Location"] | ||
| 345 | - match = re.search(r"^(http://testserver)?/somewhere/else/\?c=\d+#baz$", location) | ||
| 346 | - self.assertIsNotNone(match, "Unexpected redirect location: %s" % location) | 345 | + self.assertRedirects( |
| 346 | + response, | ||
| 347 | + '/somewhere/else/?c=%s#baz' % Comment.objects.latest('id').pk, | ||
| 348 | + fetch_redirect_response=False, | ||
| 349 | + ) |
| @@ -27,7 +27,7 @@ class FlagViewTests(CommentTestCase): | @@ -27,7 +27,7 @@ class FlagViewTests(CommentTestCase): | ||
| 27 | pk = comments[0].pk | 27 | pk = comments[0].pk |
| 28 | self.client.login(username="normaluser", password="normaluser") | 28 | self.client.login(username="normaluser", password="normaluser") |
| 29 | response = self.client.post("/flag/%d/" % pk) | 29 | response = self.client.post("/flag/%d/" % pk) |
| 30 | - self.assertRedirects(response, "http://testserver/flagged/?c=%d" % pk) | 30 | + self.assertRedirects(response, "/flagged/?c=%d" % pk) |
| 31 | c = Comment.objects.get(pk=pk) | 31 | c = Comment.objects.get(pk=pk) |
| 32 | self.assertEqual(c.flags.filter(flag=CommentFlag.SUGGEST_REMOVAL).count(), 1) | 32 | self.assertEqual(c.flags.filter(flag=CommentFlag.SUGGEST_REMOVAL).count(), 1) |
| 33 | return c | 33 | return c |
| @@ -40,8 +40,7 @@ class FlagViewTests(CommentTestCase): | @@ -40,8 +40,7 @@ class FlagViewTests(CommentTestCase): | ||
| 40 | pk = comments[0].pk | 40 | pk = comments[0].pk |
| 41 | self.client.login(username="normaluser", password="normaluser") | 41 | self.client.login(username="normaluser", password="normaluser") |
| 42 | response = self.client.post("/flag/%d/" % pk, {'next': "/go/here/"}) | 42 | response = self.client.post("/flag/%d/" % pk, {'next': "/go/here/"}) |
| 43 | - self.assertRedirects(response, | ||
| 44 | - "http://testserver/go/here/?c=%d" % pk, fetch_redirect_response=False) | 43 | + self.assertRedirects(response, "/go/here/?c=%d" % pk, fetch_redirect_response=False) |
| 45 | 44 | ||
| 46 | def testFlagPostUnsafeNext(self): | 45 | def testFlagPostUnsafeNext(self): |
| 47 | """ | 46 | """ |
| @@ -53,8 +52,7 @@ class FlagViewTests(CommentTestCase): | @@ -53,8 +52,7 @@ class FlagViewTests(CommentTestCase): | ||
| 53 | self.client.login(username="normaluser", password="normaluser") | 52 | self.client.login(username="normaluser", password="normaluser") |
| 54 | response = self.client.post("/flag/%d/" % pk, | 53 | response = self.client.post("/flag/%d/" % pk, |
| 55 | {'next': "http://elsewhere/bad"}) | 54 | {'next': "http://elsewhere/bad"}) |
| 56 | - self.assertRedirects(response, | ||
| 57 | - "http://testserver/flagged/?c=%d" % pk) | 55 | + self.assertRedirects(response, "/flagged/?c=%d" % pk) |
| 58 | 56 | ||
| 59 | def testFlagPostTwice(self): | 57 | def testFlagPostTwice(self): |
| 60 | """Users don't get to flag comments more than once.""" | 58 | """Users don't get to flag comments more than once.""" |
| @@ -69,11 +67,11 @@ class FlagViewTests(CommentTestCase): | @@ -69,11 +67,11 @@ class FlagViewTests(CommentTestCase): | ||
| 69 | pk = comments[0].pk | 67 | pk = comments[0].pk |
| 70 | response = self.client.get("/flag/%d/" % pk) | 68 | response = self.client.get("/flag/%d/" % pk) |
| 71 | self.assertRedirects(response, | 69 | self.assertRedirects(response, |
| 72 | - "http://testserver/accounts/login/?next=/flag/%d/" % pk, | 70 | + "/accounts/login/?next=/flag/%d/" % pk, |
| 73 | fetch_redirect_response=False) | 71 | fetch_redirect_response=False) |
| 74 | response = self.client.post("/flag/%d/" % pk) | 72 | response = self.client.post("/flag/%d/" % pk) |
| 75 | self.assertRedirects(response, | 73 | self.assertRedirects(response, |
| 76 | - "http://testserver/accounts/login/?next=/flag/%d/" % pk, | 74 | + "/accounts/login/?next=/flag/%d/" % pk, |
| 77 | fetch_redirect_response=False) | 75 | fetch_redirect_response=False) |
| 78 | 76 | ||
| 79 | def testFlaggedView(self): | 77 | def testFlaggedView(self): |
| @@ -118,7 +116,7 @@ class DeleteViewTests(CommentTestCase): | @@ -118,7 +116,7 @@ class DeleteViewTests(CommentTestCase): | ||
| 118 | self.client.login(username="normaluser", password="normaluser") | 116 | self.client.login(username="normaluser", password="normaluser") |
| 119 | response = self.client.get("/delete/%d/" % pk) | 117 | response = self.client.get("/delete/%d/" % pk) |
| 120 | self.assertRedirects(response, | 118 | self.assertRedirects(response, |
| 121 | - "http://testserver/accounts/login/?next=/delete/%d/" % pk, | 119 | + "/accounts/login/?next=/delete/%d/" % pk, |
| 122 | fetch_redirect_response=False) | 120 | fetch_redirect_response=False) |
| 123 | 121 | ||
| 124 | makeModerator("normaluser") | 122 | makeModerator("normaluser") |
| @@ -132,7 +130,7 @@ class DeleteViewTests(CommentTestCase): | @@ -132,7 +130,7 @@ class DeleteViewTests(CommentTestCase): | ||
| 132 | makeModerator("normaluser") | 130 | makeModerator("normaluser") |
| 133 | self.client.login(username="normaluser", password="normaluser") | 131 | self.client.login(username="normaluser", password="normaluser") |
| 134 | response = self.client.post("/delete/%d/" % pk) | 132 | response = self.client.post("/delete/%d/" % pk) |
| 135 | - self.assertRedirects(response, "http://testserver/deleted/?c=%d" % pk) | 133 | + self.assertRedirects(response, "/deleted/?c=%d" % pk) |
| 136 | c = Comment.objects.get(pk=pk) | 134 | c = Comment.objects.get(pk=pk) |
| 137 | self.assertTrue(c.is_removed) | 135 | self.assertTrue(c.is_removed) |
| 138 | self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_DELETION, user__username="normaluser").count(), 1) | 136 | self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_DELETION, user__username="normaluser").count(), 1) |
| @@ -147,8 +145,7 @@ class DeleteViewTests(CommentTestCase): | @@ -147,8 +145,7 @@ class DeleteViewTests(CommentTestCase): | ||
| 147 | makeModerator("normaluser") | 145 | makeModerator("normaluser") |
| 148 | self.client.login(username="normaluser", password="normaluser") | 146 | self.client.login(username="normaluser", password="normaluser") |
| 149 | response = self.client.post("/delete/%d/" % pk, {'next': "/go/here/"}) | 147 | response = self.client.post("/delete/%d/" % pk, {'next': "/go/here/"}) |
| 150 | - self.assertRedirects(response, | ||
| 151 | - "http://testserver/go/here/?c=%d" % pk, fetch_redirect_response=False) | 148 | + self.assertRedirects(response, "/go/here/?c=%d" % pk, fetch_redirect_response=False) |
| 152 | 149 | ||
| 153 | def testDeletePostUnsafeNext(self): | 150 | def testDeletePostUnsafeNext(self): |
| 154 | """ | 151 | """ |
| @@ -161,8 +158,7 @@ class DeleteViewTests(CommentTestCase): | @@ -161,8 +158,7 @@ class DeleteViewTests(CommentTestCase): | ||
| 161 | self.client.login(username="normaluser", password="normaluser") | 158 | self.client.login(username="normaluser", password="normaluser") |
| 162 | response = self.client.post("/delete/%d/" % pk, | 159 | response = self.client.post("/delete/%d/" % pk, |
| 163 | {'next': "http://elsewhere/bad"}) | 160 | {'next': "http://elsewhere/bad"}) |
| 164 | - self.assertRedirects(response, | ||
| 165 | - "http://testserver/deleted/?c=%d" % pk) | 161 | + self.assertRedirects(response, "/deleted/?c=%d" % pk) |
| 166 | 162 | ||
| 167 | def testDeleteSignals(self): | 163 | def testDeleteSignals(self): |
| 168 | def receive(sender, **kwargs): | 164 | def receive(sender, **kwargs): |
| @@ -195,7 +191,7 @@ class ApproveViewTests(CommentTestCase): | @@ -195,7 +191,7 @@ class ApproveViewTests(CommentTestCase): | ||
| 195 | response = self.client.get("/approve/%d/" % pk) | 191 | response = self.client.get("/approve/%d/" % pk) |
| 196 | self.assertRedirects( | 192 | self.assertRedirects( |
| 197 | response, | 193 | response, |
| 198 | - "http://testserver/accounts/login/?next=/approve/%d/" % pk, | 194 | + "/accounts/login/?next=/approve/%d/" % pk, |
| 199 | fetch_redirect_response=False | 195 | fetch_redirect_response=False |
| 200 | ) | 196 | ) |
| 201 | 197 | ||
| @@ -212,7 +208,7 @@ class ApproveViewTests(CommentTestCase): | @@ -212,7 +208,7 @@ class ApproveViewTests(CommentTestCase): | ||
| 212 | makeModerator("normaluser") | 208 | makeModerator("normaluser") |
| 213 | self.client.login(username="normaluser", password="normaluser") | 209 | self.client.login(username="normaluser", password="normaluser") |
| 214 | response = self.client.post("/approve/%d/" % c1.pk) | 210 | response = self.client.post("/approve/%d/" % c1.pk) |
| 215 | - self.assertRedirects(response, "http://testserver/approved/?c=%d" % c1.pk) | 211 | + self.assertRedirects(response, "/approved/?c=%d" % c1.pk) |
| 216 | c = Comment.objects.get(pk=c1.pk) | 212 | c = Comment.objects.get(pk=c1.pk) |
| 217 | self.assertTrue(c.is_public) | 213 | self.assertTrue(c.is_public) |
| 218 | self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_APPROVAL, user__username="normaluser").count(), 1) | 214 | self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_APPROVAL, user__username="normaluser").count(), 1) |
| @@ -230,9 +226,7 @@ class ApproveViewTests(CommentTestCase): | @@ -230,9 +226,7 @@ class ApproveViewTests(CommentTestCase): | ||
| 230 | self.client.login(username="normaluser", password="normaluser") | 226 | self.client.login(username="normaluser", password="normaluser") |
| 231 | response = self.client.post("/approve/%d/" % c1.pk, | 227 | response = self.client.post("/approve/%d/" % c1.pk, |
| 232 | {'next': "/go/here/"}) | 228 | {'next': "/go/here/"}) |
| 233 | - self.assertRedirects(response, | ||
| 234 | - "http://testserver/go/here/?c=%d" % c1.pk, | ||
| 235 | - fetch_redirect_response=False) | 229 | + self.assertRedirects(response, "/go/here/?c=%d" % c1.pk, fetch_redirect_response=False) |
| 236 | 230 | ||
| 237 | def testApprovePostUnsafeNext(self): | 231 | def testApprovePostUnsafeNext(self): |
| 238 | """ | 232 | """ |
| @@ -247,8 +241,7 @@ class ApproveViewTests(CommentTestCase): | @@ -247,8 +241,7 @@ class ApproveViewTests(CommentTestCase): | ||
| 247 | self.client.login(username="normaluser", password="normaluser") | 241 | self.client.login(username="normaluser", password="normaluser") |
| 248 | response = self.client.post("/approve/%d/" % c1.pk, | 242 | response = self.client.post("/approve/%d/" % c1.pk, |
| 249 | {'next': "http://elsewhere/bad"}) | 243 | {'next': "http://elsewhere/bad"}) |
| 250 | - self.assertRedirects(response, | ||
| 251 | - "http://testserver/approved/?c=%d" % c1.pk) | 244 | + self.assertRedirects(response, "/approved/?c=%d" % c1.pk) |
| 252 | 245 | ||
| 253 | def testApproveSignals(self): | 246 | def testApproveSignals(self): |
| 254 | def receive(sender, **kwargs): | 247 | def receive(sender, **kwargs): |
| 1 | from django.conf.urls import include, url | 1 | from django.conf.urls import include, url |
| 2 | -from django.contrib.auth.views import login, logout | 2 | +from django.contrib.auth.views import LoginView, LogoutView |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | urlpatterns = [ | 5 | urlpatterns = [ |
| 6 | url(r'^', include('django_comments.urls')), | 6 | url(r'^', include('django_comments.urls')), |
| 7 | 7 | ||
| 8 | # Provide the auth system login and logout views | 8 | # Provide the auth system login and logout views |
| 9 | - url(r'^accounts/login/$', login, {'template_name': 'login.html'}), | ||
| 10 | - url(r'^accounts/logout/$', logout), | 9 | + url(r'^accounts/login/$', LoginView.as_view(template_name='login.html')), |
| 10 | + url(r'^accounts/logout/$', LogoutView.as_view()), | ||
| 11 | ] | 11 | ] |
| 1 | [tox] | 1 | [tox] |
| 2 | envlist = | 2 | envlist = |
| 3 | - py{27,34,35}-django1{8,9,10,11} | 3 | + py{27,34,35,36}-django111 |
| 4 | py{34,35,36}-django20 | 4 | py{34,35,36}-django20 |
| 5 | - py36-django111 | ||
| 6 | py{35,36}-master | 5 | py{35,36}-master |
| 7 | 6 | ||
| 8 | [testenv] | 7 | [testenv] |
| @@ -15,9 +14,6 @@ commands = {envpython} setup.py test | @@ -15,9 +14,6 @@ commands = {envpython} setup.py test | ||
| 15 | setenv= | 14 | setenv= |
| 16 | PYTHONWARNINGS=default | 15 | PYTHONWARNINGS=default |
| 17 | deps= | 16 | deps= |
| 18 | - django-18: Django>=1.8,<1.9 | ||
| 19 | - django-19: Django>=1.9a1,<1.10 | ||
| 20 | - django-110: Django>=1.10,<1.11 | ||
| 21 | django-111: Django>=1.11a1,<2.0 | 17 | django-111: Django>=1.11a1,<2.0 |
| 22 | django-20: Django>=2.0a1,<2.1 | 18 | django-20: Django>=2.0a1,<2.1 |
| 23 | django-master: https://github.com/django/django/archive/master.tar.gz | 19 | django-master: https://github.com/django/django/archive/master.tar.gz |
Please
register
or
login
to post a comment