Skip to content

Commit

Permalink
Starting point for initial unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmurray-r7 committed Nov 18, 2024
1 parent a474bdb commit e2905e9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/redis/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# All dependencies must be version-pinned, eg. requests==1.2.0
# See: https://pip.pypa.io/en/stable/user_guide/#requirements-files
redis==4.3.6
parameterized==0.9.0
43 changes: 43 additions & 0 deletions plugins/redis/unit_test/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import sys

sys.path.append(os.path.abspath("../"))

from typing import Any, Dict
from unittest import TestCase
from unittest.mock import MagicMock, patch

from insightconnect_plugin_runtime.exceptions import PluginException
from jsonschema import validate
from komand_redis.actions.delete import Delete
from parameterized import parameterized
import util


@patch("redis.StrictRedis", side_effect=util.mock_redis)
class TestForward(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.action = util.Util.default_connector(Delete())

@parameterized.expand(
[
[
"delete",
{"key": "user:1234"},
{"count": 0}
]
]
)
def test_delete(
self,
_mock_request: MagicMock,
_test_name: str,
input_params: Dict[str, Any],
expected: Dict[str, Any],
) -> None:
validate(input_params, self.action.input.schema)
actual = self.action.run(input_params)
validate(actual, self.action.output.schema)
self.assertEqual(expected, actual)

38 changes: 38 additions & 0 deletions plugins/redis/unit_test/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
import logging
import os
import sys
from typing import Any, Dict, List
sys.path.append(os.path.abspath("../"))
from insightconnect_plugin_runtime.action import Action
from komand_redis.connection.connection import Connection

class Util():
def __init__(self):
pass

def default_connector(action: Action) -> Action:
default_connection = Connection()
default_connection.logger = logging.getLogger("connection logger")
params = {"host": "127.0.0.1", "port": 8080, "db": 0}
default_connection.connect(params)
action.connection = default_connection
action.logger = logging.getLogger("action logger")
return action

class mock_redis():

def __init__(self):
pass

def delete(self):
return 10

def get(self, params: str):
if params == "test":
return True





0 comments on commit e2905e9

Please sign in to comment.