Пример #1
0
 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")
Пример #2
0
 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"
Пример #3
0
 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")
Пример #4
0
 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
Пример #5
0
 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)
Пример #6
0
 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"
Пример #7
0
 def test_iter_207(self):
     """Test WebDAVResponse.__iter__ in Multi-Status."""
     response = Mock.Response()
     response.content = MULTISTATUS
     response.status = 207
     davresponse = WebDAVResponse(response)
     assert list(davresponse)[0] == 200
Пример #8
0
 def test_iter(self):
     """Test WebDAVResponse.__iter__."""
     response = Mock.Response()
     response.content = MULTISTATUS
     response.status = 200
     davresponse = WebDAVResponse(response)
     assert isinstance(list(davresponse)[0], WebDAVResponse)
Пример #9
0
 def test_len_207(self):
     """Test WebDAVResponse.__len__ in Multi-Status."""
     response = Mock.Response()
     response.content = MULTISTATUS
     response.status = 207
     davresponse = WebDAVResponse(response)
     assert len(davresponse) == 1
Пример #10
0
 def test_init(self):
     """Test initializing the WebDAVResponse."""
     response = Mock.Response()
     response.content = MULTISTATUS
     # no parsing
     response.status = 200
     davresponse = WebDAVResponse(response)
     assert not bool(davresponse._etree.getroot())
     # parsing
     response.status = 207
     davresponse = WebDAVResponse(response)
     assert bool(davresponse._etree.getroot())
     # broken xml
     response.status = 207
     response.content = MULTISTATUS_BROKEN
     davresponse = WebDAVResponse(response)
     assert bool(davresponse._etree.getroot())
     assert isinstance(davresponse.parse_error, ParseError)