test_select.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import pytest
  2. from pytest import mark, raises
  3. from bottle import template
  4. @mark.parametrize('expected, params', [
  5. ("""<div class="pure-u-1">
  6. <label for="select-id">Choose: </label>
  7. <select id="select-id" name="select-name" size=10 multiple style="width: calc(100% - 1em); margin: 0 1em 1em">
  8. <option value="hint" disabled >hint</option>
  9. <optgroup label="Group">
  10. <option value="val1-to-backend" >val1</option>
  11. <option value="val2" disabled >val2</option>
  12. </optgroup>
  13. </select>
  14. </div>""", {
  15. "id": "select-id", "label": "Choose: ", "name": "select-name",
  16. "hint": "hint", "multiple": True, "children": [{"optgroup": "Group", "options": [
  17. {
  18. "value": "val1-to-backend",
  19. "display": "val1",
  20. },
  21. {
  22. "value": "val2",
  23. "disabled": True,
  24. }, ]}, ]}),
  25. ("""<div class="pure-u-1">
  26. <select id="select-unit-id" name="unit" size=10 style="width: calc(100% - 1em); margin: 0 1em 1em">
  27. <option value="val1" >val1</option>
  28. <option value="val2" selected>val2</option>
  29. </select>
  30. </div>""",{
  31. "id": "select-unit-id", "name": "unit", "children": [{ "options": [
  32. {
  33. "value": "val1",
  34. },
  35. {
  36. "value": "val2",
  37. "selected": True,
  38. }, ]}, ]}),
  39. ("""<div class="pure-u-1">
  40. <label for="select-id">Choose: </label>
  41. <select id="select-id" name="select-name" size=10 multiple style="width: calc(100% - 1em); margin: 0 1em 1em">
  42. <option value="hint" disabled >hint</option>
  43. <optgroup label="Group">
  44. <option value="val1-to-backend" >val1</option>
  45. <option value="val2" disabled >val2</option>
  46. </optgroup>
  47. <option value="val1" >val1</option>
  48. <option value="val2" selected>val2</option>
  49. </select>
  50. </div>""",{
  51. "id": "select-id", "label": "Choose: ", "name": "select-name",
  52. "hint": "hint", "multiple": True, "children": [
  53. {"optgroup": "Group", "options": [
  54. {
  55. "value": "val1-to-backend",
  56. "display": "val1",
  57. },
  58. {
  59. "value": "val2",
  60. "disabled": True,
  61. }
  62. ]},
  63. { "options": [
  64. {
  65. "value": "val1",
  66. },
  67. {
  68. "value": "val2",
  69. "selected": True,
  70. },
  71. ]},
  72. ]})
  73. ])
  74. def test_select_render_exact(expected, params):
  75. assert template('select', **params) == expected