def test_swift_create_container(self): container = self.containers.first() swift_api = self.stub_swiftclient() swift_api.head_container(container.name).AndReturn(container) self.mox.ReplayAll() # Verification handled by mox, no assertions needed. with self.assertRaises(exceptions.AlreadyExists): api.swift_create_container(self.request, container.name)
def test_swift_create_duplicate_container(self): container = self.containers.first() swift_api = self.stub_swiftclient(expected_calls=2) # Check for existence, then create exc = self.exceptions.swift swift_api.head_container(container.name).AndRaise(exc) swift_api.put_container(container.name).AndReturn(container) self.mox.ReplayAll() # Verification handled by mox, no assertions needed. api.swift_create_container(self.request, container.name)
def test_create_container_post(self): api.swift_create_container(IsA(http.HttpRequest), self.containers.first().name) self.mox.ReplayAll() formData = {'name': self.containers.first().name, 'method': forms.CreateContainer.__name__} res = self.client.post(reverse('horizon:project:containers:create'), formData) url = reverse('horizon:project:containers:index', args=[wrap_delimiter(self.containers.first().name)]) self.assertRedirectsNoFollow(res, url)
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() formData = { 'name': self.containers.first().name, 'method': forms.CreateContainer.__name__ } res = self.client.post(reverse('horizon:project:containers:create'), formData) url = reverse('horizon:project:containers:index', args=[wrap_delimiter(self.containers.first().name)]) self.assertRedirectsNoFollow(res, url)
def handle(self, request, data): try: if not data['parent']: # Create a container api.swift_create_container(request, data["name"]) messages.success(request, _("Container created successfully.")) else: # Create a pseudo-folder container, slash, remainder = data['parent'].partition("/") remainder = remainder.rstrip("/") subfolder_name = "/".join([bit for bit in (remainder, data['name']) if bit]) api.swift_create_subfolder(request, container, subfolder_name) messages.success(request, _("Folder created successfully.")) return True except: exceptions.handle(request, _('Unable to create container.'))