Просмотр исходного кода

Add unit tests for the `cache.py` module

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 лет назад
Родитель
Сommit
fe0467c548
1 измененных файлов с 31 добавлено и 0 удалено
  1. 31 0
      coriolis/tests/test_cache.py

+ 31 - 0
coriolis/tests/test_cache.py

@@ -0,0 +1,31 @@
+# Copyright 2023 Cloudbase Solutions Srl
+# All Rights Reserved.
+
+from unittest import mock
+from coriolis import exception
+from coriolis import cache
+from coriolis.tests import test_base
+
+
+class CacheTestCase(test_base.CoriolisBaseTestCase):
+    """Collection of tests for the Coriolis cache package."""
+
+    @mock.patch.object(cache.cache, 'get_memoization_decorator')
+    def test_get_cache_decorator(self, mock_get_memoization_decorator):
+        provider = 'ValidProviderName'
+        result = cache.get_cache_decorator(provider)
+
+        self.assertEqual(result, mock_get_memoization_decorator.return_value)
+        mock_get_memoization_decorator.assert_called_once_with(
+            cache.CONF,
+            cache.cache_region,
+            provider
+        )
+
+    def test_get_cache_decorator_invalid_provider_name(self):
+        invalid_providers = [123, '', None]
+
+        for provider in invalid_providers:
+            self.assertRaises(exception.CoriolisException,
+                              cache.get_cache_decorator,
+                              provider)