forked from jenkinsci/resources-ai-chatbot-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_env.py
More file actions
122 lines (99 loc) · 3.86 KB
/
test_env.py
File metadata and controls
122 lines (99 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Fixtures for unit tests."""
import pytest
from fastapi import FastAPI
from sentence_transformers import SentenceTransformer
from api.routes.chatbot import router
@pytest.fixture
def fastapi_app() -> FastAPI:
"""Fixture to create FastAPI app instance with routes."""
app = FastAPI()
app.include_router(router)
return app
@pytest.fixture
def mock_get_session(mocker):
"""Mock the memory.get_session function."""
return mocker.patch("api.services.chat_service.get_session")
@pytest.fixture
def mock_retrieve_context(mocker):
"""Mock the retrieve_context function."""
return mocker.patch("api.services.chat_service.retrieve_context")
@pytest.fixture
def mock_prompt_builder(mocker):
"""Mock the build_prompt function."""
return mocker.patch("api.services.chat_service.build_prompt")
@pytest.fixture
def mock_llm_provider(mocker):
"""Mock the LLM provider generate function."""
return mocker.patch("api.services.chat_service.llm_provider")
@pytest.fixture
def mock_get_relevant_documents(mocker):
"""Mock the get_relevant_documents function."""
return mocker.patch("api.services.chat_service.get_relevant_documents")
@pytest.fixture
def mock_init_session(mocker):
"""Mock the init_session function."""
return mocker.patch("api.routes.chatbot.init_session")
@pytest.fixture
def mock_session_exists(mocker):
"""Mock the session_exists function."""
return mocker.patch("api.routes.chatbot.session_exists")
@pytest.fixture
def mock_delete_session(mocker):
"""Mock the delete_session function."""
return mocker.patch("api.routes.chatbot.delete_session")
@pytest.fixture
def mock_list_sessions(mocker):
"""Mock the list_sessions function."""
return mocker.patch("api.routes.chatbot.list_sessions")
@pytest.fixture
def mock_get_chatbot_reply(mocker):
"""Mock the get_chatbot_reply function."""
return mocker.patch("api.routes.chatbot.get_chatbot_reply")
@pytest.fixture
def mock_process_uploaded_file(mocker):
"""Mock the process_uploaded_file function."""
return mocker.patch("api.routes.chatbot.process_uploaded_file")
@pytest.fixture
def mock_format_file_context(mocker):
"""Mock the format_file_context function."""
return mocker.patch("api.services.chat_service.format_file_context")
@pytest.fixture
def mock_sentence_transformer(mocker):
"""Mock the SentenceTransformer class constructor."""
return mocker.patch("rag.embedding.embedding_utils.SentenceTransformer")
@pytest.fixture
def mock_model_encode(mocker):
"""Fixture to create a mock SentenceTransformer model with encode function."""
mock_model = mocker.create_autospec(SentenceTransformer)
return mock_model
@pytest.fixture
def mock_collect_all_chunks(mocker):
"""Mock collect_all_chunks function."""
return mocker.patch("rag.embedding.embed_chunks.collect_all_chunks")
@pytest.fixture
def mock_load_embedding_model(mocker):
"""Mock load_embedding_model function."""
return mocker.patch("rag.embedding.embed_chunks.load_embedding_model")
@pytest.fixture
def mock_embed_documents(mocker):
"""Mock embed_documents function."""
return mocker.patch("rag.embedding.embed_chunks.embed_documents")
@pytest.fixture
def patched_chunk_files(mocker):
"""Fixture to patch CHUNK_FILES."""
return mocker.patch(
"rag.embedding.embed_chunks.CHUNK_FILES",
["file1.json", "file2.json", "file3.json"]
)
@pytest.fixture
def mock_load_chunks_from_file(mocker):
"""Mock load_chunks_from_file function."""
return mocker.patch("rag.embedding.embed_chunks.load_chunks_from_file")
@pytest.fixture
def mock_save_faiss_index(mocker):
"""Mock save_faiss_index function."""
return mocker.patch("rag.vectorstore.store_embeddings.save_faiss_index")
@pytest.fixture
def mock_save_metadata(mocker):
"""Mock save_metadata function."""
return mocker.patch("rag.vectorstore.store_embeddings.save_metadata")