test_du.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright 2023 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 unittest.mock import patch
  13. from taipy.gui import Gui, Markdown
  14. def test_du_table_data_fetched(gui: Gui, helpers, csvdata):
  15. # Bind test variables
  16. csvdata = csvdata
  17. # set gui frame
  18. gui._set_frame(inspect.currentframe())
  19. Gui._set_timezone("UTC")
  20. # Bind a page so that the variable will be evaluated as expression
  21. gui.add_page(
  22. "test",
  23. Markdown(
  24. "<|{csvdata}|table|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>"
  25. ),
  26. )
  27. with patch("sys.argv", ["prog"]):
  28. gui.run(run_server=False)
  29. flask_client = gui._server.test_client()
  30. # WS client and emit
  31. ws_client = gui._server._ws.test_client(gui._server.get_flask())
  32. sid = helpers.create_scope_and_get_sid(gui)
  33. # Get the jsx once so that the page will be evaluated -> variable will be registered
  34. flask_client.get(f"/taipy-jsx/test?client_id={sid}")
  35. ws_client.emit(
  36. "message",
  37. {
  38. "client_id": sid,
  39. "type": "DU",
  40. "name": "_TpD_tpec_TpExPr_csvdata_TPMDL_0",
  41. "payload": {
  42. "columns": ["Day", "Entity", "Code", "Daily hospital occupancy"],
  43. "pagekey": "0-100--asc",
  44. "start": 0,
  45. "end": 9,
  46. "orderby": "",
  47. "sort": "asc",
  48. },
  49. },
  50. )
  51. # assert for received message (message that would be sent to the front-end client)
  52. received_messages = ws_client.get_received()
  53. assert received_messages
  54. helpers.assert_outward_ws_message(
  55. received_messages[0],
  56. "MU",
  57. "_TpD_tpec_TpExPr_csvdata_TPMDL_0",
  58. {
  59. "data": [
  60. {
  61. "Code": "AUT",
  62. "Day_str": "2020-04-01T00:00:00.000000Z",
  63. "Daily hospital occupancy": 856,
  64. "Entity": "Austria",
  65. "_tp_index": 0,
  66. },
  67. {
  68. "Code": "AUT",
  69. "Day_str": "2020-04-02T00:00:00.000000Z",
  70. "Daily hospital occupancy": 823,
  71. "Entity": "Austria",
  72. "_tp_index": 1,
  73. },
  74. {
  75. "Code": "AUT",
  76. "Day_str": "2020-04-03T00:00:00.000000Z",
  77. "Daily hospital occupancy": 829,
  78. "Entity": "Austria",
  79. "_tp_index": 2,
  80. },
  81. {
  82. "Code": "AUT",
  83. "Day_str": "2020-04-04T00:00:00.000000Z",
  84. "Daily hospital occupancy": 826,
  85. "Entity": "Austria",
  86. "_tp_index": 3,
  87. },
  88. {
  89. "Code": "AUT",
  90. "Day_str": "2020-04-05T00:00:00.000000Z",
  91. "Daily hospital occupancy": 712,
  92. "Entity": "Austria",
  93. "_tp_index": 4,
  94. },
  95. {
  96. "Code": "AUT",
  97. "Day_str": "2020-04-06T00:00:00.000000Z",
  98. "Daily hospital occupancy": 824,
  99. "Entity": "Austria",
  100. "_tp_index": 5,
  101. },
  102. {
  103. "Code": "AUT",
  104. "Day_str": "2020-04-07T00:00:00.000000Z",
  105. "Daily hospital occupancy": 857,
  106. "Entity": "Austria",
  107. "_tp_index": 6,
  108. },
  109. {
  110. "Code": "AUT",
  111. "Day_str": "2020-04-08T00:00:00.000000Z",
  112. "Daily hospital occupancy": 829,
  113. "Entity": "Austria",
  114. "_tp_index": 7,
  115. },
  116. {
  117. "Code": "AUT",
  118. "Day_str": "2020-04-09T00:00:00.000000Z",
  119. "Daily hospital occupancy": 820,
  120. "Entity": "Austria",
  121. "_tp_index": 8,
  122. },
  123. {
  124. "Code": "AUT",
  125. "Day_str": "2020-04-10T00:00:00.000000Z",
  126. "Daily hospital occupancy": 771,
  127. "Entity": "Austria",
  128. "_tp_index": 9,
  129. },
  130. ],
  131. "rowcount": 14477,
  132. "start": 0,
  133. "format": "JSON",
  134. },
  135. )