test_database.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test Database."""
  18. from unittest.mock import patch
  19. import pytest
  20. from pydolphinscheduler.core.database import Database
  21. TEST_DATABASE_DATASOURCE_NAME = "test_datasource"
  22. TEST_DATABASE_TYPE_KEY = "type"
  23. TEST_DATABASE_KEY = "datasource"
  24. @pytest.mark.parametrize(
  25. "expect",
  26. [
  27. {
  28. TEST_DATABASE_TYPE_KEY: "mock_type",
  29. TEST_DATABASE_KEY: 1,
  30. }
  31. ],
  32. )
  33. @patch(
  34. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  35. return_value=(123, 1),
  36. )
  37. @patch(
  38. "pydolphinscheduler.core.database.Database.get_database_info",
  39. return_value=({"id": 1, "type": "mock_type"}),
  40. )
  41. def test_get_datasource_detail(mock_datasource, mock_code_version, expect):
  42. """Test :func:`get_database_type` and :func:`get_database_id` can return expect value."""
  43. database_info = Database(
  44. TEST_DATABASE_DATASOURCE_NAME, TEST_DATABASE_TYPE_KEY, TEST_DATABASE_KEY
  45. )
  46. assert expect == database_info