Fixed getting success msg on failing swift operation
Show error message instead of success message when attempting to create a duplicate object or pseudo-folder. Added tests for creating and creating duplicate pseudo-folders. Change-Id: I875d471921d9a37bb6706a17d4fbca5e9428ae93 Closes-Bug: #1478126
This commit is contained in:
parent
ede7402604
commit
5693109901
@ -277,6 +277,8 @@ def swift_copy_object(request, orig_container_name, orig_object_name,
|
|||||||
|
|
||||||
def swift_upload_object(request, container_name, object_name,
|
def swift_upload_object(request, container_name, object_name,
|
||||||
object_file=None):
|
object_file=None):
|
||||||
|
if swift_object_exists(request, container_name, object_name):
|
||||||
|
raise exceptions.AlreadyExists(object_name, 'object')
|
||||||
headers = {}
|
headers = {}
|
||||||
size = 0
|
size = 0
|
||||||
if object_file:
|
if object_file:
|
||||||
@ -294,6 +296,10 @@ def swift_upload_object(request, container_name, object_name,
|
|||||||
|
|
||||||
|
|
||||||
def swift_create_pseudo_folder(request, container_name, pseudo_folder_name):
|
def swift_create_pseudo_folder(request, container_name, pseudo_folder_name):
|
||||||
|
# Make sure the folder name doesn't already exist.
|
||||||
|
if swift_object_exists(request, container_name, pseudo_folder_name):
|
||||||
|
name = pseudo_folder_name.strip('/')
|
||||||
|
raise exceptions.AlreadyExists(name, 'pseudo-folder')
|
||||||
headers = {}
|
headers = {}
|
||||||
etag = swift_api(request).put_object(container_name,
|
etag = swift_api(request).put_object(container_name,
|
||||||
pseudo_folder_name,
|
pseudo_folder_name,
|
||||||
|
@ -170,6 +170,34 @@ class SwiftApiTests(test.APITestCase):
|
|||||||
self.assertEqual(object.name, obj.name)
|
self.assertEqual(object.name, obj.name)
|
||||||
self.assertIsNone(obj.data)
|
self.assertIsNone(obj.data)
|
||||||
|
|
||||||
|
def test_swift_create_pseudo_folder(self):
|
||||||
|
container = self.containers.first()
|
||||||
|
folder = self.folder.first()
|
||||||
|
swift_api = self.stub_swiftclient()
|
||||||
|
exc = self.exceptions.swift
|
||||||
|
swift_api.head_object(container.name, folder.name).AndRaise(exc)
|
||||||
|
swift_api.put_object(container.name,
|
||||||
|
folder.name,
|
||||||
|
None,
|
||||||
|
headers={}).AndReturn(folder)
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
# Verification handled by mox, no assertions needed.
|
||||||
|
api.swift.swift_create_pseudo_folder(self.request,
|
||||||
|
container.name,
|
||||||
|
folder.name)
|
||||||
|
|
||||||
|
def test_swift_create_duplicate_folder(self):
|
||||||
|
container = self.containers.first()
|
||||||
|
folder = self.folder.first()
|
||||||
|
swift_api = self.stub_swiftclient()
|
||||||
|
swift_api.head_object(container.name, folder.name).AndReturn(folder)
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
# Verification handled by mox, no assertions needed.
|
||||||
|
with self.assertRaises(exceptions.AlreadyExists):
|
||||||
|
api.swift.swift_create_pseudo_folder(self.request,
|
||||||
|
container.name,
|
||||||
|
folder.name)
|
||||||
|
|
||||||
def test_swift_upload_object(self):
|
def test_swift_upload_object(self):
|
||||||
container = self.containers.first()
|
container = self.containers.first()
|
||||||
obj = self.objects.first()
|
obj = self.objects.first()
|
||||||
@ -184,6 +212,8 @@ class SwiftApiTests(test.APITestCase):
|
|||||||
headers = {'X-Object-Meta-Orig-Filename': fake_name}
|
headers = {'X-Object-Meta-Orig-Filename': fake_name}
|
||||||
|
|
||||||
swift_api = self.stub_swiftclient()
|
swift_api = self.stub_swiftclient()
|
||||||
|
exc = self.exceptions.swift
|
||||||
|
swift_api.head_object(container.name, obj.name).AndRaise(exc)
|
||||||
test_file = FakeFile()
|
test_file = FakeFile()
|
||||||
swift_api.put_object(container.name,
|
swift_api.put_object(container.name,
|
||||||
obj.name,
|
obj.name,
|
||||||
@ -197,11 +227,35 @@ class SwiftApiTests(test.APITestCase):
|
|||||||
obj.name,
|
obj.name,
|
||||||
test_file)
|
test_file)
|
||||||
|
|
||||||
|
def test_swift_upload_duplicate_object(self):
|
||||||
|
container = self.containers.first()
|
||||||
|
obj = self.objects.first()
|
||||||
|
fake_name = 'fake_object.jpg'
|
||||||
|
|
||||||
|
class FakeFile(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.name = fake_name
|
||||||
|
self.data = obj.data
|
||||||
|
self.size = len(obj.data)
|
||||||
|
|
||||||
|
swift_api = self.stub_swiftclient()
|
||||||
|
swift_api.head_object(container.name, obj.name).AndReturn(obj)
|
||||||
|
test_file = FakeFile()
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
with self.assertRaises(exceptions.AlreadyExists):
|
||||||
|
api.swift.swift_upload_object(self.request,
|
||||||
|
container.name,
|
||||||
|
obj.name,
|
||||||
|
test_file)
|
||||||
|
|
||||||
def test_swift_upload_object_without_file(self):
|
def test_swift_upload_object_without_file(self):
|
||||||
container = self.containers.first()
|
container = self.containers.first()
|
||||||
obj = self.objects.first()
|
obj = self.objects.first()
|
||||||
|
|
||||||
swift_api = self.stub_swiftclient()
|
swift_api = self.stub_swiftclient()
|
||||||
|
exc = self.exceptions.swift
|
||||||
|
swift_api.head_object(container.name, obj.name).AndRaise(exc)
|
||||||
swift_api.put_object(container.name,
|
swift_api.put_object(container.name,
|
||||||
obj.name,
|
obj.name,
|
||||||
None,
|
None,
|
||||||
|
Loading…
Reference in New Issue
Block a user