Fixed unicode for object copy

Removed deprecated check for unicode symbols
in object names, fixed the reverse() for success_url,
which expects "/" to be included in path arguments.

Fixes bug 1008940

Change-Id: I1122437c40f8e31b64a82b39cd326141842ca519
This commit is contained in:
Tihomir Trifonov 2012-12-11 12:02:06 +02:00
parent 648c8a582b
commit 4b1fc16789
6 changed files with 22 additions and 33 deletions

View File

@ -204,19 +204,6 @@ def wildcard_search(string, q):
def swift_copy_object(request, orig_container_name, orig_object_name,
new_container_name, new_object_name):
try:
# FIXME(gabriel): The swift currently fails at unicode in the
# copy_to method, so to provide a better experience we check for
# unicode here and pre-empt with an error message rather than
# letting the call fail.
str(orig_container_name)
str(orig_object_name)
str(new_container_name)
str(new_object_name)
except UnicodeEncodeError:
raise exceptions.HorizonException(_("Unicode is not currently "
"supported for object copy."))
if swift_object_exists(request, new_container_name, new_object_name):
raise exceptions.AlreadyExists(new_object_name, 'object')

View File

@ -41,7 +41,7 @@ class CreateNetwork(forms.SelfHandlingForm):
def _instantiate(cls, request, *args, **kwargs):
return cls(request, *args, **kwargs)
def __init__(self, request, *args, **kwargs):
def __init__(self, request, *args, **kwargs):
super(CreateNetwork, self).__init__(request, *args, **kwargs)
tenant_choices = [('', _("Select a project"))]
for tenant in api.keystone.tenant_list(request, admin=True):

View File

@ -119,12 +119,15 @@ class CopyObject(forms.SelfHandlingForm):
orig_object = data['orig_object_name']
new_container = data['new_container_name']
new_object = data['new_object_name']
new_path = "%s%s" % (data['path'], new_object)
path = data['path']
if path and not path.endswith("/"):
path = path + "/"
new_path = "%s%s" % (path, new_object)
# Iteratively make sure all the directory markers exist.
if data['path']:
if path:
path_component = ""
for bit in [i for i in data['path'].split("/") if i]:
for bit in [i for i in path.split("/") if i]:
path_component += bit
try:
api.swift.swift_create_subfolder(request,
@ -145,7 +148,7 @@ class CopyObject(forms.SelfHandlingForm):
orig_object,
new_container,
new_path)
dest = "%s/%s" % (new_container, data['path'])
dest = "%s/%s" % (new_container, path)
vals = {"dest": dest.rstrip("/"),
"orig": orig_object.split("/")[-1],
"new": new_object}

View File

@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__)
def wrap_delimiter(name):
if not name.endswith(FOLDER_DELIMITER):
if name and not name.endswith(FOLDER_DELIMITER):
return name + FOLDER_DELIMITER
return name
@ -54,7 +54,7 @@ class DeleteContainer(tables.DeleteAction):
# completion url
if current_container in self.success_ids:
return self.success_url
return request.get_full_path()
return request.get_full_path()
class CreateContainer(tables.LinkAction):

View File

