Пример #1
0
 def make_content(self, hash=None, crc32=None, size=None,
                  deflated_size=None, storage_key=None, magic_hash=None):
     """Create content for a file node."""
     content = ContentBlob()
     content.hash = hash or get_fake_hash()
     content.magic_hash = magic_hash or get_fake_hash()
     content.crc32 = crc32 or self.get_unique_integer()
     content.size = size or self.get_unique_integer()
     content.deflated_size = deflated_size or self.get_unique_integer()
     content.status = STATUS_LIVE
     content.storage_key = storage_key or uuid.uuid4()
     self.store.add(content)
     return content
Пример #2
0
 def test_get_status(self):
     """Test get_status."""
     status = downloadservices.get_status(
         self.user.id, self.volume_id, self.fpath, self.dl_url, self.dl_key)
     self.assertEquals(status, downloadservices.UNKNOWN)
     dl = self.get_or_make_it()
     status = downloadservices.get_status(
         self.user.id, self.volume_id, self.fpath, self.dl_url, self.dl_key)
     self.assertEquals(status, downloadservices.QUEUED)
     # go ahead and complete it and create a file
     mime = u'image/tif'
     hash = get_fake_hash()
     storage_key = uuid.uuid4()
     crc = 12345
     size = deflated_size = 300
     dl = self.get_or_make_it()
     downloadservices.download_complete(
         self.user.id, dl.id, hash, crc, size,
         deflated_size, mime, storage_key)
     status = downloadservices.get_status(
         self.user.id, self.volume_id, self.fpath, self.dl_url, self.dl_key)
     self.assertEquals(status, downloadservices.DOWNLOADED)
     #delete the file
     f = self.user.volume().get_node_by_path(self.fpath)
     f.delete()
     status = downloadservices.get_status(
         self.user.id, self.volume_id, self.fpath, self.dl_url, self.dl_key)
     self.assertEquals(status, downloadservices.DOWNLOADED_NOT_PRESENT)
def make_user_data(user):
    """Make some user data."""
    u = services.get_storage_user(username=user_names[random.randint(0, 4)])
    s = user.root.share(u.id, u"%s to %s" % (user.username, u.username))
    u.get_share(s.id).accept()
    for i in range(10):
        d = user.root.make_subdirectory(u"%s dir%s" % (user.username, i))
        for f in range(10):
            f = d.make_file(u"%s file%s.txt" % (user.username, f))
            uj = f.make_uploadjob(f.content_hash,
                                  get_fake_hash(str(random.random())),
                                  random.randint(1, 100),
                                  random.randint(100, 1000000),
                                  random.randint(100, 1000000))
            uj.commit_content(f.content_hash, uuid.uuid4(), None)
            services.add_music_metadata(uj.file.content_hash, TEST_MUSIC_DATA,
                                        user.shard_id)
    for i in range(10):
        user.make_musicstore_download(random.randint(100, 1000000),
                                      random.randint(1, 100),
                                      u"https://fake.com/%s/%s" % (user.id, i),
                                      u"%s" % user.username,
                                      u"%s Greatest Hits" % user.username,
                                      u"Track %s" % i, "US")
    for i in range(10):
        downloadservices.get_or_make_download(
            user.id, user.root_volume_id,
            u"https://fake.com/%s/%s" % (user.id, i), u"/a/b",
            u"%s%s" % (user.id, i))
Пример #4
0
def make_user_data(user):
    """Make some user data."""
    u = services.get_storage_user(username=user_names[random.randint(0, 4)])
    s = user.root.share(u.id, u"%s to %s" % (user.username, u.username))
    u.get_share(s.id).accept()
    for i in range(10):
        d = user.root.make_subdirectory(u"%s dir%s" % (user.username, i))
        for f in range(10):
            f = d.make_file(u"%s file%s.txt" % (user.username, f))
            uj = f.make_uploadjob(
                f.content_hash, get_fake_hash(str(random.random())),
                random.randint(1, 100), random.randint(100, 1000000),
                random.randint(100, 1000000))
            uj.commit_content(f.content_hash, uuid.uuid4(), None)
            services.add_music_metadata(
                uj.file.content_hash, TEST_MUSIC_DATA, user.shard_id)
    for i in range(10):
        user.make_musicstore_download(
            random.randint(100, 1000000),
            random.randint(1, 100), u"https://fake.com/%s/%s" % (user.id, i),
            u"%s" % user.username, u"%s Greatest Hits" % user.username,
            u"Track %s" % i, "US")
    for i in range(10):
        downloadservices.get_or_make_download(
            user.id, user.root_volume_id,
            u"https://fake.com/%s/%s" % (user.id, i),
            u"/a/b", u"%s%s" % (user.id, i))
