conftest.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 pytest
  17. from elyra.metadata.manager import MetadataManager
  18. from elyra.metadata.schema import METADATA_TEST_SCHEMASPACE
  19. from elyra.metadata.schema import SchemaManager
  20. from elyra.tests.metadata.test_utils import another_metadata_json
  21. from elyra.tests.metadata.test_utils import byo_metadata_json
  22. from elyra.tests.metadata.test_utils import create_instance
  23. from elyra.tests.metadata.test_utils import create_json_file
  24. from elyra.tests.metadata.test_utils import invalid_json
  25. from elyra.tests.metadata.test_utils import invalid_metadata_json
  26. from elyra.tests.metadata.test_utils import invalid_schema_name_json
  27. from elyra.tests.metadata.test_utils import valid_metadata_json
  28. def mkdir(tmp_path, *parts):
  29. path = tmp_path.joinpath(*parts)
  30. if not path.exists():
  31. path.mkdir(parents=True)
  32. return path
  33. # These location fixtures will need to be revisited once we support multiple metadata storage types.
  34. schemaspace_location = pytest.fixture(lambda jp_data_dir: mkdir(jp_data_dir, "metadata", METADATA_TEST_SCHEMASPACE))
  35. bogus_location = pytest.fixture(lambda jp_data_dir: mkdir(jp_data_dir, "metadata", "bogus"))
  36. shared_location = pytest.fixture(
  37. lambda jp_system_jupyter_path: mkdir(jp_system_jupyter_path, "metadata", METADATA_TEST_SCHEMASPACE)
  38. )
  39. factory_location = pytest.fixture(
  40. lambda jp_env_jupyter_path: mkdir(jp_env_jupyter_path, "metadata", METADATA_TEST_SCHEMASPACE)
  41. )
  42. @pytest.fixture
  43. def setup_data(schemaspace_location):
  44. create_json_file(schemaspace_location, "valid.json", valid_metadata_json)
  45. create_json_file(schemaspace_location, "another.json", another_metadata_json)
  46. create_json_file(schemaspace_location, "invalid.json", invalid_metadata_json)
  47. @pytest.fixture
  48. def setup_hierarchy(jp_environ, factory_location):
  49. # Only populate factory info
  50. byo_instance = byo_metadata_json
  51. byo_instance["display_name"] = "factory"
  52. create_json_file(factory_location, "byo_1.json", byo_instance)
  53. create_json_file(factory_location, "byo_2.json", byo_instance)
  54. create_json_file(factory_location, "byo_3.json", byo_instance)
  55. @pytest.fixture
  56. def store_manager(tests_manager):
  57. return tests_manager.metadata_store
  58. @pytest.fixture(
  59. params=["elyra.metadata.storage.FileMetadataStore", "elyra.tests.metadata.test_utils.MockMetadataStore"]
  60. ) # Add types as needed
  61. def tests_manager(jp_environ, schemaspace_location, request):
  62. metadata_mgr = MetadataManager(schemaspace=METADATA_TEST_SCHEMASPACE, metadata_store_class=request.param)
  63. store_mgr = metadata_mgr.metadata_store
  64. create_instance(store_mgr, schemaspace_location, "valid", valid_metadata_json)
  65. create_instance(store_mgr, schemaspace_location, "another", another_metadata_json)
  66. create_instance(store_mgr, schemaspace_location, "invalid", invalid_metadata_json)
  67. create_instance(store_mgr, schemaspace_location, "bad", invalid_json)
  68. create_instance(store_mgr, schemaspace_location, "invalid_schema_name", invalid_schema_name_json)
  69. return metadata_mgr
  70. @pytest.fixture
  71. def tests_hierarchy_manager(setup_hierarchy): # Only uses FileMetadataStore for storage right now.
  72. return MetadataManager(schemaspace=METADATA_TEST_SCHEMASPACE)
  73. @pytest.fixture
  74. def schema_manager():
  75. schema_manager = SchemaManager.instance()
  76. yield schema_manager
  77. SchemaManager.clear_instance()
  78. # Set Elyra server extension as enabled (overriding server_config fixture from jupyter_server)
  79. @pytest.fixture
  80. def jp_server_config():
  81. return {"ServerApp": {"jpserver_extensions": {"elyra": True}}}