def test_non_js_post_workflow(self):
""" Post to a view ensuring that the response is like the normal 'get' response, but with
the thumber success message, and that a populated Feedback model is created.
"""
view_name = 'thumber_tests:example_form'
path = reverse(view_name)
http_referer = 'http://example.com{0}'.format(path)
# Get the form view, and 'follow' so that the session cookie gets set on the client
response = self.client.get(path, follow=True)
self.assertIn(settings.SESSION_COOKIE_NAME, response.cookies)
# Post the thumber form, and get the same page but with teh success message
data = {'satisfied': 'True', 'comment': 'test comment', 'thumber_token': 'sync'}
response = self.client.post(path, data, HTTP_REFERER=http_referer)
self.assertContains(response, 'Thank you for your feedback', status_code=200)
# Check that a Feedback model was created with the correct details
self.assertEquals(Feedback.objects.count(), 1)
feedback = Feedback.objects.all()[0]
self.assertEquals(feedback.view_name, view_name)
self.assertEquals(feedback.url, http_referer)
self.assertEquals(feedback.satisfied, True)
self.assertEquals(feedback.comment, 'test comment')
评论列表
文章目录