@ -36,9 +36,9 @@ CONTAINER_INDEX_URL = reverse('horizon:project:containers:index')
class SwiftTests(test.TestCase):
@test.create_stubs({api: ('swift_get_containers',)})
def test_index_no_container_selected(self):
containers = self.containers.list()
self.mox.StubOutWithMock(api, 'swift_get_containers')
api.swift_get_containers(IsA(http.HttpRequest), marker=None) \
.AndReturn((containers, False))
self.mox.ReplayAll()
@ -50,9 +50,9 @@ class SwiftTests(test.TestCase):
resp_containers = res.context['table'].data
self.assertEqual(len(resp_containers), len(containers))
@test.create_stubs({api: ('swift_delete_container',)})
def test_delete_container(self):
container = self.containers.get(name=u"container_two\u6346")
self.mox.StubOutWithMock(api, 'swift_delete_container')
api.swift_delete_container(IsA(http.HttpRequest), container.name)
self.mox.ReplayAll()
@ -63,9 +63,9 @@ class SwiftTests(test.TestCase):
handled = table.maybe_handle()
self.assertEqual(handled['location'], CONTAINER_INDEX_URL)
@test.create_stubs({api: ('swift_delete_container',)})
def test_delete_container_nonempty(self):
container = self.containers.first()
self.mox.StubOutWithMock(api, 'swift_delete_container')
exc = self.exceptions.swift
exc.silence_logging = True
api.swift_delete_container(IsA(http.HttpRequest),
@ -83,8 +83,8 @@ class SwiftTests(test.TestCase):
res = self.client.get(reverse('horizon:project:containers:create'))
self.assertTemplateUsed(res, 'project/containers/create.html')
@test.create_stubs({api: ('swift_create_container',)})
def test_create_container_post(self):
self.mox.StubOutWithMock(api, 'swift_create_container')
api.swift_create_container(IsA(http.HttpRequest),
self.containers.first().name)
self.mox.ReplayAll()
@ -97,9 +97,8 @@ class SwiftTests(test.TestCase):
args=[wrap_delimiter(self.containers.first().name)])
self.assertRedirectsNoFollow(res, url)
@test.create_stubs({api: ('swift_get_containers', 'swift_get_objects')})
def test_index_container_selected(self):
self.mox.StubOutWithMock(api, 'swift_get_containers')
self.mox.StubOutWithMock(api, 'swift_get_objects')
containers = (self.containers.list(), False)
ret = (self.objects.list(), False)
api.swift_get_containers(IsA(http.HttpRequest),
@ -121,6 +120,7 @@ class SwiftTests(test.TestCase):
expected,
lambda obj: obj.name.encode('utf8'))
@test.create_stubs({api: ('swift_upload_object',)})
def test_upload(self):
container = self.containers.first()
obj = self.objects.first()
@ -131,7 +131,6 @@ class SwiftTests(test.TestCase):
temp_file.flush()
temp_file.seek(0)
self.mox.StubOutWithMock(api, 'swift_upload_object')
api.swift_upload_object(IsA(http.HttpRequest),
container.name,
obj.name,
@ -163,12 +162,12 @@ class SwiftTests(test.TestCase):
self.assertNoMessages()
self.assertContains(res, "Slash is not an allowed character.")
@test.create_stubs({api: ('swift_delete_object',)})
def test_delete(self):
container = self.containers.first()
obj = self.objects.first()
index_url = reverse('horizon:project:containers:index',
args=[wrap_delimiter(container.name)])
self.mox.StubOutWithMock(api, 'swift_delete_object')
api.swift_delete_object(IsA(http.HttpRequest),
container.name,
obj.name)
@ -182,11 +181,11 @@ class SwiftTests(test.TestCase):
handled = table.maybe_handle()
self.assertEqual(handled['location'], index_url)
@test.create_stubs({api.swift: ('swift_get_object',)})
def test_download(self):
container = self.containers.first()
obj = self.objects.first()
self.mox.StubOutWithMock(api.swift, 'swift_get_object')
api.swift.swift_get_object(IsA(http.HttpRequest),
container.name,
obj.name).AndReturn(obj)
@ -198,8 +197,8 @@ class SwiftTests(test.TestCase):
self.assertEqual(res.content, obj.data)
self.assertTrue(res.has_header('Content-Disposition'))
@test.create_stubs({api: ('swift_get_containers',)})
def test_copy_index(self):
self.mox.StubOutWithMock(api, 'swift_get_containers')
ret = (self.containers.list(), False)
api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret)
self.mox.ReplayAll()
@ -209,13 +208,12 @@ class SwiftTests(test.TestCase):
self.objects.first().name]))
self.assertTemplateUsed(res, 'project/containers/copy.html')
@test.create_stubs({api: ('swift_get_containers', 'swift_copy_object')})
def test_copy(self):
container_1 = self.containers.get(name=u"container_one\u6346")
container_2 = self.containers.get(name=u"container_two\u6346")
obj = self.objects.first()
self.mox.StubOutWithMock(api, 'swift_get_containers')
self.mox.StubOutWithMock(api, 'swift_copy_object')
ret = (self.containers.list(), False)
api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret)
api.swift_copy_object(IsA(http.HttpRequest),

View File

@ -188,7 +188,8 @@ class CopyView(forms.ModalFormView):
new_container_name = self.request.POST['new_container_name']
return reverse(self.success_url,
args=(wrap_delimiter(new_container_name),
self.request.POST.get('path', '')))
wrap_delimiter(self.request.POST.get('path',
''))))
def get_form_kwargs(self):
kwargs = super(CopyView, self).get_form_kwargs()