orc-renaming/tests/test_webdav.py

48 lines
1.7 KiB
Python

from __future__ import annotations
import httpx
from orc_renaming.webdav import WebDAVClient
def test_list_pdfs_ignores_subfolders_and_other_files(config) -> None:
xml = """<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:">
<d:response>
<d:href>/remote.php/dav/files/test/Scanner/Eingang/</d:href>
<d:propstat><d:prop><d:resourcetype><d:collection/></d:resourcetype>
</d:prop></d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/test/Scanner/Eingang/Scan%20A.PDF</d:href>
<d:propstat><d:prop><d:resourcetype/><d:getcontentlength>123</d:getcontentlength>
<d:getetag>&quot;etag-1&quot;</d:getetag></d:prop></d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/test/Scanner/Eingang/notiz.txt</d:href>
<d:propstat><d:prop><d:resourcetype/></d:prop></d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/test/Scanner/Eingang/umbenannt/</d:href>
<d:propstat><d:prop><d:resourcetype><d:collection/></d:resourcetype>
</d:prop></d:propstat>
</d:response>
</d:multistatus>"""
def handler(request: httpx.Request) -> httpx.Response:
assert request.method == "PROPFIND"
assert request.headers["Depth"] == "1"
return httpx.Response(207, text=xml)
client = WebDAVClient(config.nextcloud)
client.client.close()
client.client = httpx.Client(transport=httpx.MockTransport(handler))
files = client.list_pdfs("/Scanner/Eingang")
client.close()
assert len(files) == 1
assert files[0].name == "Scan A.PDF"
assert files[0].size == 123
assert files[0].path == "/Scanner/Eingang/Scan A.PDF"