You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/04/13 09:33:35 UTC

[29/46] libcloud git commit: convert fixtures in python 2

convert fixtures in python 2


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/50f47c82
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/50f47c82
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/50f47c82

Branch: refs/heads/trunk
Commit: 50f47c82859128d622ee9a7efe14662e2f141dc5
Parents: 69cb28d
Author: Anthony Shaw <an...@apache.org>
Authored: Wed Apr 12 17:37:34 2017 +1000
Committer: Anthony Shaw <an...@apache.org>
Committed: Wed Apr 12 17:37:34 2017 +1000

----------------------------------------------------------------------
 .../compute/fixtures/ecs/describe_images.xml    | 41 ---------------
 libcloud/test/file_fixtures.py                  |  2 +-
 libcloud/test/storage/test_cloudfiles.py        | 55 ++++----------------
 3 files changed, 12 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/50f47c82/libcloud/test/compute/fixtures/ecs/describe_images.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/describe_images.xml b/libcloud/test/compute/fixtures/ecs/describe_images.xml
index 80b1a31..e69de29 100644
--- a/libcloud/test/compute/fixtures/ecs/describe_images.xml
+++ b/libcloud/test/compute/fixtures/ecs/describe_images.xml
@@ -1,41 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<DescribeImagesResponse>
-	<PageNumber>1</PageNumber>
-	<TotalCount>1</TotalCount>
-	<PageSize>10</PageSize>
-	<RegionId>cn-qingdao</RegionId>
-	<RequestId>FAD4D9B9-D75F-4A9E-BC13-991C0F06F50F</RequestId>
-	<Images>
-		<Image>
-			<ImageId>freebsd1001_64_20G_aliaegis_20150527.vhd</ImageId>
-			<Description>freebsd1001_64_20G_aliaegis_20150527.vhd</Description>
-			<ProductCode></ProductCode>
-			<OSType>linux</OSType>
-			<Architecture>x86_64</Architecture>
-			<OSName>FreeBSD  10.1 64\u4f4d</OSName>
-			<DiskDeviceMappings>
-				<DiskDeviceMapping>
-					<ImportOSSObject></ImportOSSObject>
-					<Format></Format>
-					<Device>/dev/xvda</Device>
-					<SnapshotId></SnapshotId>
-					<ImportOSSBucket></ImportOSSBucket>
-					<Size>20</Size>
-				</DiskDeviceMapping>
-			</DiskDeviceMappings>
-			<ImageOwnerAlias>system</ImageOwnerAlias>
-			<Progress>100%</Progress>
-			<Usage>instance</Usage>
-			<CreationTime>2015-06-19T07:25:42Z</CreationTime>
-			<Tags />
-			<ImageVersion>1.0.0</ImageVersion>
-			<Status>Available</Status>
-			<ImageName>freebsd1001_64_20G_aliaegis_20150527.vhd</ImageName>
-			<IsSelfShared></IsSelfShared>
-			<IsCopied>false</IsCopied>
-			<IsSubscribed>false</IsSubscribed>
-			<Platform>Freebsd</Platform>
-			<Size>20</Size>
-		</Image>
-	</Images>
-</DescribeImagesResponse>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/50f47c82/libcloud/test/file_fixtures.py
----------------------------------------------------------------------
diff --git a/libcloud/test/file_fixtures.py b/libcloud/test/file_fixtures.py
index 502dec5..3d9bd32 100644
--- a/libcloud/test/file_fixtures.py
+++ b/libcloud/test/file_fixtures.py
@@ -50,7 +50,7 @@ class FileFixtures(object):
             else:
                 with codecs.open(path, 'r', 'utf-8') as fh:
                     content = fh.read()
-                    return content
+                return content
         else:
             raise IOError(path)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/50f47c82/libcloud/test/storage/test_cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py
index bf2ab6e..7e665f4 100644
--- a/libcloud/test/storage/test_cloudfiles.py
+++ b/libcloud/test/storage/test_cloudfiles.py
@@ -318,7 +318,7 @@ class CloudFilesTests(unittest.TestCase):
         self.assertTrue(result)
 
     def test_download_object_invalid_file_size(self):
