-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting point for initial unit test
- Loading branch information
1 parent
a474bdb
commit e2905e9
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|