libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 01/02: Fix test failure - we don't want to verify and refresh the token inside tests where we use an expired token.
Date Thu, 28 May 2020 11:39:43 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 4004375ccb9d5e899e70b85b33bb7a018c312eee
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Thu May 28 13:13:19 2020 +0200

    Fix test failure - we don't want to verify and refresh the token inside
    tests where we use an expired token.
---
 libcloud/test/compute/test_gig_g8.py | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/libcloud/test/compute/test_gig_g8.py b/libcloud/test/compute/test_gig_g8.py
index a9e7e14..3a4b18a 100644
--- a/libcloud/test/compute/test_gig_g8.py
+++ b/libcloud/test/compute/test_gig_g8.py
@@ -18,13 +18,23 @@ import base64
 import json
 import time
 
+import mock
+
 from libcloud.utils.py3 import httplib
 from libcloud.test import MockHttp
 from libcloud.compute.base import NodeImage, NodeSize, Node, StorageVolume
 from libcloud.compute.drivers.gig_g8 import G8NodeDriver, G8Network, G8PortForward
-from libcloud.common import gig_g8
+import libcloud.common.gig_g8
+
 from libcloud.test.file_fixtures import ComputeFileFixtures
 
+# For tests we don't want to actually verify a token since we use an expired on
+original_is_jwt_expired = libcloud.common.gig_g8.is_jwt_expired
+
+
+def mock_is_jwt_expired(jwt):
+    return False
+
 
 class G8MockHttp(MockHttp):
     """Fixtures needed for tests related to rating model"""
@@ -38,6 +48,7 @@ class G8MockHttp(MockHttp):
         return method
 
 
+@mock.patch('libcloud.common.gig_g8.is_jwt_expired', mock_is_jwt_expired)
 class G8Tests(unittest.TestCase):
     def setUp(self):
         G8NodeDriver.connectionCls.conn_class = G8MockHttp
@@ -161,12 +172,11 @@ class G8Tests(unittest.TestCase):
             jsondata = json.dumps(data).encode()
             return "header.{}.signature".format(base64.encodebytes(jsondata).decode())
 
-        self.assertTrue(gig_g8.is_jwt_expired(contruct_jwt(data)))
-        data["exp"] = int(time.time()) + 300  # expire in 5min
-        self.assertFalse(gig_g8.is_jwt_expired(contruct_jwt(data)))
-
-
+        libcloud.common.gig_g8.is_jwt_expired = original_is_jwt_expired
 
+        self.assertTrue(libcloud.common.gig_g8.is_jwt_expired(contruct_jwt(data)))
+        data["exp"] = int(time.time()) + 300  # expire in 5min
+        self.assertFalse(libcloud.common.gig_g8.is_jwt_expired(contruct_jwt(data)))
 
 
 if __name__ == '__main__':


Mime
View raw message