Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Fixed #19483 -- Improved import error message in contrib.comm…

…ents

Thanks Valentin Lorentz for the report and the suggested fix.
Backport of ed711c4 from master.
  • Loading branch information...
commit 0bbc7c2b4921919ae989c6335be3b25676c6c40f 1 parent 53b40d7
Claude Paroz authored December 16, 2012
4  django/contrib/comments/__init__.py
@@ -20,9 +20,9 @@ def get_comment_app():
20 20
     # Try to import the package
21 21
     try:
22 22
         package = import_module(comments_app)
23  
-    except ImportError:
  23
+    except ImportError as e:
24 24
         raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
25  
-                                   "a non-existing package.")
  25
+                                   "a non-existing package. (%s)" % e)
26 26
 
27 27
     return package
28 28
 
27  tests/regressiontests/comment_tests/tests/app_api_tests.py
@@ -4,6 +4,9 @@
4 4
 from django.contrib import comments
5 5
 from django.contrib.comments.models import Comment
6 6
 from django.contrib.comments.forms import CommentForm
  7
+from django.core.exceptions import ImproperlyConfigured
  8
+from django.test.utils import override_settings
  9
+from django.utils import six
7 10
 
8 11
 from . import CommentTestCase
9 12
 
@@ -14,6 +17,14 @@ class CommentAppAPITests(CommentTestCase):
14 17
     def testGetCommentApp(self):
15 18
         self.assertEqual(comments.get_comment_app(), comments)
16 19
 
  20
+    @override_settings(
  21
+        COMMENTS_APP='missing_app',
  22
+        INSTALLED_APPS=list(settings.INSTALLED_APPS) + ['missing_app'],
  23
+    )
  24
+    def testGetMissingCommentApp(self):
  25
+        with six.assertRaisesRegex(self, ImproperlyConfigured, 'missing_app'):
  26
+            _ = comments.get_comment_app()
  27
+
17 28
     def testGetForm(self):
18 29
         self.assertEqual(comments.get_form(), CommentForm)
19 30
 
@@ -33,20 +44,14 @@ def getGetApproveURL(self):
33 44
         self.assertEqual(comments.get_approve_url(c), "/approve/12345/")
34 45
 
35 46
 
  47
+@override_settings(
  48
+    COMMENTS_APP='regressiontests.comment_tests.custom_comments',
  49
+    INSTALLED_APPS=list(settings.INSTALLED_APPS) + [
  50
+        'regressiontests.comment_tests.custom_comments'],
  51
+)
36 52
 class CustomCommentTest(CommentTestCase):
37 53
     urls = 'regressiontests.comment_tests.urls'
38 54
 
39  
-    def setUp(self):
40  
-        self.old_comments_app = getattr(settings, 'COMMENTS_APP', None)
41  
-        settings.COMMENTS_APP = 'regressiontests.comment_tests.custom_comments'
42  
-        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + [settings.COMMENTS_APP,]
43  
-
44  
-    def tearDown(self):
45  
-        del settings.INSTALLED_APPS[-1]
46  
-        settings.COMMENTS_APP = self.old_comments_app
47  
-        if settings.COMMENTS_APP is None:
48  
-            del settings._wrapped.COMMENTS_APP
49  
-
50 55
     def testGetCommentApp(self):
51 56
         from regressiontests.comment_tests import custom_comments
52 57
         self.assertEqual(comments.get_comment_app(), custom_comments)

0 notes on commit 0bbc7c2

Please sign in to comment.
Something went wrong with that request. Please try again.