You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/11/15 11:13:25 UTC
[4/5] git commit: Add tests for _populate_hosts_and_request_paths
method.
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 <to...@apache.org>
Authored: Fri Nov 15 11:00:30 2013 +0100
Committer: Tomaz Muraus <to...@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(