diff --git a/ironicclient/tests/unit/test_filecache.py b/ironicclient/tests/unit/test_filecache.py index 728629405..237bf9109 100644 --- a/ironicclient/tests/unit/test_filecache.py +++ b/ironicclient/tests/unit/test_filecache.py @@ -54,9 +54,10 @@ class FileCacheTest(utils.BaseTestCase): self.assertEqual(0, mock_exists.call_count) self.assertEqual(0, mock_makedirs.call_count) - @mock.patch.object(filecache, 'CACHE', autospec=True) - def test_save_data_ok(self, mock_cache): - mock_cache.set = mock.Mock(spec=dogpile.cache.region.CacheRegion.set) + @mock.patch.object(dogpile.cache.region, 'CacheRegion', autospec=True) + @mock.patch.object(filecache, '_get_cache', autospec=True) + def test_save_data_ok(self, mock_get_cache, mock_cache): + mock_get_cache.return_value = mock_cache host = 'fred' port = '1234' hostport = '%s:%s' % (host, port) @@ -65,12 +66,13 @@ class FileCacheTest(utils.BaseTestCase): mock_cache.set.assert_called_once_with(hostport, data) @mock.patch.object(os.path, 'isfile', autospec=True) - @mock.patch.object(filecache, 'CACHE', autospec=True) - def test_retrieve_data_ok(self, mock_cache, mock_isfile): + @mock.patch.object(dogpile.cache.region, 'CacheRegion', autospec=True) + @mock.patch.object(filecache, '_get_cache', autospec=True) + def test_retrieve_data_ok(self, mock_get_cache, mock_cache, mock_isfile): s = 'spam' mock_isfile.return_value = True - mock_cache.get = mock.Mock(spec=dogpile.cache.region.CacheRegion.get, - return_value=s) + mock_cache.get.return_value = s + mock_get_cache.return_value = mock_cache host = 'fred' port = '1234' hostport = '%s:%s' % (host, port) @@ -79,12 +81,14 @@ class FileCacheTest(utils.BaseTestCase): self.assertEqual(s, result) @mock.patch.object(os.path, 'isfile', autospec=True) - @mock.patch.object(filecache, 'CACHE', autospec=True) - def test_retrieve_data_ok_with_expiry(self, mock_cache, mock_isfile): + @mock.patch.object(dogpile.cache.region, 'CacheRegion', autospec=True) + @mock.patch.object(filecache, '_get_cache', autospec=True) + def test_retrieve_data_ok_with_expiry(self, mock_get_cache, mock_cache, + mock_isfile): s = 'spam' mock_isfile.return_value = True - mock_cache.get = mock.Mock(spec=dogpile.cache.region.CacheRegion.get, - return_value=s) + mock_cache.get.return_value = s + mock_get_cache.return_value = mock_cache host = 'fred' port = '1234' expiry = '987' @@ -95,11 +99,13 @@ class FileCacheTest(utils.BaseTestCase): self.assertEqual(s, result) @mock.patch.object(os.path, 'isfile', autospec=True) - @mock.patch.object(filecache, 'CACHE', autospec=True) - def test_retrieve_data_not_found(self, mock_cache, mock_isfile): + @mock.patch.object(dogpile.cache.region, 'CacheRegion', autospec=True) + @mock.patch.object(filecache, '_get_cache', autospec=True) + def test_retrieve_data_not_found(self, mock_get_cache, mock_cache, + mock_isfile): mock_isfile.return_value = True - mock_cache.get = mock.Mock(spec=dogpile.cache.region.CacheRegion.get, - return_value=dogpile.cache.api.NO_VALUE) + mock_cache.get.return_value = dogpile.cache.api.NO_VALUE + mock_get_cache.return_value = mock_cache host = 'fred' port = '1234' hostport = '%s:%s' % (host, port) diff --git a/test-requirements.txt b/test-requirements.txt index 5ba792825..7b3afa609 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,8 @@ discover fixtures>=1.3.1 hacking<0.11,>=0.10.0 httpretty<0.8.7,>=0.8.4 -mock>=1.0 +mock==1.0.1;python_version=='2.6' +mock>=1.1;python_version!='2.6' oslosphinx>=2.5.0 # Apache-2.0 python-subunit>=0.0.18 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2