Skip to content

Commit

Permalink
Fix trash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivknv committed Jul 10, 2021
1 parent 2c56a2e commit f243346
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions tests/resources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def __init__(self, *args, **kwargs):

self.path = os.environ.get("PYTHON_YADISK_TEST_ROOT")

# Get rid of 'disk:/' prefix in the path and make it start with a slash
# for consistency
if self.path.startswith("disk:/"):
self.path = posixpath.join("/", self.path[len("disk:/"):])

def __del__(self):
if self.yadisk is None:
return
Expand Down Expand Up @@ -103,7 +108,7 @@ async def test_listdir_on_file(self):
with self.assertRaises(yadisk_async.exceptions.WrongResourceTypeError):
[i async for i in await self.yadisk.listdir(path)]

await self.yadisk.remove(path)
await self.yadisk.remove(path, permanently=True)

def test_listdir_with_limits(self):
names = ["dir1", "dir2", "dir3"]
Expand Down Expand Up @@ -175,18 +180,32 @@ async def test_check_token(self):
@async_test
async def test_permanent_remove(self):
path = posixpath.join(self.path, "dir")
origin_path = "disk:" + path

await self.yadisk.mkdir(path)
await self.yadisk.remove(path, permanently=True)
self.assertFalse(await self.yadisk.trash_exists(path))

async for i in await self.yadisk.trash_listdir("/"):
self.assertFalse(i.origin_path == origin_path)

@async_test
async def test_restore_trash(self):
path = posixpath.join(self.path, "dir")
origin_path = "disk:" + path

await self.yadisk.mkdir(path)
await self.yadisk.remove(path)
await self.yadisk.restore_trash("dir", path)

trash_path = None

async for i in await self.yadisk.trash_listdir("/"):
if i.origin_path == origin_path:
trash_path = i.path
break

self.assertTrue(trash_path is not None)

await self.yadisk.restore_trash(trash_path, path)
self.assertTrue(await self.yadisk.exists(path))
await self.yadisk.remove(path, permanently=True)

Expand All @@ -204,10 +223,22 @@ async def test_move(self):
@async_test
async def test_remove_trash(self):
path = posixpath.join(self.path, "dir-to-remove")
origin_path = "disk:" + path

await self.yadisk.mkdir(path)
await self.yadisk.remove(path)
await self.yadisk.remove_trash("dir-to-remove")
self.assertFalse(await self.yadisk.trash_exists("dir-to-remove"))

trash_path = None

async for i in await self.yadisk.trash_listdir("/"):
if i.origin_path == origin_path:
trash_path = i.path
break

self.assertTrue(trash_path is not None)

await self.yadisk.remove_trash(trash_path)
self.assertFalse(await self.yadisk.trash_exists(trash_path))

@async_test
async def test_publish_unpublish(self):
Expand Down

0 comments on commit f243346

Please sign in to comment.