summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-02-23 22:16:26 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-02-23 22:16:26 +0000
commit63d85a684ac713b74a8ea5fee3757139229e45a5 (patch)
tree0d0828536fbf2e29695e6c7baf0f316144053f83 /tests
parent7d4a954836069d740d24101078cfadb4580533c2 (diff)
Fixed #8630: finished the custom comment app API that was left out of 1.0. This means it's now possible to override any of the models, forms, or views used by the comment app; see the new custom comment app docs for details and an example. Thanks to Thejaswi Puthraya for the original patch, and to carljm for docs and tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9890 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/comment_tests/custom_comments/__init__.py32
-rw-r--r--tests/regressiontests/comment_tests/custom_comments/forms.py4
-rw-r--r--tests/regressiontests/comment_tests/custom_comments/models.py4
-rw-r--r--tests/regressiontests/comment_tests/custom_comments/views.py13
-rw-r--r--tests/regressiontests/comment_tests/tests/app_api_tests.py41
-rw-r--r--tests/regressiontests/comment_tests/urls.py9
6 files changed, 103 insertions, 0 deletions
diff --git a/tests/regressiontests/comment_tests/custom_comments/__init__.py b/tests/regressiontests/comment_tests/custom_comments/__init__.py
new file mode 100644
index 0000000000..598927eace
--- /dev/null
+++ b/tests/regressiontests/comment_tests/custom_comments/__init__.py
@@ -0,0 +1,32 @@
+from django.core import urlresolvers
+from regressiontests.comment_tests.custom_comments.models import CustomComment
+from regressiontests.comment_tests.custom_comments.forms import CustomCommentForm
+
+def get_model():
+ return CustomComment
+
+def get_form():
+ return CustomCommentForm
+
+def get_form_target():
+ return urlresolvers.reverse(
+ "regressiontests.comment_tests.custom_comments.views.custom_submit_comment"
+ )
+
+def get_flag_url(c):
+ return urlresolvers.reverse(
+ "regressiontests.comment_tests.custom_comments.views.custom_flag_comment",
+ args=(c.id,)
+ )
+
+def get_delete_url(c):
+ return urlresolvers.reverse(
+ "regressiontests.comment_tests.custom_comments.views.custom_delete_comment",
+ args=(c.id,)
+ )
+
+def get_approve_url(c):
+ return urlresolvers.reverse(
+ "regressiontests.comment_tests.custom_comments.views.custom_approve_comment",
+ args=(c.id,)
+ )
diff --git a/tests/regressiontests/comment_tests/custom_comments/forms.py b/tests/regressiontests/comment_tests/custom_comments/forms.py
new file mode 100644
index 0000000000..b788cdcf29
--- /dev/null
+++ b/tests/regressiontests/comment_tests/custom_comments/forms.py
@@ -0,0 +1,4 @@
+from django import forms
+
+class CustomCommentForm(forms.Form):
+ pass
diff --git a/tests/regressiontests/comment_tests/custom_comments/models.py b/tests/regressiontests/comment_tests/custom_comments/models.py
new file mode 100644
index 0000000000..592ad79586
--- /dev/null
+++ b/tests/regressiontests/comment_tests/custom_comments/models.py
@@ -0,0 +1,4 @@
+from django.db import models
+
+class CustomComment(models.Model):
+ pass
diff --git a/tests/regressiontests/comment_tests/custom_comments/views.py b/tests/regressiontests/comment_tests/custom_comments/views.py
new file mode 100644
index 0000000000..93cea9d591
--- /dev/null
+++ b/tests/regressiontests/comment_tests/custom_comments/views.py
@@ -0,0 +1,13 @@
+from django.http import HttpResponse
+
+def custom_submit_comment(request):
+ return HttpResponse("Hello from the custom submit comment view.")
+
+def custom_flag_comment(request, comment_id):
+ return HttpResponse("Hello from the custom flag view.")
+
+def custom_delete_comment(request, comment_id):
+ return HttpResponse("Hello from the custom delete view.")
+
+def custom_approve_comment(request, comment_id):
+ return HttpResponse("Hello from the custom approve view.")
diff --git a/tests/regressiontests/comment_tests/tests/app_api_tests.py b/tests/regressiontests/comment_tests/tests/app_api_tests.py
index d4a4488ab5..6a9eb1c637 100644
--- a/tests/regressiontests/comment_tests/tests/app_api_tests.py
+++ b/tests/regressiontests/comment_tests/tests/app_api_tests.py
@@ -28,3 +28,44 @@ class CommentAppAPITests(CommentTestCase):
c = Comment(id=12345)
self.assertEqual(comments.get_approve_url(c), "/approve/12345/")
+
+class CustomCommentTest(CommentTestCase):
+ urls = 'regressiontests.comment_tests.urls'
+
+ def setUp(self):
+ self.old_comments_app = getattr(settings, 'COMMENTS_APP', None)
+ settings.COMMENTS_APP = 'regressiontests.comment_tests.custom_comments'
+ settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + [settings.COMMENTS_APP,]
+
+ def tearDown(self):
+ del settings.INSTALLED_APPS[-1]
+ settings.COMMENTS_APP = self.old_comments_app
+ if settings.COMMENTS_APP is None:
+ delattr(settings._target, 'COMMENTS_APP')
+
+ def testGetCommentApp(self):
+ from regressiontests.comment_tests import custom_comments
+ self.assertEqual(comments.get_comment_app(), custom_comments)
+
+ def testGetModel(self):
+ from regressiontests.comment_tests.custom_comments.models import CustomComment
+ self.assertEqual(comments.get_model(), CustomComment)
+
+ def testGetForm(self):
+ from regressiontests.comment_tests.custom_comments.forms import CustomCommentForm
+ self.assertEqual(comments.get_form(), CustomCommentForm)
+
+ def testGetFormTarget(self):
+ self.assertEqual(comments.get_form_target(), "/post/")
+
+ def testGetFlagURL(self):
+ c = Comment(id=12345)
+ self.assertEqual(comments.get_flag_url(c), "/flag/12345/")
+
+ def getGetDeleteURL(self):
+ c = Comment(id=12345)
+ self.assertEqual(comments.get_delete_url(c), "/delete/12345/")
+
+ def getGetApproveURL(self):
+ c = Comment(id=12345)
+ self.assertEqual(comments.get_approve_url(c), "/approve/12345/")
diff --git a/tests/regressiontests/comment_tests/urls.py b/tests/regressiontests/comment_tests/urls.py
new file mode 100644
index 0000000000..0058689657
--- /dev/null
+++ b/tests/regressiontests/comment_tests/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('regressiontests.comment_tests.custom_comments.views',
+ url(r'^post/$', 'custom_submit_comment'),
+ url(r'^flag/(\d+)/$', 'custom_flag_comment'),
+ url(r'^delete/(\d+)/$', 'custom_delete_comment'),
+ url(r'^approve/(\d+)/$', 'custom_approve_comment'),
+)
+