Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add new method to disconnect to redis #47

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions RedisLibrary/RedisLibraryKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,20 @@ def delete_item_from_list_redis(self, redis_conn, list_name, index, item=None):
raise AssertionError
redis_conn.lset(list_name, index, 'DELETE_ITEM')
redis_conn.lrem(list_name, 1, 'DELETE_ITEM')

@keyword('Disconnect from Redis')
def disconnect_from_redis(self, redis_conn):
"""Securely disconnect from Redis database.

Arguments:
- redis_conn: Redis connection object

Examples:
| Disconnect from Redis | ${redis_conn} |
"""
try:
redis_conn.close()
logger.info("Disconnection successful")
except Exception as ex:
logger.error(f"Failed to disconnect: {ex}")
raise Exception(str(ex))
7 changes: 6 additions & 1 deletion tests/test_RedisLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = 'Traitanit Huangsri'
__email__ = '[email protected]'

from unittest.mock import MagicMock, patch
from RedisLibrary import RedisLibrary
import unittest, fakeredis, ast

Expand Down Expand Up @@ -315,5 +315,10 @@ def test_delete_item_from_list_redis_item_not_matched(self):
with self.assertRaises(AssertionError):
self.redis.delete_item_from_list_redis(self.fake_redis, 'Country', 2, 'Spain')

def test_disconnect_from_redis(self):
self.fake_redis.close = MagicMock()
self.assertIsNone(self.redis.disconnect_from_redis(self.fake_redis))
self.fake_redis.close.assert_called_once()

def tearDown(self):
self.fake_redis.flushall()