-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
214 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import requests | ||
|
||
from cat.log import log | ||
|
||
|
||
async def registry_search_plugins( | ||
query: str = None, | ||
#author: str = None, | ||
#tag: str = None, | ||
): | ||
|
||
registry_url = "https://registry.cheshirecat.ai" | ||
|
||
try: | ||
if query: | ||
# search plugins | ||
url = f"{registry_url}/search" | ||
payload = { | ||
"query": query | ||
} | ||
response = requests.post(url, json=payload) | ||
return response.json() | ||
else: | ||
# list plugins as sorted by registry (no search) | ||
url = f"{registry_url}/plugins" | ||
params = { | ||
"page": 1, | ||
"page_size": 1000, | ||
} | ||
response = requests.get(url, params=params) | ||
return response.json()["plugins"] | ||
|
||
except Exception as e: | ||
log(e, "ERROR") | ||
return [] |
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 |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import os | ||
import time | ||
import pytest | ||
import shutil | ||
from tests.utils import key_in_json | ||
|
||
|
||
@pytest.mark.parametrize("key", ["installed", "registry"]) | ||
def test_list_plugins(client, key): | ||
# Act | ||
response = client.get("/plugins") | ||
def test_list_plugins(client): | ||
|
||
response_json = response.json() | ||
response = client.get("/plugins") | ||
json = response.json() | ||
|
||
# Assert | ||
assert response.status_code == 200 | ||
assert key_in_json(key, response_json) | ||
assert response_json["installed"][0]["id"] == "core_plugin" | ||
assert response_json["installed"][0]["active"] == True | ||
for key in ["filters", "installed", "registry"]: | ||
assert key in json.keys() | ||
|
||
# query | ||
for key in ["query"]: # ["query", "author", "tag"]: | ||
assert key in json["filters"].keys() | ||
|
||
# installed | ||
assert json["installed"][0]["id"] == "core_plugin" | ||
assert json["installed"][0]["active"] == True | ||
|
||
@pytest.mark.parametrize("keys", ["data"]) | ||
def test_get_plugin_id(client, keys): | ||
# Act | ||
# registry (see more registry tests in `./test_plugins_registry.py`) | ||
assert type(json["registry"] == list) | ||
assert len(json["registry"]) > 0 | ||
|
||
|
||
def test_get_plugin_id(client): | ||
|
||
response = client.get("/plugins/core_plugin") | ||
|
||
response_json = response.json() | ||
json = response.json() | ||
|
||
assert key_in_json(keys, response_json) | ||
assert response_json["data"] is not None | ||
assert response_json["data"]["id"] == "core_plugin" | ||
assert response_json["data"]["active"] == True | ||
assert "data" in json.keys() | ||
assert json["data"] is not None | ||
assert json["data"]["id"] == "core_plugin" | ||
assert json["data"]["active"] == True | ||
|
||
|
||
def test_get_non_existent_plugin(client): | ||
|
||
response = client.get("/plugins/no_plugin") | ||
response_json = response.json() | ||
json = response.json() | ||
|
||
assert response.status_code == 404 | ||
assert response_json["detail"]["error"] == "Plugin not found" | ||
|
||
assert json["detail"]["error"] == "Plugin not found" |
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,91 @@ | ||
import os | ||
|
||
# TODO: registry responses here should be mocked, at the moment we are actually calling the service | ||
|
||
def test_list_registry_plugins(client): | ||
|
||
response = client.get("/plugins") | ||
json = response.json() | ||
|
||
assert response.status_code == 200 | ||
assert "registry" in json.keys() | ||
assert type(json["registry"] == list) | ||
assert len(json["registry"]) > 0 | ||
|
||
# registry (see more registry tests in `./test_plugins_registry.py`) | ||
assert type(json["registry"] == list) | ||
assert len(json["registry"]) > 0 | ||
|
||
# query | ||
for key in ["query"]: # ["query", "author", "tag"]: | ||
assert key in json["filters"].keys() | ||
|
||
|
||
def test_list_registry_plugins_by_query(client): | ||
|
||
params = { | ||
"query": "podcast" | ||
} | ||
response = client.get("/plugins", params=params) | ||
json = response.json() | ||
print(json) | ||
|
||
assert response.status_code == 200 | ||
assert json["filters"]["query"] == params["query"] | ||
assert len(json["registry"]) > 0 # found registry plugins with text | ||
for plugin in json["registry"]: | ||
plugin_text = plugin["name"] + plugin["description"] | ||
assert params["query"] in plugin_text # verify searched text | ||
|
||
|
||
# TOOD: these tests are to be activated when also search by tag and author is activated in core | ||
''' | ||
def test_list_registry_plugins_by_author(client): | ||
params = { | ||
"author": "Nicola Corbellini" | ||
} | ||
response = client.get("/plugins", params=params) | ||
json = response.json() | ||
assert response.status_code == 200 | ||
assert json["filters"]["author"] == params["query"] | ||
assert len(json["registry"]) > 0 # found registry plugins with author | ||
for plugin in json["registry"]: | ||
assert params["author"] in plugin["author_name"] # verify author | ||
def test_list_registry_plugins_by_tag(client): | ||
params = { | ||
"tag": "llm" | ||
} | ||
response = client.get("/plugins", params=params) | ||
json = response.json() | ||
assert response.status_code == 200 | ||
assert json["filters"]["tag"] == params["tag"] | ||
assert len(json["registry"]) > 0 # found registry plugins with tag | ||
for plugin in json["registry"]: | ||
plugin_tags = plugin["tags"].split(", ") | ||
assert params["tag"] in plugin_tags # verify tag | ||
''' | ||
|
||
|
||
# take away from the list of availbale registry plugins, the ones that are already installed | ||
def test_list_registry_plugins_without_duplicating_installed_plugins(client): | ||
|
||
# 1. install plugin from registry | ||
# TODO !!! | ||
|
||
# 2. get available plugins searching for the one just installed | ||
params = { | ||
"query": "podcast" | ||
} | ||
response = client.get("/plugins", params=params) | ||
json = response.json() | ||
|
||
# 3. plugin should show up among installed by not among registry ones | ||
assert response.status_code == 200 | ||
# TODO plugin compares in installed!!! | ||
# TODO plugin does not appear in registry!!! |