test_loaders.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (c) 2012-2013 LiuYC https://github.com/liuyichen/
  2. # Copyright 2012-2014 ksyun.com, Inc. or its affiliates. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"). You
  5. # may not use this file except in compliance with the License. A copy of
  6. # the License is located at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # or in the "license" file accompanying this file. This file is
  11. # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. # ANY KIND, either express or implied. See the License for the specific
  13. # language governing permissions and limitations under the License.
  14. import os
  15. from tests import unittest
  16. import mock
  17. import kscore.session
  18. # Basic sanity checks for loader functionality.
  19. # We're not using BaseEnvVar here because we don't actually
  20. # want to patch out all of os.environ, we just want to ensure
  21. # AWS_DATA_PATH doesn't affect our test results.
  22. class TestLoaderBasicFunctionality(unittest.TestCase):
  23. def setUp(self):
  24. self.environ = os.environ.copy()
  25. self.patched = mock.patch('os.environ', self.environ)
  26. self.patched.start()
  27. self.environ.pop('KS_DATA_PATH', None)
  28. self.session = kscore.session.get_session()
  29. self.loader = self.session.get_component('data_loader')
  30. def tearDown(self):
  31. self.patched.stop()
  32. def test_search_path_has_at_least_one_entry(self):
  33. self.assertTrue(len(self.loader.search_paths) > 0)
  34. def test_can_list_available_services(self):
  35. # We don't want an exact check, as this list changes over time.
  36. # We just need a basic sanity check.
  37. available_services = self.loader.list_available_services(
  38. type_name='service-2')
  39. self.assertIn('kog', available_services)
  40. def test_can_determine_latest_version(self):
  41. api_versions = self.loader.list_api_versions(
  42. service_name='kog', type_name='service-2')
  43. self.assertEqual(
  44. self.loader.determine_latest_version(
  45. service_name='kog', type_name='service-2'),
  46. max(api_versions))
  47. def test_can_load_data(self):
  48. api_version = self.loader.determine_latest_version(
  49. service_name='kog', type_name='service-2')
  50. data = self.loader.load_data(
  51. os.path.join('kog', api_version, 'service-2'))
  52. self.assertIn('metadata', data)