-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the
cache.py
module
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
- Loading branch information
1 parent
64d86bf
commit 153bdeb
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 TestGetCacheDecoratorTestCase(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) |