diff options
| author | Chinmoy Chakraborty <chinmoy12c@gmail.com> | 2023-10-02 23:16:21 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-10-03 10:44:36 +0200 |
| commit | 1dae65dc63ae84be5002c37b4ddae0b9220e8808 (patch) | |
| tree | 7f541e24d9b7816e8f6edf6fcb5a676ffb56d345 /tests/test_utils | |
| parent | 54d9d26ebfc90711430a79219d6547141ce1717f (diff) | |
Fixed #34657 -- Made assert(Not)Contains/assertInHTML display haystacks in error messages.
Diffstat (limited to 'tests/test_utils')
| -rw-r--r-- | tests/test_utils/tests.py | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 95526f768f..7df81650d5 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -985,12 +985,18 @@ class HTMLEqualTests(SimpleTestCase): class InHTMLTests(SimpleTestCase): def test_needle_msg(self): - msg = "False is not true : Couldn't find '<b>Hello</b>' in response" + msg = ( + "False is not true : Couldn't find '<b>Hello</b>' in the following " + "response\n'<p>Test</p>'" + ) with self.assertRaisesMessage(AssertionError, msg): self.assertInHTML("<b>Hello</b>", "<p>Test</p>") def test_msg_prefix(self): - msg = "False is not true : Prefix: Couldn't find '<b>Hello</b>' in response" + msg = ( + "False is not true : Prefix: Couldn't find '<b>Hello</b>' in the following " + 'response\n\'<input type="text" name="Hello" />\'' + ) with self.assertRaisesMessage(AssertionError, msg): self.assertInHTML( "<b>Hello</b>", @@ -1000,8 +1006,9 @@ class InHTMLTests(SimpleTestCase): def test_count_msg_prefix(self): msg = ( - "2 != 1 : Prefix: Found 2 instances of '<b>Hello</b>' in response " - "(expected 1)" + "2 != 1 : Prefix: Found 2 instances of '<b>Hello</b>' (expected 1) in the " + "following response\n'<b>Hello</b><b>Hello</b>'" + "" ) with self.assertRaisesMessage(AssertionError, msg): self.assertInHTML( @@ -1011,6 +1018,38 @@ class InHTMLTests(SimpleTestCase): msg_prefix="Prefix", ) + def test_base(self): + haystack = "<p><b>Hello</b> <span>there</span>! Hi <span>there</span>!</p>" + + self.assertInHTML("<b>Hello</b>", haystack=haystack) + msg = f"Couldn't find '<p>Howdy</p>' in the following response\n{haystack!r}" + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML("<p>Howdy</p>", haystack) + + self.assertInHTML("<span>there</span>", haystack=haystack, count=2) + msg = ( + "Found 1 instances of '<b>Hello</b>' (expected 2) in the following response" + f"\n{haystack!r}" + ) + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML("<b>Hello</b>", haystack=haystack, count=2) + + def test_long_haystack(self): + haystack = ( + "<p>This is a very very very very very very very very long message which " + "exceedes the max limit of truncation.</p>" + ) + msg = f"Couldn't find '<b>Hello</b>' in the following response\n{haystack!r}" + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML("<b>Hello</b>", haystack) + + msg = ( + "Found 0 instances of '<b>This</b>' (expected 3) in the following response" + f"\n{haystack!r}" + ) + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML("<b>This</b>", haystack, 3) + class JSONEqualTests(SimpleTestCase): def test_simple_equal(self): |
