From bccf1dd2589a6385e3e68d1322f31a52cfc772b5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 8 Feb 2024 09:43:55 +0100 Subject: [PATCH] Patch redis module in tests Make sure the tests can be run even if redis isn't installed. --- tests/test_token_plugins.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_token_plugins.py b/tests/test_token_plugins.py index d13d944..f09ae8a 100644 --- a/tests/test_token_plugins.py +++ b/tests/test_token_plugins.py @@ -2,6 +2,7 @@ """ Unit tests for Token plugins""" +import sys import unittest from unittest.mock import patch, mock_open, MagicMock from jwcrypto import jwt, jwk @@ -178,6 +179,14 @@ class JWSTokenTestCase(unittest.TestCase): self.assertEqual(result[1], "remote_port") class TokenRedisTestCase(unittest.TestCase): + def setUp(self): + try: + import redis + except ImportError: + patcher = patch.dict(sys.modules, {'redis': MagicMock()}) + patcher.start() + self.addCleanup(patcher.stop) + @patch('redis.Redis') def test_empty(self, mock_redis): plugin = TokenRedis('127.0.0.1:1234')