-        CloudFilesMockRawResponse.type = 'INVALID_SIZE'
+        CloudFilesMockHttp.type = 'INVALID_SIZE'
         container = Container(name='foo_bar_container', extra={}, driver=self)
         obj = Object(name='foo_bar_object', size=1000, hash=None, extra={},
                      container=container, meta_data=None,
@@ -331,7 +331,7 @@ class CloudFilesTests(unittest.TestCase):
         self.assertFalse(result)
 
     def test_download_object_success_not_found(self):
-        CloudFilesMockRawResponse.type = 'NOT_FOUND'
+        CloudFilesMockHttp.type = 'NOT_FOUND'
         container = Container(name='foo_bar_container', extra={}, driver=self)
 
         obj = Object(name='foo_bar_object', size=1000, hash=None, extra={},
@@ -416,7 +416,7 @@ class CloudFilesTests(unittest.TestCase):
         self.driver.connection.request = old_request
 
     def test_upload_object_invalid_hash(self):
-        CloudFilesMockRawResponse.type = 'INVALID_HASH'
+        CloudFilesMockHttp.type = 'INVALID_HASH'
 
         def upload_file(self, object_name=None, content_type=None,
                         request_path=None, request_method=None,
@@ -459,35 +459,6 @@ class CloudFilesTests(unittest.TestCase):
         self.assertEqual(obj.name, object_name)
         libcloud.utils.files.guess_file_mime_type = old_func
 
-    def test_upload_object_error(self):
-        def dummy_content_type(name):
-            return 'application/zip', None
-
-        def send(instance):
-            raise Exception('')
-
-        old_func1 = libcloud.utils.files.guess_file_mime_type
-        libcloud.utils.files.guess_file_mime_type = dummy_content_type
-        old_func2 = CloudFilesMockHttp.send
-        CloudFilesMockHttp.send = send
-
-        file_path = os.path.abspath(__file__)
-        container = Container(name='foo_bar_container', extra={}, driver=self)
-        object_name = 'foo_test_upload'
-        try:
-            self.driver.upload_object(
-                file_path=file_path,
-                container=container,
-                object_name=object_name)
-        except LibcloudError:
-            pass
-        else:
-            self.fail(
-                'Timeout while uploading but an exception was not thrown')
-        finally:
-            libcloud.utils.files.guess_file_mime_type = old_func1
-            CloudFilesMockHttp.send = old_func2
-
     def test_upload_object_inexistent_file(self):
         def dummy_content_type(name):
             return 'application/zip', None
@@ -884,7 +855,7 @@ class CloudFilesDeprecatedUKTests(CloudFilesTests):
     region = 'lon'
 
 
-class CloudFilesMockHttp(MockHttp):
+class CloudFilesMockHttp(MockHttp, unittest.TestCase):
 
     fixtures = StorageFileFixtures('cloudfiles')
     base_headers = {'content-type': 'application/json; charset=UTF-8'}
@@ -1131,7 +1102,13 @@ class CloudFilesMockHttp(MockHttp):
             body = self.fixtures.load('list_container_objects_empty.json')
             headers = self.base_headers
             status_code = httplib.NO_CONTENT
-        return (status_code, body, headers, httplib.responses[httplib.OK])
+            return (status_code, body, headers, httplib.responses[httplib.OK])
+        elif method == 'GET':
+            body = generate_random_data(1000)
+            return (httplib.OK,
+                    body,
+                    self.base_headers,
+                    httplib.responses[httplib.OK])
 
     def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND(
             self, method, url, body, headers):
@@ -1190,16 +1167,6 @@ class CloudFilesMockHttp(MockHttp):
         return (httplib.CREATED, body, headers,
                 httplib.responses[httplib.OK])
 
-    def _v1_MossoCloudFS_foo_bar_container_foo_bar_object(
-            self, method, url, body, headers):
-
-        # test_download_object_success
-        body = generate_random_data(1000)
-        return (httplib.OK,
-                body,
-                self.base_headers,
-                httplib.responses[httplib.OK])
-
     def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE(
             self, method, url, body, headers):
         # test_download_object_invalid_file_size