What's the difference between assertIn and assertContains?

64 views
Skip to first unread message

Pepsodent Cola

unread,
Oct 28, 2013, 8:45:17 PM10/28/13
to django...@googlegroups.com
    # List word
    def test_VIEW_Index_WORD_List_word(self):
        w = self.create_word()
        url = reverse('navi_polls:index')
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertIn(w.rosword, resp.content) # What's the difference between
                                                               # assertIn and assertContains?
        #self.assertContains(resp, "Test word")
        self.assertContains(resp, w.rosword)


test_VIEW_Index_WORD_List_word (navi_polls.tests.WordTests) ... ok



What's the difference between assertIn and assertContains?
They seem to perform the same kind of test, the only difference I can see is that the syntax differs.


Simon Charette

unread,
Oct 28, 2013, 9:42:53 PM10/28/13
to django...@googlegroups.com
assertContains performs additional assertion such as the status code of the
request and provides a way to perform comparison based on HTML semantic
instead of character-by-character equality. Under the hood it also handles
streaming and deferred response gracefully.

I suggest you take a look at the documentation for a technical reference and
at the source code for the implementation details.

Simon
Reply all
Reply to author
Forward
0 new messages