Merge "Change the unsuitable item caching for completion"

This commit is contained in:
Jenkins 2015-02-07 00:52:15 +00:00 committed by Gerrit Code Review
commit 578390ee7e
2 changed files with 31 additions and 2 deletions

View File

@ -90,9 +90,9 @@ class CompletionCache(object):
~/.novaclient/
<hash-of-endpoint-and-username>/
<resource>-id-cache
<resource>-human-id-cache
<resource>-name-cache
"""
def __init__(self, username, auth_url, attributes=('id', 'human_id')):
def __init__(self, username, auth_url, attributes=('id', 'name')):
self.directory = self._make_directory_name(username, auth_url)
self.attributes = attributes

View File

@ -16,6 +16,7 @@
import json
import logging
import os
import fixtures
import mock
@ -368,3 +369,31 @@ class ClientTest(utils.TestCase):
self.assertIn('RESP BODY: {"access": {"token": {"id":'
' "{SHA1}4fc49c6a671ce889078ff6b250f7066cf6d2ada2"}}}',
output)
@mock.patch('novaclient.client.HTTPClient')
def test_completion_cache(self, instance):
cp_cache = novaclient.client.CompletionCache('user',
"server/v2")
client = novaclient.v2.client.Client("user",
"password", "project_id",
auth_url="server/v2",
completion_cache=cp_cache)
instance.id = "v1c49c6a671ce889078ff6b250f7066cf6d2ada2"
instance.name = "foo.bar.baz v1_1"
client.write_object_to_completion_cache(instance)
self.assertTrue(os.path.isdir(cp_cache.directory))
for file_name in os.listdir(cp_cache.directory):
file_path = os.path.join(cp_cache.directory, file_name)
f = open(file_path, 'r')
for line in f:
line = line.rstrip()
if '-id-' in file_name:
self.assertEqual(instance.id, line)
elif '-name-' in file_name:
self.assertEqual(instance.name, line)
f.close()
os.remove(file_path)
os.rmdir(cp_cache.directory)