Пример #5
0
 def make_content(self,
                  hash=None,
                  crc32=None,
                  size=None,
                  deflated_size=None,
                  storage_key=None,
                  magic_hash=None):
     """Create content for a file node."""
     content = model.ContentBlob()
     content.hash = hash or get_fake_hash()
     content.magic_hash = magic_hash or get_fake_hash()
     content.crc32 = crc32 or self.get_unique_integer()
     content.size = size or self.get_unique_integer()
     content.deflated_size = deflated_size or self.get_unique_integer()
     content.status = model.STATUS_LIVE
     content.storage_key = storage_key or uuid.uuid4()
     self.sstore.add(content)
     return content
Пример #6
0
 def test_get_public_directory(self):
     """Test the get_public_directory function."""
     user = self.obj_factory.make_user(
         1, "Cool UserName", "Visible Name", 10)
     a_dir = user.volume().root.make_subdirectory('test_dir')
     a_dir.make_file_with_content(
         "file.txt", get_fake_hash(), 123, 1, 1, uuid.uuid4())
     a_dir.change_public_access(True, allow_directory=True)
     public_key = a_dir.public_key
     pub_dir = get_public_directory(public_key)
     self.assertEqual(pub_dir, a_dir)
     a_dir.change_public_access(False, allow_directory=True)
     self.assertRaises(errors.DoesNotExist,
                       get_public_directory, public_key)
Пример #7
0
 def test_get_public_directory(self):
     """Test the get_public_directory function."""
     user = self.obj_factory.make_user(1, u"Cool UserName", u"Visible Name",
                                       10)
     a_dir = user.volume().root.make_subdirectory(u'test_dir')
     a_dir.make_file_with_content(u"file.txt", get_fake_hash(), 123, 1, 1,
                                  uuid.uuid4())
     a_dir.change_public_access(True, allow_directory=True)
     public_key = a_dir.public_key
     pub_dir = get_public_directory(public_key)
     self.assertEqual(pub_dir, a_dir)
     a_dir.change_public_access(False, allow_directory=True)
     self.assertRaises(errors.DoesNotExist, get_public_directory,
                       public_key)
Пример #8
0
 def make_file(self, user=None, parent=None, name=None, mimetype=u"text/plain"):
     if user is None:
         user = self.make_user()
     if name is None:
         name = self.get_unique_unicode()
     if parent is None:
         parent = user.root
     hash = get_fake_hash()
     storage_key = uuid.uuid4()
     crc = self.get_unique_integer()
     size = 100
     deflated_size = 10000
     f = parent.make_file_with_content(name, hash, crc, size, deflated_size, storage_key, mimetype)
     f.load(with_content=True)
     return f
Пример #9
0
 def test_get_public_file(self):
     """Test the get_public_file function."""
     save_setting = utils.set_public_uuid
     utils.set_public_uuid = False
     user = self.obj_factory.make_user(
         1, "Cool UserName", "Visible Name", 10)
     a_file = user.volume().root.make_file_with_content(
         "file.txt", get_fake_hash(), 123, 1, 1, uuid.uuid4())
     a_file.change_public_access(True)
     public_key = a_file.public_key
     f1 = get_public_file(public_key)
     self.assertEqual(f1, a_file)
     a_file.change_public_access(False)
     self.assertRaises(errors.DoesNotExist,
                       get_public_file, public_key, use_uuid=False)
     utils.set_public_uuid = save_setting
Пример #10
0
 def test_get_public_file(self):
     """Test the get_public_file function."""
     save_setting = utils.set_public_uuid
     utils.set_public_uuid = False
     user = self.obj_factory.make_user(1, u"Cool UserName", u"Visible Name",
                                       10)
     a_file = user.volume().root.make_file_with_content(
         u"file.txt", get_fake_hash(), 123, 1, 1, uuid.uuid4())
     a_file.change_public_access(True)
     public_key = a_file.public_key
     f1 = get_public_file(public_key)
     self.assertEqual(f1, a_file)
     a_file.change_public_access(False)
     self.assertRaises(errors.DoesNotExist,
                       get_public_file,
                       public_key,
                       use_uuid=False)
     utils.set_public_uuid = save_setting
Пример #11
0
 def test_download_complete(self):
     """Test download_complete."""
     mime = u'image/tif'
     hash = get_fake_hash()
     storage_key = uuid.uuid4()
     crc = 12345
     size = deflated_size = 300
     dl = self.get_or_make_it()
     downloadservices.download_complete(
         self.user.id, dl.id, hash, crc, size,
         deflated_size, mime, storage_key)
     dl = downloadservices.get_download_by_id(self.user.id, dl.id)
     self.assertEquals(dl.status, model.DOWNLOAD_STATUS_COMPLETE)
     f = self.user.volume().get_node_by_path(
         self.fpath, with_content=True)
     self.assertEquals(f.full_path, self.fpath)
     self.assertEquals(f.content_hash, hash)
     self.assertEquals(f.content.storage_key, storage_key)
     self.assertEquals(f.mimetype, mime)
