Skip to content

Commit

Permalink
Push for Igor
Browse files Browse the repository at this point in the history
  • Loading branch information
rmurray-r7 committed Nov 18, 2024
1 parent 25d1100 commit 7a3c34c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
38 changes: 12 additions & 26 deletions plugins/redis/unit_test/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@

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

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

from komand_redis.actions.delete.schema import DeleteInput, DeleteOutput
from insightconnect_plugin_runtime.exceptions import PluginException
from jsonschema import validate
from komand_redis.actions.delete import Delete
from parameterized import parameterized
import util

import redis

@patch("redis.StrictRedis", side_effect=util.mock_redis)
@patch('redis.StrictRedis', side_effect=Util.mock_redis)
class TestForward(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.action = util.Util.default_connector(Delete())
cls.action = 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)
def test_delete(self, _mock_request):
input_param = Util.load_json("inputs/delete.json.exp")
actual = self.action.run(input_param)
validate(input_param, DeleteInput.schema)
expect = Util.load_json("expected/delete_exp.json.exp")
self.assertEqual(expect, actual)
validate(actual, DeleteOutput.schema)

3 changes: 3 additions & 0 deletions plugins/redis/unit_test/expected/delete_exp.json.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"count": 0
}
3 changes: 3 additions & 0 deletions plugins/redis/unit_test/inputs/delete.json.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "user:1234"
}
39 changes: 23 additions & 16 deletions plugins/redis/unit_test/util.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import json
import logging
import os
import os.path
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
from komand_redis.connection import Connection
from komand_redis.connection.schema import Input

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

def default_connector(action: Action) -> Action:
class Util:
@staticmethod
def default_connector(action):
default_connection = Connection()
default_connection.logger = logging.getLogger("connection logger")
params = {"host": "127.0.0.1", "port": 8080, "db": 0}
Expand All @@ -20,17 +18,26 @@ def default_connector(action: Action) -> Action:
action.logger = logging.getLogger("action logger")
return action

class mock_redis():
@staticmethod
def load_json(filename):
with open((os.path.join(os.path.dirname(os.path.realpath(__file__)), filename))) as file:
return json.loads(file.read())

def __init__(self):
pass
@staticmethod
def mock_redis():

def delete(self):
return 10
class MockResponse:
def __init__(self):
pass

def get(self, params: str):
if params == "test":
return True
@staticmethod
def delete(self):
return 10

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



Expand Down

0 comments on commit 7a3c34c

Please sign in to comment.