Skip to content

Commit

Permalink
Update test_plugins.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresCdo committed Apr 20, 2023
1 parent e4caa99 commit 9d51fbc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@


def test_inspect_zip_for_module():
"""Test that the inspect_zip_for_module function works"""
# Test that the function returns the correct path
result = inspect_zip_for_module(str(f"{PLUGINS_TEST_DIR}/{PLUGIN_TEST_ZIP_FILE}"))
assert result == PLUGIN_TEST_INIT_PY


@pytest.fixture
def mock_config_denylist_allowlist_check():
"""Mock config object for testing the denylist_allowlist_check function"""
class MockConfig:
"""Mock config object for testing the denylist_allowlist_check function"""
plugins_denylist = ["BadPlugin"]
plugins_allowlist = ["GoodPlugin"]

Expand All @@ -30,6 +34,8 @@ class MockConfig:
def test_denylist_allowlist_check_denylist(
mock_config_denylist_allowlist_check, monkeypatch
):
"""Test that the denylist_allowlist_check function works"""
# Test that the function returns False when the plugin is in the denylist
monkeypatch.setattr("builtins.input", lambda _: "y")
assert not denylist_allowlist_check(
"BadPlugin", mock_config_denylist_allowlist_check
Expand All @@ -39,13 +45,17 @@ def test_denylist_allowlist_check_denylist(
def test_denylist_allowlist_check_allowlist(
mock_config_denylist_allowlist_check, monkeypatch
):
"""Test that the denylist_allowlist_check function works"""
# Test that the function returns True when the plugin is in the allowlist
monkeypatch.setattr("builtins.input", lambda _: "y")
assert denylist_allowlist_check("GoodPlugin", mock_config_denylist_allowlist_check)


def test_denylist_allowlist_check_user_input_yes(
mock_config_denylist_allowlist_check, monkeypatch
):
"""Test that the denylist_allowlist_check function works"""
# Test that the function returns True when the user inputs "y"
monkeypatch.setattr("builtins.input", lambda _: "y")
assert denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
Expand All @@ -55,6 +65,8 @@ def test_denylist_allowlist_check_user_input_yes(
def test_denylist_allowlist_check_user_input_no(
mock_config_denylist_allowlist_check, monkeypatch
):
"""Test that the denylist_allowlist_check function works"""
# Test that the function returns False when the user inputs "n"
monkeypatch.setattr("builtins.input", lambda _: "n")
assert not denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
Expand All @@ -64,6 +76,8 @@ def test_denylist_allowlist_check_user_input_no(
def test_denylist_allowlist_check_user_input_invalid(
mock_config_denylist_allowlist_check, monkeypatch
):
"""Test that the denylist_allowlist_check function works"""
# Test that the function returns False when the user inputs an invalid value
monkeypatch.setattr("builtins.input", lambda _: "invalid")
assert not denylist_allowlist_check(
"UnknownPlugin", mock_config_denylist_allowlist_check
Expand All @@ -72,6 +86,8 @@ def test_denylist_allowlist_check_user_input_invalid(

@pytest.fixture
def config_with_plugins():
"""Mock config object for testing the scan_plugins function"""
# Test that the function returns the correct number of plugins
cfg = Config()
cfg.plugins_dir = PLUGINS_TEST_DIR
cfg.plugins_openai = ["https://weathergpt.vercel.app/"]
Expand All @@ -80,7 +96,9 @@ def config_with_plugins():

@pytest.fixture
def mock_config_openai_plugin():
"""Mock config object for testing the scan_plugins function"""
class MockConfig:
"""Mock config object for testing the scan_plugins function"""
plugins_dir = PLUGINS_TEST_DIR
plugins_openai = [PLUGIN_TEST_OPENAI]
plugins_denylist = ["AutoGPTPVicuna"]
Expand All @@ -90,12 +108,16 @@ class MockConfig:


def test_scan_plugins_openai(mock_config_openai_plugin):
"""Test that the scan_plugins function works"""
# Test that the function returns the correct number of plugins
result = scan_plugins(mock_config_openai_plugin, debug=True)
assert len(result) == 1


@pytest.fixture
def mock_config_generic_plugin():
"""Mock config object for testing the scan_plugins function"""
# Test that the function returns the correct number of plugins
class MockConfig:
plugins_dir = PLUGINS_TEST_DIR
plugins_openai = []
Expand All @@ -106,5 +128,7 @@ class MockConfig:


def test_scan_plugins_generic(mock_config_generic_plugin):
"""Test that the scan_plugins function works"""
# Test that the function returns the correct number of plugins
result = scan_plugins(mock_config_generic_plugin, debug=True)
assert len(result) == 1

0 comments on commit 9d51fbc

Please sign in to comment.