[Python-modules-commits] [python-cs] 01/03: New upstream release.

Vincent Bernat bernat at moszumanska.debian.org
Mon Sep 18 17:37:47 UTC 2017


This is an automated email from the git hooks/post-receive script.

bernat pushed a commit to branch debian/master
in repository python-cs.

commit d1f7b2fc855ca017e9bd080f0126d1bfda5e1cb9
Author: Vincent Bernat <bernat at debian.org>
Date:   Mon Sep 18 19:34:57 2017 +0200

    New upstream release.
---
 cs.py    | 15 +++++++++------
 setup.py |  2 +-
 tests.py | 26 ++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/cs.py b/cs.py
index c6d1bfb..101c048 100644
--- a/cs.py
+++ b/cs.py
@@ -92,7 +92,7 @@ class Unauthorized(CloudStackException):
 
 class CloudStack(object):
     def __init__(self, endpoint, key, secret, timeout=10, method='get',
-                 verify=True, cert=None):
+                 verify=True, cert=None, name=None):
         self.endpoint = endpoint
         self.key = key
         self.secret = secret
@@ -100,9 +100,10 @@ class CloudStack(object):
         self.method = method.lower()
         self.verify = verify
         self.cert = cert
+        self.name = name
 
     def __repr__(self):
-        return '<CloudStack: {0}>'.format(self.endpoint)
+        return '<CloudStack: {0}>'.format(self.name or self.endpoint)
 
     def __getattr__(self, command):
         def handler(**kwargs):
@@ -145,8 +146,7 @@ class CloudStack(object):
                 msg = "Make sure endpoint URL '%s' is correct." % self.endpoint
                 raise CloudStackException(
                     "HTTP {0} response from CloudStack".format(
-                        response.status_code), response, "%s. " % str(e) + msg
-                    )
+                        response.status_code), response, "%s. " % str(e) + msg)
 
             [key] = data.keys()
             data = data[key]
@@ -199,6 +199,7 @@ def read_config(ini_group=None):
     else:
         env_conf['verify'] = os.environ.get('CLOUDSTACK_VERIFY', True)
         env_conf['cert'] = os.environ.get('CLOUDSTACK_CERT', None)
+        env_conf['name'] = None
         return env_conf
 
     # Config file: $PWD/cloudstack.ini or $HOME/.cloudstack.ini
@@ -216,9 +217,11 @@ def read_config(ini_group=None):
     conf = ConfigParser()
     conf.read(paths)
     try:
-        return conf[ini_group]
+        cs_conf = conf[ini_group]
     except AttributeError:  # python 2
-        return dict(conf.items(ini_group))
+        cs_conf = dict(conf.items(ini_group))
+    cs_conf['name'] = ini_group
+    return cs_conf
 
 
 def main():
diff --git a/setup.py b/setup.py
index 8ce1f19..779c222 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@ with open('README.rst', 'r') as f:
 
 setup(
     name='cs',
-    version='1.0.0',
+    version='1.1.1',
     url='https://github.com/exoscale/cs',
     license='BSD',
     author=u'Bruno Renié',
diff --git a/tests.py b/tests.py
index aac854e..0e706f6 100644
--- a/tests.py
+++ b/tests.py
@@ -69,6 +69,7 @@ class ConfigTest(TestCase):
                 'timeout': '10',
                 'verify': True,
                 'cert': None,
+                'name': None,
             })
 
         with env(CLOUDSTACK_KEY='test key from env',
@@ -87,6 +88,7 @@ class ConfigTest(TestCase):
                 'timeout': '99',
                 'verify': '/path/to/ca.pem',
                 'cert': '/path/to/cert.pem',
+                'name': None,
             })
 
     def test_current_dir_config(self):
@@ -105,6 +107,7 @@ class ConfigTest(TestCase):
                 'key': 'test key from file',
                 'secret': 'test secret from file',
                 'timeout': '50',
+                'name': 'cloudstack',
             })
 
 
@@ -130,6 +133,29 @@ class RequestTest(TestCase):
         )
 
     @patch('requests.get')
+    def test_request_params_casing(self, get):
+        cs = CloudStack(endpoint='localhost', key='foo', secret='bar',
+                        timeout=20)
+        get.return_value.status_code = 200
+        get.return_value.json.return_value = {
+            'listvirtualmachinesresponse': {},
+        }
+        machines = cs.listVirtualMachines(zoneId=2, templateId='3',
+                                          temPlateidd='4')
+        self.assertEqual(machines, {})
+        get.assert_called_once_with(
+            'localhost', timeout=20, verify=True, cert=None, params={
+                'apiKey': 'foo',
+                'response': 'json',
+                'command': 'listVirtualMachines',
+                'signature': 'dMRxAZcs2OPK15WUulzUtnrLWD0=',
+                'templateId': '3',
+                'temPlateidd': '4',
+                'zoneId': '2'
+            },
+        )
+
+    @patch('requests.get')
     def test_encoding(self, get):
         cs = CloudStack(endpoint='localhost', key='foo', secret='bar')
         get.return_value.status_code = 200

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-cs.git



More information about the Python-modules-commits mailing list