Files
evanescere/tests/test_webdav_stability.py
2026-05-31 23:30:35 -07:00

53 lines
2.0 KiB
Python

from evanescere.services.webdav import WebDavFile, has_stable_size, parse_propfind_response
class DummyVideo:
def __init__(self, samples):
self.size_samples = samples
def test_has_stable_size_requires_two_equal_positive_samples():
assert not has_stable_size(DummyVideo([]))
assert not has_stable_size(DummyVideo([{"size_bytes": 100}]))
assert not has_stable_size(DummyVideo([{"size_bytes": 100}, {"size_bytes": 101}]))
assert has_stable_size(DummyVideo([{"size_bytes": 100}, {"size_bytes": 100}]))
def test_parse_propfind_response_filters_video_files():
xml = """<?xml version="1.0"?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>/webdav/recordings/</D:href>
<D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat>
</D:response>
<D:response>
<D:href>/webdav/recordings/stream.flv</D:href>
<D:propstat><D:prop><D:getcontentlength>123</D:getcontentlength></D:prop></D:propstat>
</D:response>
<D:response>
<D:href>/webdav/recordings/readme.txt</D:href>
<D:propstat><D:prop><D:getcontentlength>12</D:getcontentlength></D:prop></D:propstat>
</D:response>
</D:multistatus>"""
assert parse_propfind_response(xml, "https://host/webdav/recordings") == [
WebDavFile("https://host/webdav/recordings/stream.flv", "stream.flv", 123, None)
]
def test_parse_propfind_response_preserves_encoded_chinese_filename():
xml = """<?xml version="1.0"?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>/Hirumi/hirumi-2-06%E6%9C%8801%E6%97%A501%E6%97%B602%E5%88%8641%E7%A7%92.flv</D:href>
<D:propstat><D:prop><D:getcontentlength>123</D:getcontentlength></D:prop></D:propstat>
</D:response>
</D:multistatus>"""
assert parse_propfind_response(xml, "http://recording.home.arpa/Hirumi") == [
WebDavFile(
"http://recording.home.arpa/Hirumi/hirumi-2-06%E6%9C%8801%E6%97%A501%E6%97%B602%E5%88%8641%E7%A7%92.flv",
"hirumi-2-06月01日01时02分41秒.flv",
123,
None,
)
]