def test_parse_xml_content_broken(self): """Test WebDAVResponse._parse_xml_content with broken XML.""" response = Mock.Response() response.content = MULTISTATUS_BROKEN response.status = 207 with replaced(WebDAVResponse, _parse_xml_content=Mock.omnivore_func()): davresponse = WebDAVResponse(response) davresponse._parse_xml_content() empty = davresponse._etree.getroot().getchildren()[0] assert empty.tag == "empty"
def test_parse_xml_content_broken(self): """Test WebDAVResponse._parse_xml_content with broken XML.""" response = Mock.Response() response.content = MULTISTATUS_BROKEN response.status = 207 with replaced(WebDAVResponse, _parse_xml_content=Mock.omnivore_func()): davresponse = WebDAVResponse(response) davresponse._parse_xml_content() empty = davresponse._etree.getroot().getchildren()[0] self.assertEquals(empty.tag, "empty")
def test_parse_xml_content(self): """Test WebDAVResponse._parse_xml_content.""" response = Mock.Response() response.content = MULTISTATUS response.status = 207 with replaced(WebDAVResponse, _parse_xml_content=Mock.omnivore_func()): davresponse = WebDAVResponse(response) davresponse._parse_xml_content() href = davresponse._etree.findtext("/{DAV:}response/{DAV:}href") self.assertEquals(href, "/3/38/38f/38fa476aa97a4b2baeb41a481fdca00b")
def test_set_multistatus(self): """Test WebDAVResponse._set_multistatus.""" response = Mock.Response() response.content = MULTISTATUS response.status = 200 davresponse = WebDAVResponse(response) mockparser = Mock.Omnivore() with replaced(davresponse, _parse_xml_content=mockparser): assert not davresponse.is_multistatus assert len(mockparser.called["__call__"]) == 0 davresponse._set_multistatus() assert davresponse.is_multistatus assert len(mockparser.called["__call__"]) == 1
def test_set_multistatus(self): """Test WebDAVResponse._set_multistatus.""" response = Mock.Response() response.content = MULTISTATUS response.status = 200 davresponse = WebDAVResponse(response) mockparser = Mock.Omnivore() with replaced(davresponse, _parse_xml_content=mockparser): self.assertFalse(davresponse.is_multistatus) self.assertEquals(len(mockparser.called["__call__"]), 0) davresponse._set_multistatus() self.assertTrue(davresponse.is_multistatus) self.assertEquals(len(mockparser.called["__call__"]), 1)
def test_parse_xml_content(self): """Test WebDAVResponse._parse_xml_content.""" response = Mock.Response() if PYTHONVERSION >= (3, 0): # In Python3, HTTP Response.read() returns bytes, not str as in Python 2 response.content = bytes(MULTISTATUS, 'utf-8') else: response.content = MULTISTATUS response.status = 207 with replaced(WebDAVResponse, _parse_xml_content=Mock.omnivore_func()): davresponse = WebDAVResponse(response) davresponse._parse_xml_content() href = davresponse._etree.findtext("/{DAV:}response/{DAV:}href") assert href == "/3/38/38f/38fa476aa97a4b2baeb41a481fdca00b"