import unittest from unittest import TestCase from lxml.etree import ElementTree, Element from webdav3.client import WebDavXmlUtils as utils class ClientTestCase(TestCase): def test_parse_get_list_response(self): content = '/test_dir/' \ 'HTTP/1.1 200 OK' \ 'Mon, 16 Oct 2017 04:18:00 GMT' \ 'test_dir2017-10-16T04:18:00Z' \ '/test_dir/test.txt/' \ 'HTTP/1.1 200 OK' \ 'Mon, 16 Oct 2017 04:18:18 GMTtest.txt' \ '2017-10-16T04:18:18Z' \ '' result = utils.parse_get_list_response(content) self.assertEquals(result.__len__(), 2) def test_create_free_space_request_content(self): result = utils.create_free_space_request_content() self.assertEquals(result, '\n' '') def test_parse_free_space_response(self): content = '/' \ 'HTTP/1.1 200 OK697' \ '10737417543' \ '' result = utils.parse_free_space_response(content, 'localhost') self.assertEquals(result, 10737417543) def test_parse_info_response(self): content = '' \ '/test_dir/test.txtHTTP/1.1 200 OK' \ 'Wed, 18 Oct 2017 15:16:04 GMT' \ 'ab0b4b7973803c03639b848682b5f38ctext/plain' \ '41test.txt' \ '2017-10-18T15:16:04Z' \ '' result = utils.parse_info_response(content, '/test_dir/test.txt', 'localhost') self.assertEquals(result['created'], '2017-10-18T15:16:04Z') self.assertEquals(result['name'], 'test.txt') self.assertEquals(result['modified'], 'Wed, 18 Oct 2017 15:16:04 GMT') self.assertEquals(result['size'], '41') def test_create_get_property_request_content(self): option = { 'namespace': 'test', 'name': 'aProperty' } result = utils.create_get_property_request_content(option=option, ) self.assertEquals(result, '\n' '') def test_create_get_property_request_content_name_only(self): option = { 'name': 'aProperty' } result = utils.create_get_property_request_content(option=option) self.assertEquals(result, '\n' '') def test_parse_get_property_response(self): content = '' \ '/test_dir/test.txtHTTP/1.1 200 OK' \ 'aValue' result = utils.parse_get_property_response(content=content, name='aProperty') self.assertEquals(result, 'aValue') def test_create_set_one_property_request_content(self): option = { 'namespace': 'test', 'name': 'aProperty', 'value': 'aValue' } result = utils.create_set_property_batch_request_content(options=[option]) self.assertEquals(result, '\n' 'aValue') def test_create_set_one_property_request_content_name_only(self): option = { 'name': 'aProperty' } result = utils.create_set_property_batch_request_content(options=[option]) self.assertEquals(result, '\n' '') def test_create_set_property_batch_request_content(self): options = [ { 'namespace': 'test', 'name': 'aProperty', 'value': 'aValue' }, { 'namespace': 'test2', 'name': 'aProperty2', 'value': 'aValue2' } ] result = utils.create_set_property_batch_request_content(options=options) self.assertEquals(result, '\n' 'aValueaValue2' '') def test_create_set_property_batch_request_content_name_only(self): options = [ { 'name': 'aProperty' }, { 'name': 'aProperty2' } ] result = utils.create_set_property_batch_request_content(options=options) self.assertEquals(result, '\n' '' '') def test_etree_to_string(self): tree = ElementTree(Element('test')) result = utils.etree_to_string(tree) self.assertEquals(result, '\n') if __name__ == '__main__': unittest.main()