test_cycle.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from unittest import mock
  12. from flask import url_for
  13. def test_get_cycle(client, default_cycle):
  14. # test 404
  15. cycle_url = url_for("api.cycle_by_id", cycle_id="foo")
  16. rep = client.get(cycle_url)
  17. assert rep.status_code == 404
  18. with mock.patch("taipy.core.cycle._cycle_manager._CycleManager._get") as manager_mock:
  19. manager_mock.return_value = default_cycle
  20. # test get_cycle
  21. rep = client.get(url_for("api.cycle_by_id", cycle_id="foo"))
  22. assert rep.status_code == 200
  23. def test_delete_cycle(client):
  24. # test 404
  25. cycle_url = url_for("api.cycle_by_id", cycle_id="foo")
  26. rep = client.get(cycle_url)
  27. assert rep.status_code == 404
  28. with mock.patch("taipy.core.cycle._cycle_manager._CycleManager._delete"), mock.patch(
  29. "taipy.core.cycle._cycle_manager._CycleManager._get"
  30. ):
  31. # test get_cycle
  32. rep = client.delete(url_for("api.cycle_by_id", cycle_id="foo"))
  33. assert rep.status_code == 200
  34. def test_create_cycle(client, cycle_data):
  35. # without config param
  36. cycles_url = url_for("api.cycles")
  37. data = {"bad": "data"}
  38. rep = client.post(cycles_url, json=data)
  39. assert rep.status_code == 400
  40. rep = client.post(cycles_url, json=cycle_data)
  41. assert rep.status_code == 201
  42. def test_get_all_cycles(client, create_cycle_list):
  43. cycles_url = url_for("api.cycles")
  44. rep = client.get(cycles_url)
  45. assert rep.status_code == 200
  46. results = rep.get_json()
  47. assert len(results) == 10