Kaydet (Commit) a0f8c52a authored tarafından Jon Dufresne's avatar Jon Dufresne Kaydeden (comit) Tim Graham

Fixed ResourceWarnings in tests/servers/tests.py.

e.g. ResourceWarning: unclosed <socket.socket [closed] fd=6, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
üst ed244199
...@@ -69,6 +69,7 @@ class LiveServerViews(LiveServerBase): ...@@ -69,6 +69,7 @@ class LiveServerViews(LiveServerBase):
def test_404(self): def test_404(self):
with self.assertRaises(HTTPError) as err: with self.assertRaises(HTTPError) as err:
self.urlopen('/') self.urlopen('/')
err.exception.close()
self.assertEqual(err.exception.code, 404, 'Expected 404 response') self.assertEqual(err.exception.code, 404, 'Expected 404 response')
def test_view(self): def test_view(self):
...@@ -87,6 +88,7 @@ class LiveServerViews(LiveServerBase): ...@@ -87,6 +88,7 @@ class LiveServerViews(LiveServerBase):
""" """
with self.assertRaises(HTTPError) as err: with self.assertRaises(HTTPError) as err:
self.urlopen('/static/another_app/another_app_static_file.txt') self.urlopen('/static/another_app/another_app_static_file.txt')
err.exception.close()
self.assertEqual(err.exception.code, 404, 'Expected 404 response') self.assertEqual(err.exception.code, 404, 'Expected 404 response')
def test_media_files(self): def test_media_files(self):
...@@ -111,7 +113,8 @@ class LiveServerDatabase(LiveServerBase): ...@@ -111,7 +113,8 @@ class LiveServerDatabase(LiveServerBase):
""" """
Data written to the database by a view can be read. Data written to the database by a view can be read.
""" """
self.urlopen('/create_model_instance/') with self.urlopen('/create_model_instance/'):
pass
self.assertQuerysetEqual( self.assertQuerysetEqual(
Person.objects.all().order_by('pk'), Person.objects.all().order_by('pk'),
['jane', 'robert', 'emily'], ['jane', 'robert', 'emily'],
......
...@@ -29,11 +29,12 @@ def subview(request): ...@@ -29,11 +29,12 @@ def subview(request):
def subview_calling_view(request): def subview_calling_view(request):
response = urlopen(request.GET['url'] + '/subview/') with urlopen(request.GET['url'] + '/subview/') as response:
return HttpResponse('subview calling view: {}'.format(response.read().decode())) return HttpResponse('subview calling view: {}'.format(response.read().decode()))
def check_model_instance_from_subview(request): def check_model_instance_from_subview(request):
urlopen(request.GET['url'] + '/create_model_instance/') with urlopen(request.GET['url'] + '/create_model_instance/'):
response = urlopen(request.GET['url'] + '/model_view/') pass
return HttpResponse('subview calling view: {}'.format(response.read().decode())) with urlopen(request.GET['url'] + '/model_view/') as response:
return HttpResponse('subview calling view: {}'.format(response.read().decode()))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment