test_handlers.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import json
  17. # import os
  18. import pytest
  19. from tornado.httpclient import HTTPClientError
  20. from elyra.tests.contents.test_utils import expected_response
  21. from elyra.tests.contents.test_utils import expected_response_empty
  22. from elyra.tests.util.handlers_utils import expected_http_error
  23. async def test_file_not_found(jp_fetch):
  24. filepath = "nofile.py"
  25. with pytest.raises(HTTPClientError) as e:
  26. await jp_fetch("elyra", "contents/properties", filepath)
  27. assert expected_http_error(e, 404)
  28. async def test_file_is_not_directory(jp_fetch, create_directory, directory_name):
  29. with pytest.raises(HTTPClientError) as e:
  30. await jp_fetch("elyra", "contents/properties", directory_name)
  31. assert expected_http_error(e, 400)
  32. async def test_invalid_post_request(jp_fetch, create_python_file, python_filename):
  33. response = await jp_fetch("elyra", "contents/properties", python_filename, body=json.dumps(""), method="POST")
  34. response_body = json.loads(response.body)
  35. assert response_body["title"] == "Operation not supported."
  36. async def test_invalid_file_type(jp_fetch, create_text_file, text_filename):
  37. response = await jp_fetch("elyra", "contents/properties", text_filename)
  38. assert response.code == 200
  39. assert json.loads(response.body) == expected_response_empty
  40. async def test_valid_notebook(jp_fetch, create_notebook_file):
  41. response = await jp_fetch("elyra", "contents/properties", create_notebook_file)
  42. assert response.code == 200
  43. assert json.loads(response.body) == expected_response
  44. async def test_valid_python_file(jp_fetch, create_python_file):
  45. response = await jp_fetch("elyra", "contents/properties", create_python_file)
  46. assert response.code == 200
  47. assert json.loads(response.body) == expected_response
  48. async def test_valid_r_file(jp_fetch, create_r_file):
  49. response = await jp_fetch("elyra", "contents/properties", create_r_file)
  50. assert response.code == 200
  51. assert json.loads(response.body) == expected_response
  52. async def test_empty_notebook(jp_fetch, create_empty_notebook_file):
  53. response = await jp_fetch("elyra", "contents/properties", create_empty_notebook_file)
  54. assert response.code == 200
  55. assert json.loads(response.body) == expected_response_empty