Пример #12
0
 def make_file(self,
               user=None,
               parent=None,
               name=None,
               mimetype=u'text/plain'):
     if user is None:
         user = self.make_user()
     if name is None:
         name = self.get_unique_unicode()
     if parent is None:
         parent = user.root
     hash = get_fake_hash()
     storage_key = uuid.uuid4()
     crc = self.get_unique_integer()
     size = 100
     deflated_size = 10000
     f = parent.make_file_with_content(name, hash, crc, size, deflated_size,
                                       storage_key, mimetype)
     f.load(with_content=True)
     return f
def main(username, sharer, wlist, num):
    """Create UDFs, folders and files for the given user using a wordlist."""
    user = get_storage_user(None, username=utf2unicode(username))
    sharer = get_storage_user(None, username=utf2unicode(sharer))
    folders = [user.root]
    names = [utf2unicode(i.strip()) for i in file(wlist) if i.strip()]
    sample = random.sample(names, num)

    if sys.stdout.isatty():
        import curses
        curses.setupterm()
        cols = curses.tigetnum('cols') - 1
        progbar = makeStatBar(cols, cols - 2)
        home = curses.tigetstr('cr')

        def progress(l):
            """progress bar writer."""
            sys.stdout.write(home + progbar((cols - 2) * (num - len(l)) / num))
            sys.stdout.flush()
    else:
        progress = lambda l: None

    # UDF
    udf = user.make_udf('~/abundant-files')
    folders.append(user.volume(udf.id).get_node(udf.root_id))

    # some UDFs
    for i in range(num / 100):
        progress(sample)
        folders.append(make_udf(user, sample))

    for i in range(num / 4):
        progress(sample)
        name = sample.pop()
        folders.append(random.choice(folders).make_subdirectory(name))

    sh_folders = [sharer.root]
    for i in range(num / 10):
        progress(sample)
        sh_folders.append(make_udf(sharer, sample))
    for i in range(num / 10):
        progress(sample)
        name = sample.pop()
        sh_folders.append(random.choice(sh_folders).make_subdirectory(name))
    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + sharer.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(sh_folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(user.id, folder.name, readonly)
        user.get_share(share.id).accept()

    for i in random.sample(folders, len(folders) / 4):
        progress(sample)
        name = sample.pop()
        filename = 'shared by ' + user.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(sharer.id, folder.name, readonly)
        sharer.get_share(share.id).accept()

    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file(name)

    fake_hash = get_fake_hash()
    while sample:
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file_with_content(
            name, fake_hash, 12345, 100, 10000, uuid.uuid4(), 'image/tiff')

    if sys.stdout.isatty():
        sys.stdout.write(home + curses.tigetstr('el'))
def main(username, sharer, wlist, num):
    """Create UDFs, folders and files for the given user using a wordlist."""
    user = get_storage_user(None, username=utf2unicode(username))
    sharer = get_storage_user(None, username=utf2unicode(sharer))
    folders = [user.root]
    names = [utf2unicode(i.strip()) for i in file(wlist) if i.strip()]
    sample = random.sample(names, num)

    if sys.stdout.isatty():
        import curses
        curses.setupterm()
        cols = curses.tigetnum('cols') - 1
        progbar = makeStatBar(cols, cols - 2)
        home = curses.tigetstr('cr')

        def progress(l):
            """progress bar writer."""
            sys.stdout.write(home + progbar((cols - 2) * (num - len(l)) / num))
            sys.stdout.flush()
    else:
        progress = lambda l: None

    # UDF
    udf = user.make_udf(u'~/abundant-files')
    folders.append(user.volume(udf.id).get_node(udf.root_id))

    # some UDFs
    for i in range(num / 100):
        progress(sample)
        folders.append(make_udf(user, sample))

    for i in range(num / 4):
        progress(sample)
        name = sample.pop()
        folders.append(random.choice(folders).make_subdirectory(name))

    sh_folders = [sharer.root]
    for i in range(num / 10):
        progress(sample)
        sh_folders.append(make_udf(sharer, sample))
    for i in range(num / 10):
        progress(sample)
        name = sample.pop()
        sh_folders.append(random.choice(sh_folders).make_subdirectory(name))
    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        filename = u'shared by ' + sharer.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(sh_folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(user.id, folder.name, readonly)
        user.get_share(share.id).accept()

    for i in random.sample(folders, len(folders) / 4):
        progress(sample)
        name = sample.pop()
        filename = u'shared by ' + user.username
        readonly = random.choice((False, True))
        if readonly:
            name += ' (ro)'
            filename += ' (ro)'
        folder = random.choice(folders).make_subdirectory(name)
        folder.make_file(filename)
        share = folder.share(sharer.id, folder.name, readonly)
        sharer.get_share(share.id).accept()

    for i in range(num / 20):
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file(name)

    fake_hash = get_fake_hash()
    while sample:
        progress(sample)
        name = sample.pop()
        random.choice(folders).make_file_with_content(name, fake_hash, 12345,
                                                      100, 10000, uuid.uuid4(),
                                                      u'image/tiff')

    if sys.stdout.isatty():
        sys.stdout.write(home + curses.tigetstr('el'))