| 1 | import pathlib |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | import aioftp |
| 6 | |
| 7 | |
| 8 | @pytest.mark.asyncio |
| 9 | async def test_current_directory_simple(pair_factory): |
| 10 | async with pair_factory() as pair: |
| 11 | cwd = await pair.client.get_current_directory() |
| 12 | assert cwd == pathlib.PurePosixPath("/") |
| 13 | |
| 14 | |
| 15 | @pytest.mark.asyncio |
| 16 | async def test_current_directory_not_default(pair_factory, Server): |
| 17 | s = Server([aioftp.User(home_path="/home")]) |
| 18 | async with pair_factory(None, s) as pair: |
| 19 | cwd = await pair.client.get_current_directory() |
| 20 | assert cwd == pathlib.PurePosixPath("/home") |
| 21 | |
| 22 | |
| 23 | @pytest.mark.asyncio |
| 24 | async def test_mlsd(pair_factory): |
| 25 | async with pair_factory() as pair: |
| 26 | await pair.make_server_files("test.txt") |
| 27 | (path, stat), *_ = files = await pair.client.list() |
| 28 | assert len(files) == 1 |
| 29 | assert path == pathlib.PurePosixPath("test.txt") |
| 30 | assert stat["type"] == "file" |
| 31 | |
| 32 | |
| 33 | @pytest.mark.asyncio |
| 34 | async def test_resolving_double_dots(pair_factory): |
| 35 | async with pair_factory() as pair: |
| 36 | await pair.make_server_files("test.txt") |
| 37 | |
| 38 | async def f(): |
| 39 | cwd = await pair.client.get_current_directory() |
| 40 | assert cwd == pathlib.PurePosixPath("/") |
| 41 | (path, stat), *_ = files = await pair.client.list() |
| 42 | assert len(files) == 1 |
| 43 | assert path == pathlib.PurePosixPath("test.txt") |
| 44 | assert stat["type"] == "file" |
| 45 | |
| 46 | await f() |
| 47 | await pair.client.change_directory("../../../") |
| 48 | await f() |
| 49 | await pair.client.change_directory("/a/../b/..") |
| 50 | await f() |