def test_get_user_info(self): """Test the get_user_info function.""" user = self.obj_factory.make_user( 1, "User 1", "User 1", MAX_STORAGE_BYTES) user_info = get_user_info(user.id) quota = user.get_quota() self.assertEqual(quota.max_storage_bytes, user_info.max_storage_bytes) self.assertEqual( quota.used_storage_bytes, user_info.used_storage_bytes) self.assertEqual(quota.free_bytes, user_info.free_bytes) self.assertRaises(errors.DoesNotExist, get_user_info, 41)
def list_volumes(self, user_id): """List all the volumes the user is involved. This includes the real Root, the UDFs, and the shares that were shared to the user already accepted. """ user = self._get_user(user_id) # root info root = user.volume().get_volume() root_info = dict(root_id=root.root_id, generation=root.generation) # quota free_bytes = user.get_quota().free_bytes # shares shares = [] for share in user.get_shared_to(accepted=True): suser = share.shared_by resp = dict(id=share.id, root_id=share.root_id, name=share.name, shared_by_username=suser.username, shared_by_visible_name=suser.visible_name, accepted=share.accepted, access=share.access) info = services.get_user_info(suser.id) resp['free_bytes'] = info.free_bytes resp['generation'] = share.get_generation() shares.append(resp) # udfs udfs = [] for udf in user.get_udfs(): resp = dict(id=udf.id, root_id=udf.root_id, path=udf.path, generation=udf.generation) udfs.append(resp) result = dict(root=root_info, free_bytes=free_bytes, shares=shares, udfs=udfs) return result