Skip to content

Commit

Permalink
add missing redis:lock test
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Sep 5, 2024
1 parent 1f48c66 commit 61c3999
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class RedisLockTestCase(unittest.TestCase):
"""Tests for the redis_lock context manager"""

def setUp(self):
patcher = mock.patch.object(utils, 'Redis')
self.redis_patcher = mock.patch.object(utils, 'Redis')
mock.patch.object(utils, 'REDIS_HOST', 'test').start()
mock.patch.object(utils, 'REDIS_PORT', 6379).start()
self.redis_mock = patcher.start()
self.redis_mock = self.redis_patcher.start()
self.addCleanup(mock.patch.stopall)

def test_redis_lock_standard_usage(self):
Expand All @@ -41,6 +41,15 @@ def test_redis_lock_existing_lock(self):
self.assertFalse(acquired)
self.redis_mock.return_value.delete.assert_not_called()

def test_redis_lock_no_redis(self):
"""The lock should always grant access if Redis is not
available
"""
self.redis_patcher.stop()
with mock.patch.object(utils, 'Redis', None):
with utils.redis_lock('id', 'oid') as acquired:
self.assertTrue(acquired)
self.redis_patcher.start()

class UtilsTestCase(unittest.TestCase):
"""Tests for the utility functions"""
Expand Down

0 comments on commit 61c3999

Please sign in to comment.