1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
# Xandikos
# Copyright (C) 2025 Jelmer Vernooij <jelmer@jelmer.uk>, et al.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3
# of the License or (at your option) any later version of
# the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""Tests for RFC 5995 POST to Add Members to WebDAV Collections."""
import asyncio
import unittest
from xandikos import webdav
from xandikos.webdav import ET
class AddMemberPropertyTests(unittest.TestCase):
"""Tests for AddMemberProperty (RFC 5995 Section 3.2.1)."""
def test_property_name(self):
"""Test add-member property name."""
prop = webdav.AddMemberProperty()
self.assertEqual(prop.name, "{DAV:}add-member")
def test_property_attributes(self):
"""Test add-member property attributes.
RFC 5995 Section 3.2.1: The add-member property identifies the
URL where POST requests should be sent to add new members.
"""
prop = webdav.AddMemberProperty()
self.assertTrue(prop.live)
self.assertEqual(prop.resource_type, webdav.COLLECTION_RESOURCE_TYPE)
def test_get_value_collection_url(self):
"""Test add-member property value for collection.
RFC 5995 Section 3.2.1: The property contains a DAV:href element
pointing to the URL for POST operations (typically the collection itself).
"""
async def run_test():
prop = webdav.AddMemberProperty()
class MockResource:
pass
resource = MockResource()
el = ET.Element("test")
await prop.get_value("/collection/", resource, el, {})
hrefs = el.findall("{DAV:}href")
self.assertEqual(len(hrefs), 1)
# RFC 5995 uses "." to indicate the collection itself
self.assertEqual(hrefs[0].text, "/collection/")
asyncio.run(run_test())
def test_get_value_relative_resolution(self):
"""Test add-member with relative URL resolution."""
async def run_test():
prop = webdav.AddMemberProperty()
class MockResource:
pass
resource = MockResource()
el = ET.Element("test")
await prop.get_value("/calendars/user1/default/", resource, el, {})
hrefs = el.findall("{DAV:}href")
self.assertEqual(len(hrefs), 1)
# "." should resolve to the base href
self.assertEqual(hrefs[0].text, "/calendars/user1/default/")
asyncio.run(run_test())
def test_get_value_nested_collection(self):
"""Test add-member on nested collection."""
async def run_test():
prop = webdav.AddMemberProperty()
class MockResource:
pass
resource = MockResource()
el = ET.Element("test")
await prop.get_value("/a/b/c/", resource, el, {})
hrefs = el.findall("{DAV:}href")
self.assertEqual(len(hrefs), 1)
self.assertEqual(hrefs[0].text, "/a/b/c/")
asyncio.run(run_test())
class AddMemberFeatureTests(unittest.TestCase):
"""Tests for RFC 5995 add-member feature constant."""
def test_feature_constant(self):
"""Test add-member feature constant.
RFC 5995 Section 6: The feature identifier for add-member support.
"""
self.assertEqual(webdav.ADD_MEMBER_FEATURE, "add-member")
if __name__ == "__main__":
unittest.main()
|