def update(self, request, id): """PUT request. Update resource pool. Please see the documentation for the 'create' operation for detailed descriptions of each parameter. Optional parameters ------------------- name Name of the resource pool. description Description of the resource pool. Returns 404 if the resource pool is not found. """ pool = ResourcePool.objects.get_resource_pool_or_404( id, request.user, NODE_PERMISSION.ADMIN) form = ResourcePoolForm(instance=pool, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def test_renames_pool(self): pool = factory.make_ResourcePool() new_name = factory.make_name("pool") form = ResourcePoolForm(data={"name": new_name}, instance=pool) form.save() pool = reload_object(pool) self.assertEqual(pool.name, new_name)
def test_updates_pool(self): pool = factory.make_ResourcePool() new_description = factory.make_string() form = ResourcePoolForm(data={"description": new_description}, instance=pool) form.save() pool = reload_object(pool) self.assertEqual(pool.description, new_description)
def test_creates_pool(self): name = factory.make_name('pool') description = factory.make_string() form = ResourcePoolForm( data={'name': name, 'description': description}) form.save() pool = ResourcePool.objects.get(name=name) self.assertIsNotNone(pool) self.assertEqual(pool.description, description)
def test_creates_pool_users_groups(self): user1 = factory.make_User() user2 = factory.make_User() group1 = factory.make_UserGroup() group2 = factory.make_UserGroup() data = { 'name': factory.make_name('pool'), 'users': [user1.id, user2.id], 'groups': [group1.id, group2.id]} form = ResourcePoolForm(data=data) pool = form.save() self.assertCountEqual(pool.users, [user1, user2]) self.assertCountEqual(pool.groups, [group1, group2])
def test_updates_pool_users_groups(self): user1 = factory.make_User() user2 = factory.make_User() user3 = factory.make_User() group1 = factory.make_UserGroup() group2 = factory.make_UserGroup() group3 = factory.make_UserGroup() pool = factory.make_ResourcePool( users=[user1, user2], groups=[group1, group2]) data = { 'users': [user1.id, user3.id], 'groups': [group1.id, group3.id]} form = ResourcePoolForm(data=data, instance=pool) pool = form.save() self.assertCountEqual(pool.users, [user1, user3]) self.assertCountEqual(pool.groups, [group1, group3])
def update(self, request, id): """@description Updates a resource pool's name or description. Note that any other given parameters are silently ignored. @param (url-string) "{id}" [required=true] The resource pool id/name to update. @param (string) "description" [required=false] A brief description of the resource pool. @param (string) "name" [required=false] The resource pool's new name. @param-example "{id}" myresourcepool @param-example "name" newname @param-example "description" An updated resource pool description. @success (http-status-code) "serversuccess" 200 @success (content) "contentsuccess" A JSON object containing details about your new resource pool. @success-example "contentsuccess" { "name": "test-update-renamed", "description": "This is a new resource pool for updating.", "id": 80, "resource_uri": "/MAAS/api/2.0/resourcepool/80/" } @error (http-status-code) "404" 404 @error (content) "notfound" Zone not found @error-example "notfound" Not Found """ pool = ResourcePool.objects.get_resource_pool_or_404( id, request.user, NODE_PERMISSION.ADMIN) form = ResourcePoolForm(instance=pool, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)