Opened 9 years ago

Closed 9 years ago

Last modified 4 years ago

#25780 closed Cleanup/optimization (fixed)

Remove redundant response.status_code assertions in tests

Reported by: Tim Graham Owned by: Alex Morozov
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

self.assertContains(response, '...') also checks the response's status code. There are a lot of places (in the admin_views tests is the place I noticed it) where there's a redundant assertion that verifies self.assertEqual(response.status_code, 200).

Change History (5)

comment:1 by Alex Morozov, 9 years ago

Owner: changed from nobody to Alex Morozov
Status: newassigned

@timgraham, are you talking about these? Could there be a situation when a view fails but still returns the wanted text? If not, I'll try to remove 'em.

(django)inductor@pushino-gw:~/.virtualenvs/django/src/tests$ ag 'self.assertEqual\(response.status.{0,100}\s*self.assertContains' .

generic_views/test_base.py
250: self.assertEqual(response.status_code, 200)
251: self.assertContains(response, '<h1>About</h1>')

test_client/tests.py
732: self.assertEqual(response.status_code, 200)
733: self.assertContains(response, 'This is a test')
743: self.assertEqual(response.status_code, 200)
744: self.assertContains(response, echoed_request_line)

flatpages_tests/test_middleware.py
60: self.assertEqual(response.status_code, 200)
61: self.assertContains(response, "<p>Isn't it flat!</p>")
75: self.assertEqual(response.status_code, 200)
76: self.assertContains(response, "<p>Isn't it sekrit!</p>")
81: self.assertEqual(response.status_code, 200)
82: self.assertContains(response, "<p>Isn't it flat!</p>")
96: self.assertEqual(response.status_code, 200)
97: self.assertContains(response, "<p>Isn't it sekrit!</p>")
111: self.assertEqual(response.status_code, 200)
112: self.assertContains(response, "<p>Isn't it special!</p>")
179: self.assertEqual(response.status_code, 200)
180: self.assertContains(response, "<p>Root</p>")

flatpages_tests/test_views.py
60: self.assertEqual(response.status_code, 200)
61: self.assertContains(response, "<p>Isn't it flat!</p>")
75: self.assertEqual(response.status_code, 200)
76: self.assertContains(response, "<p>Isn't it sekrit!</p>")
100: self.assertEqual(response.status_code, 200)
101: self.assertContains(response, "<p>Isn't it special!</p>")

flatpages_tests/test_csrf.py
60: self.assertEqual(response.status_code, 200)
61: self.assertContains(response, "<p>Isn't it flat!</p>")
75: self.assertEqual(response.status_code, 200)
76: self.assertContains(response, "<p>Isn't it sekrit!</p>")
81: self.assertEqual(response.status_code, 200)
82: self.assertContains(response, "<p>Isn't it flat!</p>")

admin_inlines/tests.py
495: self.assertEqual(response.status_code, 200)
496: self.assertContains(response, "Deleting chapter %s would require deleting "

template_tests/test_response.py
329: self.assertEqual(response.status_code, 200)
330: self.assertContains(response, 'This is where you can find the snark: /snark/')

view_tests/tests/test_i18n.py
211: self.assertEqual(response.status_code, 200)
212: self.assertContains(response, 'emoji')

admin_custom_urls/tests.py
65: self.assertEqual(response.status_code, 200)
66: self.assertContains(response, 'value="My Action"')
78: self.assertEqual(response.status_code, 200)
79: self.assertContains(response, 'dismissAddRelatedObjectPopup')
91: self.assertEqual(response.status_code, 200)
92: self.assertContains(response, 'Change action')
99: self.assertEqual(response.status_code, 200)
100: self.assertContains(response, 'Change action')

admin_views/tests.py
230: self.assertEqual(response.status_code, 200)
231: self.assertContains(response, 'value="My Section"',
295: self.assertEqual(response.status_code, 200)
296: self.assertContains(response, 'dismissAddRelatedObjectPopup')
515: self.assertEqual(response.status_code, 200)
516: self.assertContains(response, '<div id="changelist-filter">',
524: self.assertEqual(response.status_code, 200)
525: self.assertContains(response, '<div id="changelist-filter">')
685: self.assertEqual(response.status_code, 200)
686: self.assertContains(response, 'employeeperson_ptrexact')
1734: self.assertEqual(response.status_code, 200)
1735: self.assertContains(response, 'login-form')
1738: self.assertEqual(response.status_code, 200)
1739: self.assertContains(response, 'login-form')
1741: self.assertEqual(response.status_code, 200)
1742: self.assertContains(response, 'login-form')
1745: self.assertEqual(response.status_code, 200)
1746: self.assertContains(response, 'login-form')
1823: self.assertEqual(response.status_code, 200)
1824: self.assertContains(response, 'login-form')
1827: self.assertEqual(response.status_code, 200)
1828: self.assertContains(response, 'login-form')
4460: self.assertEqual(response.status_code, 200)
4461: self.assertContains(response, "id: '#id_slug',")
4467: self.assertEqual(response.status_code, 200)
4468: self.assertContains(response, "A Long Title")
4882: self.assertEqual(response.status_code, 200)
4883: self.assertContains(response, '<p class="help">Overridden help text for the date</p>')
5128: self.assertEqual(response.status_code, 200)
5129: self.assertContains(response, reverse('admin:auth_user_add'))
5143: self.assertEqual(response.status_code, 200)
5144: self.assertContains(response, 'dismissAddRelatedObjectPopup')
5149: self.assertEqual(response.status_code, 200)
5150: self.assertContains(response, reverse('admin:auth_user_change', args=('fk',)))
5170: self.assertEqual(response.status_code, 200)
5171: self.assertContains(response, 'dismissChangeRelatedObjectPopup')
5176: self.assertEqual(response.status_code, 200)
5177: self.assertContains(response, reverse('admin:auth_user_delete', args=('fk',)))
5188: self.assertEqual(response.status_code, 200)
5189: self.assertContains(response, 'dismissDeleteRelatedObjectPopup')
5332: self.assertEqual(response.status_code, 200)
5333: self.assertContains(response,
5341: self.assertEqual(response.status_code, 200)
5342: self.assertContains(response,
5352: self.assertEqual(response.status_code, 200)
5353: self.assertContains(response,
5361: self.assertEqual(response.status_code, 200)
5362: self.assertContains(response, '<body class=" dashboard app-admin_views')
5376: self.assertEqual(response.status_code, 200)
5377: self.assertContains(response,

handlers/tests.py
185: self.assertEqual(response.status_code, 404)
186: self.assertContains(response, '~%A9helloworld', status_code=404)
189: self.assertEqual(response.status_code, 404)
190: self.assertContains(response, 'd%AAo%AAw%AAn%AAl%AAo%AAa%AAd%AA', status_code=404)
193: self.assertEqual(response.status_code, 404)
194: self.assertContains(response, '%E2%99\u2665', status_code=404)
197: self.assertEqual(response.status_code, 404)
198: self.assertContains(response, '\u260e%E2%A9\u2665', status_code=404)

comment:2 by Tim Graham, 9 years ago

Correct - thanks!

comment:4 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 13dba4db:

Fixed #25780 -- Removed redundant status code assertions from tests

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In cee93c6b:

Refs #25780 -- Removed redundant status code assertions from tests.

Note: See TracTickets for help on using tickets.
Back to Top