Fixing problems of integration and unit tests
- AssertEquals deprecation warnings - Problems with byte/UTF strings and xml library
This commit is contained in:
parent
2628a80e2f
commit
17fae10abc
3 changed files with 43 additions and 38 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -2,3 +2,7 @@
|
||||||
/**/*.pyc
|
/**/*.pyc
|
||||||
/dist
|
/dist
|
||||||
/*.egg-info
|
/*.egg-info
|
||||||
|
/.eggs/
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
/.settings/
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ClientTestCase(TestCase):
|
||||||
self._prepare_for_downloading()
|
self._prepare_for_downloading()
|
||||||
buff = BytesIO()
|
buff = BytesIO()
|
||||||
self.client.download_from(buff=buff, remote_path=self.remote_path_file)
|
self.client.download_from(buff=buff, remote_path=self.remote_path_file)
|
||||||
self.assertEquals(buff.getvalue(), 'test content for testing of webdav client')
|
self.assertEqual(buff.getvalue(), 'test content for testing of webdav client')
|
||||||
|
|
||||||
@unittest.skip("Yandex brakes response for file it contains property resourcetype as collection but it should "
|
@unittest.skip("Yandex brakes response for file it contains property resourcetype as collection but it should "
|
||||||
"be empty for file")
|
"be empty for file")
|
||||||
|
@ -110,7 +110,8 @@ class ClientTestCase(TestCase):
|
||||||
|
|
||||||
def test_upload_from(self):
|
def test_upload_from(self):
|
||||||
self._prepare_for_uploading()
|
self._prepare_for_uploading()
|
||||||
buff = StringIO(u'test content for testing of webdav client')
|
buff = StringIO()
|
||||||
|
buff.write(u'test content for testing of webdav client')
|
||||||
self.client.upload_to(buff=buff, remote_path=self.remote_path_file)
|
self.client.upload_to(buff=buff, remote_path=self.remote_path_file)
|
||||||
self.assertTrue(self.client.check(self.remote_path_file), 'Expected the file is uploaded.')
|
self.assertTrue(self.client.check(self.remote_path_file), 'Expected the file is uploaded.')
|
||||||
|
|
||||||
|
@ -165,8 +166,8 @@ class ClientTestCase(TestCase):
|
||||||
def test_info(self):
|
def test_info(self):
|
||||||
self._prepare_for_downloading()
|
self._prepare_for_downloading()
|
||||||
result = self.client.info(remote_path=self.remote_path_file)
|
result = self.client.info(remote_path=self.remote_path_file)
|
||||||
self.assertEquals(result['name'], 'test.txt')
|
self.assertEqual(result['name'], 'test.txt')
|
||||||
self.assertEquals(result['size'], '41')
|
self.assertEqual(result['size'], '41')
|
||||||
self.assertTrue('created' in result)
|
self.assertTrue('created' in result)
|
||||||
self.assertTrue('modified' in result)
|
self.assertTrue('modified' in result)
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ class ClientTestCase(TestCase):
|
||||||
def test_get_property_of_non_exist(self):
|
def test_get_property_of_non_exist(self):
|
||||||
self._prepare_for_downloading()
|
self._prepare_for_downloading()
|
||||||
result = self.client.get_property(remote_path=self.remote_path_file, option={'name': 'aProperty'})
|
result = self.client.get_property(remote_path=self.remote_path_file, option={'name': 'aProperty'})
|
||||||
self.assertEquals(result, None, 'For not found property should return value as None')
|
self.assertEqual(result, None, 'For not found property should return value as None')
|
||||||
|
|
||||||
def test_set_property(self):
|
def test_set_property(self):
|
||||||
self._prepare_for_downloading()
|
self._prepare_for_downloading()
|
||||||
|
@ -192,7 +193,7 @@ class ClientTestCase(TestCase):
|
||||||
})
|
})
|
||||||
result = self.client.get_property(remote_path=self.remote_path_file,
|
result = self.client.get_property(remote_path=self.remote_path_file,
|
||||||
option={'namespace': 'test', 'name': 'aProperty'})
|
option={'namespace': 'test', 'name': 'aProperty'})
|
||||||
self.assertEquals(result, 'aValue', 'Property value should be set')
|
self.assertEqual(result, 'aValue', 'Property value should be set')
|
||||||
|
|
||||||
def test_set_property_batch(self):
|
def test_set_property_batch(self):
|
||||||
self._prepare_for_downloading()
|
self._prepare_for_downloading()
|
||||||
|
@ -210,10 +211,10 @@ class ClientTestCase(TestCase):
|
||||||
])
|
])
|
||||||
result = self.client.get_property(remote_path=self.remote_path_file,
|
result = self.client.get_property(remote_path=self.remote_path_file,
|
||||||
option={'namespace': 'test', 'name': 'aProperty'})
|
option={'namespace': 'test', 'name': 'aProperty'})
|
||||||
self.assertEquals(result, 'aValue', 'First property value should be set')
|
self.assertEqual(result, 'aValue', 'First property value should be set')
|
||||||
result = self.client.get_property(remote_path=self.remote_path_file,
|
result = self.client.get_property(remote_path=self.remote_path_file,
|
||||||
option={'namespace': 'test', 'name': 'aProperty2'})
|
option={'namespace': 'test', 'name': 'aProperty2'})
|
||||||
self.assertEquals(result, 'aValue2', 'Second property value should be set')
|
self.assertEqual(result, 'aValue2', 'Second property value should be set')
|
||||||
|
|
||||||
def _prepare_for_downloading(self):
|
def _prepare_for_downloading(self):
|
||||||
if not self.client.check(remote_path=self.remote_path_dir):
|
if not self.client.check(remote_path=self.remote_path_dir):
|
||||||
|
|
|
@ -18,21 +18,21 @@ class ClientTestCase(TestCase):
|
||||||
'<d:getlastmodified>Mon, 16 Oct 2017 04:18:18 GMT</d:getlastmodified><d:displayname>test.txt' \
|
'<d:getlastmodified>Mon, 16 Oct 2017 04:18:18 GMT</d:getlastmodified><d:displayname>test.txt' \
|
||||||
'</d:displayname><d:creationdate>2017-10-16T04:18:18Z</d:creationdate></d:prop></d:propstat>' \
|
'</d:displayname><d:creationdate>2017-10-16T04:18:18Z</d:creationdate></d:prop></d:propstat>' \
|
||||||
'</d:response></d:multistatus>'
|
'</d:response></d:multistatus>'
|
||||||
result = utils.parse_get_list_response(content)
|
result = utils.parse_get_list_response(content.encode('utf-8'))
|
||||||
self.assertEquals(result.__len__(), 2)
|
self.assertEqual(result.__len__(), 2)
|
||||||
|
|
||||||
def test_create_free_space_request_content(self):
|
def test_create_free_space_request_content(self):
|
||||||
result = utils.create_free_space_request_content()
|
result = utils.create_free_space_request_content()
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
||||||
'<quota-available-bytes/><quota-used-bytes/></prop></propfind>')
|
b'<quota-available-bytes/><quota-used-bytes/></prop></propfind>')
|
||||||
|
|
||||||
def test_parse_free_space_response(self):
|
def test_parse_free_space_response(self):
|
||||||
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response><d:href>/</d:href>' \
|
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response><d:href>/</d:href>' \
|
||||||
'<d:propstat><d:status>HTTP/1.1 200 OK</d:status><d:prop><d:quota-used-bytes>697' \
|
'<d:propstat><d:status>HTTP/1.1 200 OK</d:status><d:prop><d:quota-used-bytes>697' \
|
||||||
'</d:quota-used-bytes><d:quota-available-bytes>10737417543</d:quota-available-bytes></d:prop>' \
|
'</d:quota-used-bytes><d:quota-available-bytes>10737417543</d:quota-available-bytes></d:prop>' \
|
||||||
'</d:propstat></d:response></d:multistatus>'
|
'</d:propstat></d:response></d:multistatus>'
|
||||||
result = utils.parse_free_space_response(content, 'localhost')
|
result = utils.parse_free_space_response(content.encode('utf-8'), 'localhost')
|
||||||
self.assertEquals(result, 10737417543)
|
self.assertEqual(result, 10737417543)
|
||||||
|
|
||||||
def test_parse_info_response(self):
|
def test_parse_info_response(self):
|
||||||
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response>' \
|
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response>' \
|
||||||
|
@ -42,11 +42,11 @@ class ClientTestCase(TestCase):
|
||||||
'</d:getcontenttype><d:getcontentlength>41</d:getcontentlength><d:displayname>test.txt' \
|
'</d:getcontenttype><d:getcontentlength>41</d:getcontentlength><d:displayname>test.txt' \
|
||||||
'</d:displayname><d:creationdate>2017-10-18T15:16:04Z</d:creationdate></d:prop></d:propstat>' \
|
'</d:displayname><d:creationdate>2017-10-18T15:16:04Z</d:creationdate></d:prop></d:propstat>' \
|
||||||
'</d:response></d:multistatus>'
|
'</d:response></d:multistatus>'
|
||||||
result = utils.parse_info_response(content, '/test_dir/test.txt', 'localhost')
|
result = utils.parse_info_response(content.encode('utf-8'), '/test_dir/test.txt', 'localhost')
|
||||||
self.assertEquals(result['created'], '2017-10-18T15:16:04Z')
|
self.assertEqual(result['created'], '2017-10-18T15:16:04Z')
|
||||||
self.assertEquals(result['name'], 'test.txt')
|
self.assertEqual(result['name'], 'test.txt')
|
||||||
self.assertEquals(result['modified'], 'Wed, 18 Oct 2017 15:16:04 GMT')
|
self.assertEqual(result['modified'], 'Wed, 18 Oct 2017 15:16:04 GMT')
|
||||||
self.assertEquals(result['size'], '41')
|
self.assertEqual(result['size'], '41')
|
||||||
|
|
||||||
def test_create_get_property_request_content(self):
|
def test_create_get_property_request_content(self):
|
||||||
option = {
|
option = {
|
||||||
|
@ -54,24 +54,24 @@ class ClientTestCase(TestCase):
|
||||||
'name': 'aProperty'
|
'name': 'aProperty'
|
||||||
}
|
}
|
||||||
result = utils.create_get_property_request_content(option=option, )
|
result = utils.create_get_property_request_content(option=option, )
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
||||||
'<aProperty xmlns="test"/></prop></propfind>')
|
b'<aProperty xmlns="test"/></prop></propfind>')
|
||||||
|
|
||||||
def test_create_get_property_request_content_name_only(self):
|
def test_create_get_property_request_content_name_only(self):
|
||||||
option = {
|
option = {
|
||||||
'name': 'aProperty'
|
'name': 'aProperty'
|
||||||
}
|
}
|
||||||
result = utils.create_get_property_request_content(option=option)
|
result = utils.create_get_property_request_content(option=option)
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propfind xmlns="DAV:"><prop>'
|
||||||
'<aProperty xmlns=""/></prop></propfind>')
|
b'<aProperty xmlns=""/></prop></propfind>')
|
||||||
|
|
||||||
def test_parse_get_property_response(self):
|
def test_parse_get_property_response(self):
|
||||||
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response>' \
|
content = '<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:"><d:response>' \
|
||||||
'<d:href>/test_dir/test.txt</d:href><d:propstat><d:status>HTTP/1.1 200 OK</d:status><d:prop>' \
|
'<d:href>/test_dir/test.txt</d:href><d:propstat><d:status>HTTP/1.1 200 OK</d:status><d:prop>' \
|
||||||
'<aProperty xmlns="test">aValue</aProperty></d:prop></d:propstat></d:response></d:multistatus>'
|
'<aProperty xmlns="test">aValue</aProperty></d:prop></d:propstat></d:response></d:multistatus>'
|
||||||
|
|
||||||
result = utils.parse_get_property_response(content=content, name='aProperty')
|
result = utils.parse_get_property_response(content=content.encode('utf-8'), name='aProperty')
|
||||||
self.assertEquals(result, 'aValue')
|
self.assertEqual(result, 'aValue')
|
||||||
|
|
||||||
def test_create_set_one_property_request_content(self):
|
def test_create_set_one_property_request_content(self):
|
||||||
option = {
|
option = {
|
||||||
|
@ -80,16 +80,16 @@ class ClientTestCase(TestCase):
|
||||||
'value': 'aValue'
|
'value': 'aValue'
|
||||||
}
|
}
|
||||||
result = utils.create_set_property_batch_request_content(options=[option])
|
result = utils.create_set_property_batch_request_content(options=[option])
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
||||||
'<aProperty xmlns="test">aValue</aProperty></prop></set></propertyupdate>')
|
b'<aProperty xmlns="test">aValue</aProperty></prop></set></propertyupdate>')
|
||||||
|
|
||||||
def test_create_set_one_property_request_content_name_only(self):
|
def test_create_set_one_property_request_content_name_only(self):
|
||||||
option = {
|
option = {
|
||||||
'name': 'aProperty'
|
'name': 'aProperty'
|
||||||
}
|
}
|
||||||
result = utils.create_set_property_batch_request_content(options=[option])
|
result = utils.create_set_property_batch_request_content(options=[option])
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
||||||
'<aProperty xmlns=""></aProperty></prop></set></propertyupdate>')
|
b'<aProperty xmlns=""></aProperty></prop></set></propertyupdate>')
|
||||||
|
|
||||||
def test_create_set_property_batch_request_content(self):
|
def test_create_set_property_batch_request_content(self):
|
||||||
options = [
|
options = [
|
||||||
|
@ -105,9 +105,9 @@ class ClientTestCase(TestCase):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
result = utils.create_set_property_batch_request_content(options=options)
|
result = utils.create_set_property_batch_request_content(options=options)
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
||||||
'<aProperty xmlns="test">aValue</aProperty><aProperty2 xmlns="test2">aValue2'
|
b'<aProperty xmlns="test">aValue</aProperty><aProperty2 xmlns="test2">aValue2'
|
||||||
'</aProperty2></prop></set></propertyupdate>')
|
b'</aProperty2></prop></set></propertyupdate>')
|
||||||
|
|
||||||
def test_create_set_property_batch_request_content_name_only(self):
|
def test_create_set_property_batch_request_content_name_only(self):
|
||||||
options = [
|
options = [
|
||||||
|
@ -119,14 +119,14 @@ class ClientTestCase(TestCase):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
result = utils.create_set_property_batch_request_content(options=options)
|
result = utils.create_set_property_batch_request_content(options=options)
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<propertyupdate xmlns="DAV:"><set><prop>'
|
||||||
'<aProperty xmlns=""></aProperty><aProperty2 xmlns=""></aProperty2></prop></set>'
|
b'<aProperty xmlns=""></aProperty><aProperty2 xmlns=""></aProperty2></prop></set>'
|
||||||
'</propertyupdate>')
|
b'</propertyupdate>')
|
||||||
|
|
||||||
def test_etree_to_string(self):
|
def test_etree_to_string(self):
|
||||||
tree = ElementTree(Element('test'))
|
tree = ElementTree(Element('test'))
|
||||||
result = utils.etree_to_string(tree)
|
result = utils.etree_to_string(tree)
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<test/>')
|
self.assertEqual(result, b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<test/>')
|
||||||
|
|
||||||
def test_parse_is_dir_response_directory(self):
|
def test_parse_is_dir_response_directory(self):
|
||||||
content = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><d:multistatus xmlns:d="DAV:"><d:response><d:href>/</d:h' \
|
content = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><d:multistatus xmlns:d="DAV:"><d:response><d:href>/</d:h' \
|
||||||
|
@ -175,7 +175,7 @@ class ClientTestCase(TestCase):
|
||||||
'</d:response></d:multistatus>'
|
'</d:response></d:multistatus>'
|
||||||
path = '/test_dir'
|
path = '/test_dir'
|
||||||
hostname = 'https://webdav.yandex.ru'
|
hostname = 'https://webdav.yandex.ru'
|
||||||
result = utils.parse_is_dir_response(content, path, hostname)
|
result = utils.parse_is_dir_response(content.encode('utf-8'), path, hostname)
|
||||||
self.assertTrue(result, 'It should be directory')
|
self.assertTrue(result, 'It should be directory')
|
||||||
|
|
||||||
def test_parse_is_dir_response_directory(self):
|
def test_parse_is_dir_response_directory(self):
|
||||||
|
@ -190,7 +190,7 @@ class ClientTestCase(TestCase):
|
||||||
'th><d:resourcetype/></d:prop></d:propstat></d:response></d:multistatus>'
|
'th><d:resourcetype/></d:prop></d:propstat></d:response></d:multistatus>'
|
||||||
path = '/test_dir/test.txt'
|
path = '/test_dir/test.txt'
|
||||||
hostname = 'https://webdav.yandex.ru'
|
hostname = 'https://webdav.yandex.ru'
|
||||||
result = utils.parse_is_dir_response(content, path, hostname)
|
result = utils.parse_is_dir_response(content.encode('utf-8'), path, hostname)
|
||||||
self.assertFalse(result, 'It should be file')
|
self.assertFalse(result, 'It should be file')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue