I have a simple test:
def test_project_info_form_post_submission(self):
"""
Test if project info form can be submitted via post.
"""
# set up our POST data
post_data = {
'zipcode': '90210',
'module': self.module1.pk,
'model': self.model1.pk,
'orientation': 1,
'tilt': 1,
'rails_direction': 1,
}
...
response = self.client.post(reverse(url), post_data)
self.assertEqual(response.status_code, 302)
# test empty form
response = self.client.post(reverse(url))
self.assertEqual(response.status_code, 200)
#! test for general form error message
# now test invalid responses
post_data['zipcode'] = 'abcdefg'
response = self.client.post(reverse(url), post_data)
self.assertEqual(response.status_code, 200)
#! test for specific error message associated with zipcode
So the lines I am having trouble with are marked with shebangs. I know I should have messages in the context variable but can’t seem to figure out the right ones to use.
You can test if the template contains your message in your TestCase with
assertContains.