From 17fae10abc26c8da90b4171f74da1bc821975f9d Mon Sep 17 00:00:00 2001 From: "Zimmermann, Stefan" Date: Thu, 20 Dec 2018 12:57:45 +0100 Subject: [PATCH] Fixing problems of integration and unit tests - AssertEquals deprecation warnings - Problems with byte/UTF strings and xml library --- .gitignore | 4 +++ tests/test_client_it.py | 17 +++++------ tests/test_client_unit.py | 60 +++++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 24b43f6..bf2fda7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ /**/*.pyc /dist /*.egg-info +/.eggs/ +.project +.pydevproject +/.settings/ diff --git a/tests/test_client_it.py b/tests/test_client_it.py index 52c5a60..cc4838b 100644 --- a/tests/test_client_it.py +++ b/tests/test_client_it.py @@ -60,7 +60,7 @@ class ClientTestCase(TestCase): self._prepare_for_downloading() buff = BytesIO() 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 " "be empty for file") @@ -110,7 +110,8 @@ class ClientTestCase(TestCase): def test_upload_from(self): 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.assertTrue(self.client.check(self.remote_path_file), 'Expected the file is uploaded.') @@ -165,8 +166,8 @@ class ClientTestCase(TestCase): def test_info(self): self._prepare_for_downloading() result = self.client.info(remote_path=self.remote_path_file) - self.assertEquals(result['name'], 'test.txt') - self.assertEquals(result['size'], '41') + self.assertEqual(result['name'], 'test.txt') + self.assertEqual(result['size'], '41') self.assertTrue('created' in result) self.assertTrue('modified' in result) @@ -181,7 +182,7 @@ class ClientTestCase(TestCase): def test_get_property_of_non_exist(self): self._prepare_for_downloading() 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): self._prepare_for_downloading() @@ -192,7 +193,7 @@ class ClientTestCase(TestCase): }) result = self.client.get_property(remote_path=self.remote_path_file, 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): self._prepare_for_downloading() @@ -210,10 +211,10 @@ class ClientTestCase(TestCase): ]) result = self.client.get_property(remote_path=self.remote_path_file, 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, 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): if not self.client.check(remote_path=self.remote_path_dir): diff --git a/tests/test_client_unit.py b/tests/test_client_unit.py index bbdb3c8..7489895 100644 --- a/tests/test_client_unit.py +++ b/tests/test_client_unit.py @@ -18,21 +18,21 @@ class ClientTestCase(TestCase): '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) + result = utils.parse_get_list_response(content.encode('utf-8')) + self.assertEqual(result.__len__(), 2) def test_create_free_space_request_content(self): result = utils.create_free_space_request_content() - self.assertEquals(result, '\n' - '') + self.assertEqual(result, b'\n' + b'') 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) + result = utils.parse_free_space_response(content.encode('utf-8'), 'localhost') + self.assertEqual(result, 10737417543) def test_parse_info_response(self): content = '' \ @@ -42,11 +42,11 @@ class ClientTestCase(TestCase): '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') + result = utils.parse_info_response(content.encode('utf-8'), '/test_dir/test.txt', 'localhost') + self.assertEqual(result['created'], '2017-10-18T15:16:04Z') + self.assertEqual(result['name'], 'test.txt') + self.assertEqual(result['modified'], 'Wed, 18 Oct 2017 15:16:04 GMT') + self.assertEqual(result['size'], '41') def test_create_get_property_request_content(self): option = { @@ -54,24 +54,24 @@ class ClientTestCase(TestCase): 'name': 'aProperty' } result = utils.create_get_property_request_content(option=option, ) - self.assertEquals(result, '\n' - '') + self.assertEqual(result, b'\n' + b'') 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' - '') + self.assertEqual(result, b'\n' + b'') 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') + result = utils.parse_get_property_response(content=content.encode('utf-8'), name='aProperty') + self.assertEqual(result, 'aValue') def test_create_set_one_property_request_content(self): option = { @@ -80,16 +80,16 @@ class ClientTestCase(TestCase): 'value': 'aValue' } result = utils.create_set_property_batch_request_content(options=[option]) - self.assertEquals(result, '\n' - 'aValue') + self.assertEqual(result, b'\n' + b'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' - '') + self.assertEqual(result, b'\n' + b'') def test_create_set_property_batch_request_content(self): options = [ @@ -105,9 +105,9 @@ class ClientTestCase(TestCase): } ] result = utils.create_set_property_batch_request_content(options=options) - self.assertEquals(result, '\n' - 'aValueaValue2' - '') + self.assertEqual(result, b'\n' + b'aValueaValue2' + b'') def test_create_set_property_batch_request_content_name_only(self): options = [ @@ -119,14 +119,14 @@ class ClientTestCase(TestCase): } ] result = utils.create_set_property_batch_request_content(options=options) - self.assertEquals(result, '\n' - '' - '') + self.assertEqual(result, b'\n' + b'' + b'') def test_etree_to_string(self): tree = ElementTree(Element('test')) result = utils.etree_to_string(tree) - self.assertEquals(result, '\n') + self.assertEqual(result, b'\n') def test_parse_is_dir_response_directory(self): content = '/' path = '/test_dir' 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') def test_parse_is_dir_response_directory(self): @@ -190,7 +190,7 @@ class ClientTestCase(TestCase): 'th>' path = '/test_dir/test.txt' 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')