From 53781a511ef48f298573c03c57cffda2dab90051 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Wed, 21 Aug 2024 14:02:47 +0800 Subject: [PATCH] feat: init pytest workflow --- pyproject.toml | 3 +-- server/agent/bot_builder.py | 6 +++--- server/agent/qa_chat.py | 6 +++--- server/bot/builder.py | 2 +- server/dao/authorizationDAO.py | 4 ++-- server/dao/repositoryConfigDAO.py | 4 ++-- server/event_handler/discussion.py | 2 +- server/event_handler/issue.py | 2 +- server/main.py | 2 +- server/routers/auth.py | 2 +- server/routers/bot.py | 6 +++--- server/routers/chat.py | 6 +++--- server/routers/github.py | 12 ++++++------ server/routers/rag.py | 2 +- server/tests/test_main.py | 2 +- server/tools/bot_builder.py | 2 +- server/tools/issue.py | 2 +- server/utils/github.py | 6 +++--- server/verify/rate_limit.py | 2 +- 19 files changed, 36 insertions(+), 37 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f17610ac..f56a9cbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,8 +11,7 @@ builtins = ["_"] [pytest] testpaths = ["tests"] -rootdir = "server" -pythonpath = "server" +pythonpath = "." consider_namespace_packages = "True" python_files = "test_*.py" cov="com" diff --git a/server/agent/bot_builder.py b/server/agent/bot_builder.py index a7b94598..339873ba 100644 --- a/server/agent/bot_builder.py +++ b/server/agent/bot_builder.py @@ -1,9 +1,9 @@ from typing import AsyncIterator, Optional from petercat_utils.data_class import ChatData -from ..agent.base import AgentBuilder -from ..prompts.bot_builder import generate_prompt_by_user_id -from ..tools import bot_builder +from agent.base import AgentBuilder +from prompts.bot_builder import generate_prompt_by_user_id +from tools import bot_builder TOOL_MAPPING = { diff --git a/server/agent/qa_chat.py b/server/agent/qa_chat.py index 52717a72..1be7d8f9 100644 --- a/server/agent/qa_chat.py +++ b/server/agent/qa_chat.py @@ -2,9 +2,9 @@ from petercat_utils import get_client from petercat_utils.data_class import ChatData -from ..agent.base import AgentBuilder -from ..prompts.bot_template import generate_prompt_by_repo_name -from ..tools import issue, sourcecode, knowledge, git_info +from agent.base import AgentBuilder +from prompts.bot_template import generate_prompt_by_repo_name +from tools import issue, sourcecode, knowledge, git_info def get_tools(bot_id: str, token: Optional[str]): diff --git a/server/bot/builder.py b/server/bot/builder.py index 6c270835..35603ac8 100644 --- a/server/bot/builder.py +++ b/server/bot/builder.py @@ -5,7 +5,7 @@ from petercat_utils.data_class import RAGGitDocConfig from petercat_utils import git_doc_task -from ..prompts.bot_template import generate_prompt_by_repo_name +from prompts.bot_template import generate_prompt_by_repo_name g = Github() diff --git a/server/dao/authorizationDAO.py b/server/dao/authorizationDAO.py index 44f752ef..9fff5100 100644 --- a/server/dao/authorizationDAO.py +++ b/server/dao/authorizationDAO.py @@ -2,8 +2,8 @@ from petercat_utils.db.client.supabase import get_client -from ..dao.BaseDAO import BaseDAO -from ..models.authorization import Authorization +from dao.BaseDAO import BaseDAO +from models.authorization import Authorization class AuthorizationDAO(BaseDAO): client: Client diff --git a/server/dao/repositoryConfigDAO.py b/server/dao/repositoryConfigDAO.py index 89cc1372..dceb1d57 100644 --- a/server/dao/repositoryConfigDAO.py +++ b/server/dao/repositoryConfigDAO.py @@ -1,8 +1,8 @@ from supabase.client import Client from petercat_utils.db.client.supabase import get_client -from ..dao.BaseDAO import BaseDAO -from ..models.repository import RepositoryConfig +from dao.BaseDAO import BaseDAO +from models.repository import RepositoryConfig class RepositoryConfigDAO(BaseDAO): client: Client diff --git a/server/event_handler/discussion.py b/server/event_handler/discussion.py index c13f43fd..d0f8648d 100644 --- a/server/event_handler/discussion.py +++ b/server/event_handler/discussion.py @@ -5,7 +5,7 @@ from petercat_utils.data_class import ChatData, Message, TextContentBlock -from ..agent.qa_chat import agent_chat +from agent.qa_chat import agent_chat class DiscussionEventHandler: diff --git a/server/event_handler/issue.py b/server/event_handler/issue.py index 3db2b954..72eae3b5 100644 --- a/server/event_handler/issue.py +++ b/server/event_handler/issue.py @@ -4,7 +4,7 @@ from petercat_utils.data_class import ChatData, Message, TextContentBlock -from ..agent.qa_chat import agent_chat +from agent.qa_chat import agent_chat class IssueEventHandler: diff --git a/server/main.py b/server/main.py index 48270a30..80748ea4 100644 --- a/server/main.py +++ b/server/main.py @@ -7,7 +7,7 @@ # Import fastapi routers -from .routers import bot, health_checker, github, rag, auth, chat, task +from routers import bot, health_checker, github, rag, auth, chat, task AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN") API_AUDIENCE = get_env_variable("API_IDENTIFIER") diff --git a/server/routers/auth.py b/server/routers/auth.py index d0ce0a26..851b4949 100644 --- a/server/routers/auth.py +++ b/server/routers/auth.py @@ -4,7 +4,7 @@ import httpx from petercat_utils import get_client, get_env_variable -from ..auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserInfoByToken +from auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserInfoByToken AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN") diff --git a/server/routers/bot.py b/server/routers/bot.py index f674994a..7482fe33 100644 --- a/server/routers/bot.py +++ b/server/routers/bot.py @@ -3,9 +3,9 @@ from petercat_utils import get_client from typing import Annotated, Optional -from ..auth.get_user_info import get_user_id -from ..bot.builder import bot_builder, bot_info_generator -from ..type_class.bot import BotUpdateRequest, BotCreateRequest +from auth.get_user_info import get_user_id +from bot.builder import bot_builder, bot_info_generator +from type_class.bot import BotUpdateRequest, BotCreateRequest router = APIRouter( prefix="/api/bot", diff --git a/server/routers/chat.py b/server/routers/chat.py index 5ebd0114..ed865b11 100644 --- a/server/routers/chat.py +++ b/server/routers/chat.py @@ -3,9 +3,9 @@ from fastapi.responses import StreamingResponse from petercat_utils.data_class import ChatData -from ..agent import qa_chat, bot_builder -from ..verify.rate_limit import verify_rate_limit -from ..auth.get_user_info import get_user_access_token, get_user_id +from agent import qa_chat, bot_builder +from verify.rate_limit import verify_rate_limit +from auth.get_user_info import get_user_access_token, get_user_id router = APIRouter( diff --git a/server/routers/github.py b/server/routers/github.py index 9b08d4c0..33097bad 100644 --- a/server/routers/github.py +++ b/server/routers/github.py @@ -9,12 +9,12 @@ from petercat_utils import get_env_variable from jwt import JWT, jwk_from_pem -from ..auth.get_user_info import get_user_access_token -from ..dao.authorizationDAO import AuthorizationDAO -from ..dao.repositoryConfigDAO import RepositoryConfigDAO -from ..models.repository import RepositoryConfig -from ..models.authorization import Authorization -from ..utils.github import get_handler, get_private_key +from auth.get_user_info import get_user_access_token +from dao.authorizationDAO import AuthorizationDAO +from dao.repositoryConfigDAO import RepositoryConfigDAO +from models.repository import RepositoryConfig +from models.authorization import Authorization +from utils.github import get_handler, get_private_key APP_ID = get_env_variable("X_GITHUB_APP_ID") WEB_URL = get_env_variable("WEB_URL") diff --git a/server/routers/rag.py b/server/routers/rag.py index 04fe4510..a919f11c 100644 --- a/server/routers/rag.py +++ b/server/routers/rag.py @@ -13,7 +13,7 @@ git_issue_task, ) -from ..verify.rate_limit import verify_rate_limit +from verify.rate_limit import verify_rate_limit router = APIRouter( diff --git a/server/tests/test_main.py b/server/tests/test_main.py index 3526ddef..1612d400 100644 --- a/server/tests/test_main.py +++ b/server/tests/test_main.py @@ -1,5 +1,5 @@ from fastapi.testclient import TestClient -from ..main import app +from main import app client = TestClient(app) diff --git a/server/tools/bot_builder.py b/server/tools/bot_builder.py index 01363190..9f39079f 100644 --- a/server/tools/bot_builder.py +++ b/server/tools/bot_builder.py @@ -4,7 +4,7 @@ from github import Github from petercat_utils import get_client -from ..bot.builder import bot_builder +from bot.builder import bot_builder g = Github() diff --git a/server/tools/issue.py b/server/tools/issue.py index b937cbc2..4e44e09a 100644 --- a/server/tools/issue.py +++ b/server/tools/issue.py @@ -3,7 +3,7 @@ from github import Auth, Github from langchain.tools import tool -from ..tools.helper import need_github_login +from tools.helper import need_github_login DEFAULT_REPO_NAME = "ant-design/ant-design" diff --git a/server/utils/github.py b/server/utils/github.py index ce2df27e..71a51c83 100644 --- a/server/utils/github.py +++ b/server/utils/github.py @@ -4,9 +4,9 @@ from petercat_utils import get_env_variable from github import Auth -from ..event_handler.pull_request import PullRequestEventHandler -from ..event_handler.discussion import DiscussionEventHandler -from ..event_handler.issue import IssueEventHandler +from event_handler.pull_request import PullRequestEventHandler +from event_handler.discussion import DiscussionEventHandler +from event_handler.issue import IssueEventHandler APP_ID = get_env_variable("X_GITHUB_APP_ID") diff --git a/server/verify/rate_limit.py b/server/verify/rate_limit.py index 14db30f6..cb820378 100644 --- a/server/verify/rate_limit.py +++ b/server/verify/rate_limit.py @@ -4,7 +4,7 @@ from petercat_utils import get_client, get_env_variable -from ..auth.get_user_info import getUserInfoByToken +from auth.get_user_info import getUserInfoByToken RATE_LIMIT_ENABLED = get_env_variable("RATE_LIMIT_ENABLED", "False") == 'True' RATE_LIMIT_REQUESTS = get_env_variable("RATE_LIMIT_REQUESTS") or 100