details: https://code.tryton.org/communication/website/commit/37057a81fff4
branch: default
user: Cédric Krier <[email protected]>
date: Wed Nov 04 09:43:46 2026 +0100
description:
Close response when testing the app
diffstat:
tests/test_app.py | 67 ++++++++++++++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 32 deletions(-)
diffs (97 lines):
diff -r 85a25ca70f3b -r 37057a81fff4 tests/test_app.py
--- a/tests/test_app.py Tue Nov 03 14:21:41 2026 +0100
+++ b/tests/test_app.py Wed Nov 04 09:43:46 2026 +0100
@@ -1,5 +1,6 @@
import os
import unittest
+from contextlib import closing
from http import HTTPStatus
import html5lib
@@ -59,8 +60,8 @@
src = el.attrib['src']
if src.startswith(app.static_url_path):
with self.subTest(src=src):
- response = self.client.get(src)
- self.assertEqual(response.status_code, HTTPStatus.OK)
+ with closing(self.client.get(src)) as response:
+ self.assertEqual(response.status_code, HTTPStatus.OK)
def assertHref(self, document):
if not TEST_HREF:
@@ -98,43 +99,45 @@
continue
if 'GET' in rule.methods and not rule.arguments:
with self.subTest(endpoint=rule.endpoint):
- response = self.client.get(app.url_for(rule.endpoint))
-
- if 200 <= response.status_code < 300:
- if response.mimetype == 'test/html':
- document = self.parser.parse(response.data)
- self.assertStatic(document)
- self.assertHref(document)
- elif 300 <= response.status_code < 400:
- self.assertIn('Location', response.headers)
- pass
- else:
- self.fail(f"status code: {response.status_code}")
+ with closing(
+ self.client.get(app.url_for(rule.endpoint))
+ ) as response:
+ if 200 <= response.status_code < 300:
+ if response.mimetype == 'test/html':
+ document = self.parser.parse(response.data)
+ self.assertStatic(document)
+ self.assertHref(document)
+ elif 300 <= response.status_code < 400:
+ self.assertIn('Location', response.headers)
+ pass
+ else:
+ self.fail(f"status code: {response.status_code}")
def test_success_stories(self):
for endpoint, arguments in success_story_generator():
with self.subTest(endpoint=endpoint, arguments=arguments):
- response = self.client.get(app.url_for(endpoint, **arguments))
-
- self.assertEqual(response.status_code, HTTPStatus.OK)
- self.assertEqual(response.mimetype, 'text/html')
- document = self.parser.parse(response.data)
- self.assertStatic(document)
- self.assertHref(document)
+ with closing(
+ self.client.get(app.url_for(endpoint, **arguments))
+ ) as response:
+ self.assertEqual(response.status_code, HTTPStatus.OK)
+ self.assertEqual(response.mimetype, 'text/html')
+ document = self.parser.parse(response.data)
+ self.assertStatic(document)
+ self.assertHref(document)
def test_events(self):
for event in ['tum2019', 'tsd2019', 'tsd2021']:
with self.subTest(event=event):
- response = self.client.get(app.url_for('event', event=event))
-
- self.assertEqual(response.status_code, HTTPStatus.OK)
- self.assertEqual(response.mimetype, 'text/html')
- document = self.parser.parse(response.data)
- self.assertStatic(document)
- self.assertHref(document)
+ with closing(
+ self.client.get(app.url_for('event', event=event))
+ ) as response:
+ self.assertEqual(response.status_code, HTTPStatus.OK)
+ self.assertEqual(response.mimetype, 'text/html')
+ document = self.parser.parse(response.data)
+ self.assertStatic(document)
+ self.assertHref(document)
def test_robots(self):
- response = self.client.get('/robots.txt')
-
- self.assertEqual(response.status_code, HTTPStatus.OK)
- self.assertEqual(response.mimetype, 'text/plain')
+ with closing(self.client.get('/robots.txt')) as response:
+ self.assertEqual(response.status_code, HTTPStatus.OK)
+ self.assertEqual(response.mimetype, 'text/plain')