1
- from django .test import SimpleTestCase , TestCase , RequestFactory
1
+ from django .test import SimpleTestCase , TestCase , RequestFactory , override_settings
2
2
from django .http import HttpRequest
3
3
from ..views import SignupView
4
4
from app import settings
5
5
6
6
7
+ @override_settings (STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' )
7
8
class AddCSSTemplateTagTest (SimpleTestCase ):
8
9
9
10
def test_rendered (self ):
@@ -13,6 +14,7 @@ def test_rendered(self):
13
14
self .assertInHTML (needle , str (SignupView .as_view ()(request , as_string = True ).content ))
14
15
15
16
17
+ @override_settings (STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' )
16
18
class ViewsTest (SimpleTestCase ):
17
19
"""Class for testing views"""
18
20
@@ -52,12 +54,17 @@ def test_signup_not_allowed(self):
52
54
self .assertEqual (response .status_code , 302 )
53
55
54
56
57
+ @override_settings (STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' )
55
58
class ViewsDBTest (TestCase ):
56
59
"""Class for testing views with DB queries"""
57
60
58
61
def test_form_submission (self ):
59
62
self .factory = RequestFactory ()
60
- EMAIL_BACKEND = settings .EMAIL_BACKEND
63
+ if hasattr (settings , 'EMAIL_BACKEND' ):
64
+ EMAIL_BACKEND = settings .EMAIL_BACKEND
65
+ else :
66
+ EMAIL_BACKEND = False
67
+
61
68
settings .EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
62
69
request = self .factory .post ('/signup' )
63
70
request .POST = {'username' : 'username5648' ,
@@ -67,5 +74,8 @@ def test_form_submission(self):
67
74
}
68
75
response = SignupView .as_view ()(request )
69
76
needle = '<span>emailed you instructions to activate your account</span>'
70
- settings .EMAIL_BACKEND = EMAIL_BACKEND
77
+ if not EMAIL_BACKEND :
78
+ delattr (settings , 'EMAIL_BACKEND' )
79
+ else :
80
+ settings .EMAIL_BACKEND = EMAIL_BACKEND
71
81
self .assertInHTML (needle , str (response .content ))
0 commit comments