remove support for redis 4, add redis 7, and clean up in tests

This commit is contained in:
Ken Cochrane 2023-02-22 16:15:12 -05:00
parent 482d4d2cf9
commit d474d7a656
3 changed files with 14 additions and 5 deletions

View file

@ -10,7 +10,7 @@ jobs:
max-parallel: 5
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8']
redis-version: [4, 5, 6]
redis-version: [5, 6, 7]
steps:
- uses: actions/checkout@v2

View file

@ -110,7 +110,7 @@ Requirements
* Python: 3.7, 3.8, 3.9, 3.10, PyPy
* Django: 3.x, 4.x
* Redis
* Redis: 5.x, 6.x, 7.x
Installation

View file

@ -1193,7 +1193,7 @@ class TestRedisConnection(TestCase):
@patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_PLAIN)
@patch("defender.config.MOCK_REDIS", False)
def test_get_redis_connection(self):
""" make sure the IP address is stripped of its port number """
""" get redis connection """
redis_client = get_redis_connection()
self.assertIsInstance(redis_client, Redis)
redis_client.set('test', 0)
@ -1204,7 +1204,7 @@ class TestRedisConnection(TestCase):
@patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_PASS)
@patch("defender.config.MOCK_REDIS", False)
def test_get_redis_connection_with_password(self):
""" make sure the IP address is stripped of its port number """
""" get redis connection with password """
connection = redis.Redis()
connection.config_set('requirepass', 'mypass')
@ -1215,14 +1215,20 @@ class TestRedisConnection(TestCase):
result = int(redis_client.get('test2'))
self.assertEqual(result, 0)
redis_client.delete('test2')
# clean up
connection.config_set('requirepass', '')
@patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_NAME_PASS)
@patch("defender.config.MOCK_REDIS", False)
def test_get_redis_connection_with_name_password(self):
""" make sure the IP address is stripped of its port number """
""" get redis connection with password and name """
connection = redis.Redis()
if connection.info().get('redis_version') < '6':
# redis versions before 6 don't have acl, so skip.
return
connection.acl_setuser(
'myname',
enabled=True,
@ -1236,3 +1242,6 @@ class TestRedisConnection(TestCase):
result = int(redis_client.get('test3'))
self.assertEqual(result, 0)
redis_client.delete('test3')
# clean up
connection.acl_deluser('myname')