MCPcopy
hub / github.com/cherrypy/cherrypy / testParams

Method testParams

cherrypy/test/test_request_obj.py:348–391  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

346 self.assertBody('/pathinfo/foo/bar')
347
348 def testParams(self):
349 self.getPage('/params/?thing=a')
350 self.assertBody(repr(ntou('a')))
351
352 self.getPage('/params/?thing=a&thing=b&thing=c')
353 self.assertBody(repr([ntou('a'), ntou('b'), ntou('c')]))
354
355 # Test friendly error message when given params are not accepted.
356 cherrypy.config.update({'request.show_mismatched_params': True})
357 self.getPage('/params/?notathing=meeting')
358 self.assertInBody('Missing parameters: thing')
359 self.getPage('/params/?thing=meeting&notathing=meeting')
360 self.assertInBody('Unexpected query string parameters: notathing')
361
362 # Test ability to turn off friendly error messages
363 cherrypy.config.update({'request.show_mismatched_params': False})
364 self.getPage('/params/?notathing=meeting')
365 self.assertInBody('Not Found')
366 self.getPage('/params/?thing=meeting&notathing=meeting')
367 self.assertInBody('Not Found')
368
369 # Test "% HEX HEX"-encoded URL, param keys, and values
370 self.getPage('/params/%d4%20%e3/cheese?Gruy%E8re=Bulgn%e9ville')
371 self.assertBody('args: %s kwargs: %s' %
372 (('\xd4 \xe3', 'cheese'),
373 [('Gruy\xe8re', ntou('Bulgn\xe9ville'))]))
374
375 # Make sure that encoded = and & get parsed correctly
376 self.getPage(
377 '/params/code?url=http%3A//cherrypy.dev/index%3Fa%3D1%26b%3D2')
378 self.assertBody('args: %s kwargs: %s' %
379 (('code',),
380 [('url', ntou('http://cherrypy.dev/index?a=1&b=2'))]))
381
382 # Test coordinates sent by <img ismap>
383 self.getPage('/params/ismap?223,114')
384 self.assertBody('Coordinates: 223, 114')
385
386 # Test "name[key]" dict-like params
387 self.getPage('/params/dictlike?a[1]=1&a[2]=2&b=foo&b[bar]=baz')
388 self.assertBody('args: %s kwargs: %s' %
389 (('dictlike',),
390 [('a[1]', ntou('1')), ('a[2]', ntou('2')),
391 ('b', ntou('foo')), ('b[bar]', ntou('baz'))]))
392
393 def testParamErrors(self):
394

Callers

nothing calls this directly

Calls 3

ntouFunction · 0.90
getPageMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected