﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37205	Replace assertIsInstance HttpResponse test assertions as do not fail if result is a subclass	Jonathan Biemond	Jonathan Biemond	"Tests in the Django test suite that use `self.assertIsInstance()` to check if a response is an `HttpResponse` will pass for any object that is a subclass of `HttpResponse`, such as `HttpResponseNotAllowed`. This can lead to uncaught errors when the expectation is that the result is only and exactly `HttpResponse`.

For example the following test will continue to pass after these changes:
{{{#!div
  {{{#!diff
     def test_require_http_methods_methods(self):
-        @require_http_methods([""GET"", ""PUT""])
+        @require_http_methods([""PUT""])
         def my_view(request):
             return HttpResponse(""OK"")

         request = HttpRequest()
         request.method = ""GET""
         self.assertIsInstance(my_view(request), HttpResponse)
         request.method = ""POST""
         self.assertIsInstance(my_view(request), HttpResponseNotAllowed)
  }}}
}}}

Both responses are `HttpResponseNotAllowed` and both assert statements are true.
Majority of occurrences may be found here: https://github.com/django/django/blob/main/tests/decorators/test_http.py"	Cleanup/optimization	assigned	Core (Other)	dev	Normal		tests, internal		Accepted	0	0	0	0	0	0
