Example #1
0
 def test_mkcol_exists(self):
     app = self.makeApp({
         '/resource': Resource(),
         '/resource/bla': Resource()}, [])
     code, headers, contents = self.mkcol(app, '/resource/bla')
     self.assertEqual('405 Method Not Allowed', code)
     self.assertEqual(b'', contents)
Example #2
0
 def test_mkcol_exists(self):
     app = self.makeApp(
         {
             "/resource": Resource(),
             "/resource/bla": Resource()
         }, [])
     code, headers, contents = self.mkcol(app, "/resource/bla")
     self.assertEqual("405 Method Not Allowed", code)
     self.assertEqual(b"", contents)
Example #3
0
    def test_propfind_found_multi(self):
        class TestProperty1(Property):
            name = '{DAV:}current-user-principal'

            async def get_value(self, href, resource, el, environ):
                ET.SubElement(el, '{DAV:}href').text = '/user/'

        class TestProperty2(Property):
            name = '{DAV:}somethingelse'

            async def get_value(self, href, resource, el, environ):
                pass
        app = self.makeApp(
            {'/resource': Resource()},
            [TestProperty1(), TestProperty2()]
        )
        code, headers, contents = self.propfind(app, '/resource', b"""\
<d:propfind xmlns:d="DAV:"><d:prop><d:current-user-principal/>\
<d:somethingelse/></d:prop></d:propfind>""")
        self.maxDiff = None
        self.assertMultiLineEqual(
            contents.decode('utf-8'),
            '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response>'
            '<ns0:href>/resource</ns0:href>'
            '<ns0:propstat><ns0:status>HTTP/1.1 200 OK</ns0:status>'
            '<ns0:prop><ns0:current-user-principal><ns0:href>/user/</ns0:href>'
            '</ns0:current-user-principal><ns0:somethingelse /></ns0:prop>'
            '</ns0:propstat></ns0:response></ns0:multistatus>')
        self.assertEqual(code, '207 Multi-Status')
Example #4
0
    def test_propfind_found_multi_status(self):
        class TestProperty(Property):
            name = "{DAV:}current-user-principal"

            async def get_value(self, href, resource, ret, environ):
                ET.SubElement(ret, "{DAV:}href").text = "/user/"

        app = self.makeApp({"/resource": Resource()}, [TestProperty()])
        code, headers, contents = self.propfind(
            app,
            "/resource",
            b"""\
<d:propfind xmlns:d="DAV:"><d:prop><d:current-user-principal/>\
<d:somethingelse/></d:prop></d:propfind>""",
        )
        self.maxDiff = None
        self.assertEqual(code, "207 Multi-Status")
        self.assertMultiLineEqual(
            contents.decode("utf-8"),
            """\
<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/resource</ns0:href>\
<ns0:propstat><ns0:status>HTTP/1.1 200 OK</ns0:status><ns0:prop>\
<ns0:current-user-principal><ns0:href>/user/</ns0:href>\
</ns0:current-user-principal></ns0:prop></ns0:propstat><ns0:propstat>\
<ns0:status>HTTP/1.1 404 Not Found</ns0:status><ns0:prop>\
<ns0:somethingelse /></ns0:prop></ns0:propstat>\
</ns0:response>\
</ns0:multistatus>""",
        )
Example #5
0
    def test_propfind_prop_does_not_exist(self):
        app = self.makeApp({'/resource': Resource()}, [])
        code, headers, contents = self.propfind(app, '/resource', b"""\
<d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype /></d:prop></d:propfind>""")
        self.assertMultiLineEqual(
            contents.decode('utf-8'),
            '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response>'
            '<ns0:href>/resource</ns0:href>'
            '<ns0:propstat><ns0:status>HTTP/1.1 404 Not Found</ns0:status>'
            '<ns0:prop><ns0:resourcetype /></ns0:prop></ns0:propstat>'
            '</ns0:response></ns0:multistatus>')
        self.assertEqual(code, '207 Multi-Status')
Example #6
0
    def test_propfind_prop_not_present(self):
        class TestProperty(Property):
            name = '{DAV:}current-user-principal'

            async def get_value(self, href, resource, ret, environ):
                raise KeyError
        app = self.makeApp({'/resource': Resource()}, [TestProperty()])
        code, headers, contents = self.propfind(app, '/resource', b"""\
<d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype /></d:prop></d:propfind>""")
        self.assertMultiLineEqual(
            contents.decode('utf-8'),
            '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response>'
            '<ns0:href>/resource</ns0:href>'
            '<ns0:propstat><ns0:status>HTTP/1.1 404 Not Found</ns0:status>'
            '<ns0:prop><ns0:resourcetype /></ns0:prop></ns0:propstat>'
            '</ns0:response></ns0:multistatus>')
        self.assertEqual(code, '207 Multi-Status')
Example #7
0
    def test_propfind_prop_does_not_exist(self):
        app = self.makeApp({"/resource": Resource()}, [])
        code, headers, contents = self.propfind(
            app,
            "/resource",
            b"""\
<d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype /></d:prop></d:propfind>""",
        )
        self.assertMultiLineEqual(
            contents.decode("utf-8"),
            '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response>'
            "<ns0:href>/resource</ns0:href>"
            "<ns0:propstat><ns0:status>HTTP/1.1 404 Not Found</ns0:status>"
            "<ns0:prop><ns0:resourcetype /></ns0:prop></ns0:propstat>"
            "</ns0:response></ns0:multistatus>",
        )
        self.assertEqual(code, "207 Multi-Status")