test_du.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import inspect
  12. from taipy.gui import Gui, Markdown
  13. def test_du_table_data_fetched(gui: Gui, helpers, csvdata):
  14. # Bind test variables
  15. csvdata = csvdata
  16. # set gui frame
  17. gui._set_frame(inspect.currentframe())
  18. Gui._set_timezone("UTC")
  19. # Bind a page so that the variable will be evaluated as expression
  20. gui.add_page(
  21. "test",
  22. Markdown(
  23. "<|{csvdata}|table|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>" # noqa: E501
  24. ),
  25. )
  26. gui.run(run_server=False)
  27. flask_client = gui._server.test_client()
  28. # WS client and emit
  29. ws_client = gui._server._ws.test_client(gui._server.get_flask())
  30. sid = helpers.create_scope_and_get_sid(gui)
  31. # Get the jsx once so that the page will be evaluated -> variable will be registered
  32. flask_client.get(f"/taipy-jsx/test?client_id={sid}")
  33. ws_client.emit(
  34. "message",
  35. {
  36. "client_id": sid,
  37. "type": "DU",
  38. "name": "_TpD_tpec_TpExPr_csvdata_TPMDL_0",
  39. "payload": {
  40. "columns": ["Day", "Entity", "Code", "Daily hospital occupancy"],
  41. "pagekey": "0-100-asc",
  42. "start": 0,
  43. "end": 9,
  44. "orderby": "",
  45. "sort": "asc",
  46. },
  47. },
  48. )
  49. # assert for received message (message that would be sent to the front-end client)
  50. received_messages = ws_client.get_received()
  51. assert received_messages
  52. helpers.assert_outward_ws_message(
  53. received_messages[0],
  54. "MU",
  55. "_TpD_tpec_TpExPr_csvdata_TPMDL_0",
  56. {
  57. "data": [
  58. {
  59. "Code": "AUT",
  60. "Day_str": "2020-04-01T00:00:00.000000Z",
  61. "Daily hospital occupancy": 856,
  62. "Entity": "Austria",
  63. "_tp_index": 0,
  64. },
  65. {
  66. "Code": "AUT",
  67. "Day_str": "2020-04-02T00:00:00.000000Z",
  68. "Daily hospital occupancy": 823,
  69. "Entity": "Austria",
  70. "_tp_index": 1,
  71. },
  72. {
  73. "Code": "AUT",
  74. "Day_str": "2020-04-03T00:00:00.000000Z",
  75. "Daily hospital occupancy": 829,
  76. "Entity": "Austria",
  77. "_tp_index": 2,
  78. },
  79. {
  80. "Code": "AUT",
  81. "Day_str": "2020-04-04T00:00:00.000000Z",
  82. "Daily hospital occupancy": 826,
  83. "Entity": "Austria",
  84. "_tp_index": 3,
  85. },
  86. {
  87. "Code": "AUT",
  88. "Day_str": "2020-04-05T00:00:00.000000Z",
  89. "Daily hospital occupancy": 712,
  90. "Entity": "Austria",
  91. "_tp_index": 4,
  92. },
  93. {
  94. "Code": "AUT",
  95. "Day_str": "2020-04-06T00:00:00.000000Z",
  96. "Daily hospital occupancy": 824,
  97. "Entity": "Austria",
  98. "_tp_index": 5,
  99. },
  100. {
  101. "Code": "AUT",
  102. "Day_str": "2020-04-07T00:00:00.000000Z",
  103. "Daily hospital occupancy": 857,
  104. "Entity": "Austria",
  105. "_tp_index": 6,
  106. },
  107. {
  108. "Code": "AUT",
  109. "Day_str": "2020-04-08T00:00:00.000000Z",
  110. "Daily hospital occupancy": 829,
  111. "Entity": "Austria",
  112. "_tp_index": 7,
  113. },
  114. {
  115. "Code": "AUT",
  116. "Day_str": "2020-04-09T00:00:00.000000Z",
  117. "Daily hospital occupancy": 820,
  118. "Entity": "Austria",
  119. "_tp_index": 8,
  120. },
  121. {
  122. "Code": "AUT",
  123. "Day_str": "2020-04-10T00:00:00.000000Z",
  124. "Daily hospital occupancy": 771,
  125. "Entity": "Austria",
  126. "_tp_index": 9,
  127. },
  128. ],
  129. "rowcount": 14477,
  130. "start": 0,
  131. "format": "JSON",
  132. },
  133. )