comparison test/test_cgi.py @ 8592:363a6bb5a6ae default tip

test: add subtest support to testTokenlessCsrfProtection Make each list driven test case a subtest of its own. Add pytest-subtest pip module to make this work.
author John Rouillard <rouilj@ieee.org>
date Tue, 21 Apr 2026 12:55:19 -0400
parents 501eb8088ea3
children
comparison
equal deleted inserted replaced
8591:501eb8088ea3 8592:363a6bb5a6ae
217 classes = '|'.join(self.db.classes.keys()) 217 classes = '|'.join(self.db.classes.keys())
218 self.FV_SPECIAL = re.compile(FormParser.FV_LABELS%classes, 218 self.FV_SPECIAL = re.compile(FormParser.FV_LABELS%classes,
219 re.VERBOSE) 219 re.VERBOSE)
220 220
221 @pytest.fixture(autouse=True) 221 @pytest.fixture(autouse=True)
222 def inject_fixtures(self, caplog, monkeypatch): 222 def inject_fixtures(self, caplog, monkeypatch, subtests):
223 """Used to add pytest test fixtures to unittest based tests
224 because adding the name of a fixture to a method does not
225 make the method available.
226
227 So the decrorator runs with autouse=True to set params on
228 the unittest "self" making the fixtures available for
229 tests.
230
231 If you need another fixture, just add it to the argument list
232 and assign it to self and pytest will make it available.
233 """
234
223 self._caplog = caplog 235 self._caplog = caplog
224 self._monkeypatch = monkeypatch 236 self._monkeypatch = monkeypatch
237 self._subtests = subtests
225 238
226 # 239 #
227 # form label extraction 240 # form label extraction
228 # 241 #
229 def tl(self, s, c, i, a, p): 242 def tl(self, s, c, i, a, p):
1205 'allowed_api_origins'] 1218 'allowed_api_origins']
1206 else: 1219 else:
1207 cl.db.config['WEB_ALLOWED_API_ORIGINS'] = "" 1220 cl.db.config['WEB_ALLOWED_API_ORIGINS'] = ""
1208 1221
1209 cl.main() 1222 cl.main()
1210 self.assertIn(test['Result'], out[0]) 1223
1211 1224 # make each case above a subtest
1212 if "response_code" in test: 1225 with self._subtests.test(entry=entry):
1213 self.assertEqual(test['response_code'], cl.response_code) 1226 self.assertIn(test['Result'], out[0])
1227
1228 if "response_code" in test:
1229 self.assertEqual(test['response_code'], cl.response_code)
1214 1230
1215 del(out[0]) 1231 del(out[0])
1216 1232
1217 # get request with nonce 1233 # get request with nonce
1218 cl.env = {"PATH_INFO": "/"} 1234 cl.env = {"PATH_INFO": "/"}

Roundup Issue Tracker: http://roundup-tracker.org/