def test_get_user_info_for_shard(self): """Test the get_user_info_for_shard function.""" user = self.obj_factory.make_user( 1, u"User 1", u"User 1", MAX_STORAGE_BYTES, shard_id=u"shard1") user_info = get_user_info_for_shard(user.id, user.shard_id) quota = user.get_quota() self.assertEquals(quota.max_storage_bytes, user_info.max_storage_bytes) self.assertEquals(quota.used_storage_bytes, user_info.used_storage_bytes) self.assertEquals(quota.free_bytes, user_info.free_bytes) self.assertRaises(errors.DoesNotExist, get_user_info_for_shard, 41, user.shard_id)
def test_get_user_info_for_shard(self): """Test the get_user_info_for_shard function.""" user = self.obj_factory.make_user(1, u"User 1", u"User 1", MAX_STORAGE_BYTES, shard_id=u"shard1") user_info = get_user_info_for_shard(user.id, user.shard_id) quota = user.get_quota() self.assertEquals(quota.max_storage_bytes, user_info.max_storage_bytes) self.assertEquals(quota.used_storage_bytes, user_info.used_storage_bytes) self.assertEquals(quota.free_bytes, user_info.free_bytes) self.assertRaises(errors.DoesNotExist, get_user_info_for_shard, 41, user.shard_id)
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_for_shard(suser.id, suser.shard_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