test_catalog_connector.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. from pathlib import Path
  17. from elyra.pipeline.catalog_connector import UrlComponentCatalogConnector
  18. def test_url_connector_valid_get_entry_data():
  19. """
  20. Validate that UrlComponentCatalogConnector.get_entry_data(...) returns
  21. the expected results
  22. """
  23. # Test valid "file://" inputs
  24. test_conn = UrlComponentCatalogConnector([".yaml"])
  25. resource_location = Path(__file__).parent / "resources" / "components" / "download_data.yaml"
  26. resource_url = resource_location.as_uri()
  27. ed = test_conn.get_entry_data({"url": resource_url}, {"display_name": "file://is-valid-test"})
  28. assert ed is not None
  29. with open(resource_location, "r") as source:
  30. assert ed.definition == source.read()
  31. def test_url_connector_invalid_get_entry_data():
  32. """
  33. Validate that UrlComponentCatalogConnector.get_entry_data(...) returns
  34. the expected results for invalid inputs
  35. """
  36. # Test invalid "file://" inputs ...
  37. # ... input refers to a directory
  38. test_conn = UrlComponentCatalogConnector([".yaml"])
  39. resource_location = Path(__file__).parent / "resources" / "components"
  40. resource_url = resource_location.as_uri()
  41. ed = test_conn.get_entry_data({"url": resource_url}, {"display_name": "file://is-a-dir-test"})
  42. assert ed is None, resource_url
  43. # ... input refers to a non-existing file
  44. test_conn = UrlComponentCatalogConnector([".yaml"])
  45. resource_location = Path(__file__).parent / "resources" / "components" / "no-such-file.yaml"
  46. resource_url = resource_location.as_uri()
  47. ed = test_conn.get_entry_data({"url": resource_url}, {"display_name": "file://no-such-file-test"})
  48. assert ed is None, resource_url