@@ -49,23 +49,22 @@ def get_email_headers(self):
4949
5050
5151class BaseEmailFormMixinTests (test .TestCase ):
52- @mock .patch ('django.template.loader.render_to_string' )
53- def test_get_message_returns_rendered_message_template (
54- self , render_to_string ):
55- context = {'message' : 'an example message.' }
52+
53+ def test_get_message_returns_rendered_message_template (self ):
54+ context = {'body' : 'an example message.' , "name" : "tester" , "email" : "a@b.com" }
5655
5756 class TestForm (forms .BaseEmailFormMixin ):
58- message_template_name = "my_template.html "
57+ message_template_name = "contact_form/email_template.txt "
5958
6059 def get_context (self ):
6160 return context
6261
6362 form = TestForm ()
6463
6564 message = form .get_message ()
66- self .assertEqual ( render_to_string . return_value , message )
67- render_to_string . assert_called_once_with ( form . message_template_name ,
68- context )
65+ self .assertIn ( "an example message." , message )
66+ self . assertIn ( "a@b.com" , message )
67+ self . assertIn ( "tester" , message )
6968
7069 @mock .patch ('django.template.loader.render_to_string' )
7170 def test_get_subject_returns_single_line_rendered_subject_template (
@@ -238,3 +237,22 @@ def test_has_valid_message_template(self):
238237 template_exists = 0
239238 self .assertTrue (template_exists ,
240239 "Email message template does not exist" )
240+
241+
242+ class BasicContactFormTests (test .TestCase ):
243+
244+ def test_basic_contact_form_get_message_dict_shows_rendered_template_values (self ):
245+ form = forms .BasicContactForm (data = {"name" : "Tester" , "email" : "a@b.com" , "body" : "Contact Me!" })
246+ form .request = test .RequestFactory ().get ("/" )
247+ message_dict = form .get_message_dict ()
248+
249+ self .assertIn ("Contact Me!" , message_dict ['body' ])
250+ self .assertIn ("Tester" , message_dict ['body' ])
251+ self .assertIn ("a@b.com" , message_dict ['body' ])
252+
253+ def test_basic_contact_form_get_message_dict_shows_subject_from_template (self ):
254+ form = forms .BasicContactForm (data = {"name" : "Tester" , "email" : "a@b.com" , "body" : "Contact Me!" })
255+ form .request = test .RequestFactory ().get ("/" )
256+ message_dict = form .get_message_dict ()
257+
258+ self .assertIn ("Contact request received" , message_dict ['subject' ])
0 commit comments