Ejemplo n.º 1
0
def test_copy_all():
    item = FileItem(
        filename='foo.txt',
        path=('folder', ),
        data=BytesIO(b'contents'),
        media_type='stuff',
    )

    new_item = item.copy()

    # Identical tuples are identical
    assert new_item == item
    assert new_item.data is item.data
Ejemplo n.º 2
0
    async def async_resolve_filename(self, item: FileItem) -> FileItem:
        """Ensures a unique name for this file in the folder"""
        if not await self._async_exists(item):
            return item

        basename, ext = os.path.splitext(item.filename)
        for counter in range(1, 1000000):
            filename = f'{basename}-{counter}{ext}'
            item = item.copy(filename=filename)
            if not await self._async_exists(item):
                return item
        else:
            raise RuntimeError(
                f'Cannot get unique name for file {basename}{ext}')
Ejemplo n.º 3
0
def test_copy_new_data():
    item = FileItem(
        filename='foo.txt',
        path=('folder', ),
        data=BytesIO(b'contents'),
        media_type='stuff',
    )

    new_item = item.copy(data=BytesIO(b'other'))

    # Tuple is no longer identical as the data is different
    assert new_item != item
    assert new_item.filename == item.filename
    assert new_item.path == item.path
    assert new_item.media_type == item.media_type
Ejemplo n.º 4
0
 def _apply(self, item: FileItem) -> FileItem:
     return item.copy(filename='filtered_name.txt')
Ejemplo n.º 5
0
 def _apply(self, item: FileItem) -> FileItem:
     self.mock._apply(item)
     # append the id_ to the filename
     return item.copy(filename=item.filename + self.id_)
Ejemplo n.º 6
0
 def get_file_key(self, item: FileItem) -> FileItem:
     return item.copy(data=None)
    def _apply(self, item: FileItem) -> FileItem:

        name, ext = os.path.splitext(item.filename)
        randomized_name = self.name_generator(name) + ext.lower()

        return item.copy(filename=randomized_name)