libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [4/5] git commit: Add tests for _populate_hosts_and_request_paths method.
Date Fri, 15 Nov 2013 10:13:25 GMT
Add tests for _populate_hosts_and_request_paths method.


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

Branch: refs/heads/trunk
Commit: de823b0e1a690a7903d94bdd272a249ad85afb0f
Parents: 22caded
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Fri Nov 15 11:00:30 2013 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Fri Nov 15 11:00:30 2013 +0100

----------------------------------------------------------------------
 libcloud/test/compute/test_openstack.py | 39 ++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/de823b0e/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index e7edd3f..a8f0c3d 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -328,6 +328,45 @@ class OpenStack_1_0_Tests(unittest.TestCase, TestCaseMixin):
         self.driver.connection._populate_hosts_and_request_paths()
         clear_pricing_data()
 
+    def test_populate_hosts_and_requests_path(self):
+        tomorrow = datetime.datetime.today() + datetime.timedelta(1)
+        cls = self.driver_klass.connectionCls
+
+        count = 5
+
+        # Test authentication and token re-use
+        con = cls('username', 'key')
+        osa = con._osa
+
+        mocked_auth_method = Mock()
+        osa.authenticate = mocked_auth_method
+
+        # Valid token returned on first call, should be reused.
+        for i in range(0, count):
+            con._populate_hosts_and_request_paths()
+
+            if i == 0:
+                osa.auth_token = '1234'
+                osa.auth_token_expires = tomorrow
+
+        self.assertEqual(mocked_auth_method.call_count, 1)
+
+        osa.auth_token = None
+        osa.auth_token_expires = None
+
+        # ex_force_auth_token provided, authenticate should never be called
+        con = cls('username', 'key', ex_force_base_url='http://ponies',
+                  ex_force_auth_token='1234')
+        osa = con._osa
+
+        mocked_auth_method = Mock()
+        osa.authenticate = mocked_auth_method
+
+        for i in range(0, count):
+            con._populate_hosts_and_request_paths()
+
+        self.assertEqual(mocked_auth_method.call_count, 0)
+
     def test_auth_token_is_set(self):
         self.driver.connection._populate_hosts_and_request_paths()
         self.assertEqual(


Mime
View raw message