libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 02/02: Improve tests - use separate mock method for two different test scenarios.
Date Mon, 01 Jul 2019 21:13:29 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit f8deceb04c41e36bc3002b3fd9c4f0d6e752b383
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Mon Jul 1 22:59:45 2019 +0200

    Improve tests - use separate mock method for two different test
    scenarios.
---
 libcloud/test/compute/test_ec2.py | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 475c2be..4049155 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -869,9 +869,11 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual('snap-30d37269', volumes[2].extra['snapshot_id'])
         self.assertEqual(StorageVolumeState.UNKNOWN, volumes[2].state)
 
-        EC2MockHttp.type = 'filters'
+        EC2MockHttp.type = 'filters_nodes'
         node = Node('i-d334b4b3', None, None, None, None, self.driver)
         self.driver.list_volumes(node=node)
+
+        EC2MockHttp.type = 'filters_status'
         self.driver.list_volumes(ex_filters={'status': 'available'})
 
     def test_create_volume(self):
@@ -1553,22 +1555,24 @@ class EC2MockHttp(MockHttp):
         body = self.fixtures.load('describe_volumes.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _filters_DescribeVolumes(self, method, url, body, headers):
-        expected_params_1 = {
+    def _filters_nodes_DescribeVolumes(self, method, url, body, headers):
+        expected_params = {
             'Filter.1.Name': 'attachment.instance-id',
             'Filter.1.Value.1': 'i-d334b4b3',
         }
 
-        expected_params_2 = {
+        self.assertUrlContainsQueryParams(url, expected_params)
+
+        body = self.fixtures.load('describe_volumes.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _filters_status_DescribeVolumes(self, method, url, body, headers):
+        expected_params = {
             'Filter.1.Name': 'status',
             'Filter.1.Value.1': 'available'
         }
 
-        try:
-            self.assertUrlContainsQueryParams(url, expected_params_1)
-        except AssertionError:
-            # dict ordering is not guaranteed
-            self.assertUrlContainsQueryParams(url, expected_params_2)
+        self.assertUrlContainsQueryParams(url, expected_params)
 
         body = self.fixtures.load('describe_volumes.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -1629,25 +1633,14 @@ class EC2MockHttp(MockHttp):
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _filters_DescribeVpcs(self, method, url, body, headers):
-        expected_params_1 = {
+        expected_params = {
             'Filter.1.Name': 'dhcp-options-id',
             'Filter.1.Value.1': 'dopt-7eded312',
             'Filter.2.Name': 'cidr',
             'Filter.2.Value.1': '192.168.51.0/24'
         }
 
-        expected_params_2 = {
-            'Filter.1.Name': 'cidr',
-            'Filter.1.Value.1': '192.168.51.0/24',
-            'Filter.2.Name': 'dhcp-options-id',
-            'Filter.2.Value.1': 'dopt-7eded312'
-        }
-
-        try:
-            self.assertUrlContainsQueryParams(url, expected_params_1)
-        except AssertionError:
-            # dict ordering is not guaranteed
-            self.assertUrlContainsQueryParams(url, expected_params_2)
+        self.assertUrlContainsQueryParams(url, expected_params)
 
         body = self.fixtures.load('describe_vpcs.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])


Mime
View raw message