Skip to content

Commit 5bc5a9e

Browse files
committed
Refactor issue service tests to use asynchronous invocation and update repository service integration
1 parent c4f7b26 commit 5bc5a9e

2 files changed

Lines changed: 42 additions & 25 deletions

File tree

tests/app/api/test_issue.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ def test_answer_issue(mock_service):
3636
kg_chunk_size=1000,
3737
kg_chunk_overlap=100,
3838
)
39-
mock_service["issue_service"].answer_issue.return_value = (
40-
"feature/fix-42", # remote_branch_name
41-
"test patch", # patch
42-
True, # passed_reproducing_test
43-
True, # passed_build
44-
True, # passed_existing_test
45-
"Issue fixed", # issue_response
39+
mock_service["issue_service"].answer_issue = mock.AsyncMock(
40+
return_value=(
41+
"feature/fix-42", # remote_branch_name
42+
"test patch", # patch
43+
True, # passed_reproducing_test
44+
True, # passed_build
45+
True, # passed_existing_test
46+
"Issue fixed", # issue_response
47+
)
4648
)
4749

4850
response = client.post(
49-
"/issue/answer",
51+
"/issue/answer/",
5052
json={
5153
"repository_id": 1,
5254
"issue_number": 42,
@@ -74,7 +76,7 @@ def test_answer_issue_no_repository(mock_service):
7476
mock_service["repository_service"].get_repository_by_id.return_value = None
7577

7678
response = client.post(
77-
"/issue/answer",
79+
"/issue/answer/",
7880
json={
7981
"repository_id": 1,
8082
"issue_number": 42,
@@ -100,7 +102,7 @@ def test_answer_issue_invalid_container_config(mock_service):
100102
)
101103

102104
response = client.post(
103-
"/issue/answer",
105+
"/issue/answer/",
104106
json={
105107
"repository_id": 1,
106108
"issue_number": 42,
@@ -135,13 +137,15 @@ def test_answer_issue_with_container(mock_service):
135137

136138
mock_service["repository_service"].get_repository.return_value = git_repo
137139

138-
mock_service["issue_service"].answer_issue.return_value = (
139-
"feature/fix-42",
140-
"test patch",
141-
True,
142-
True,
143-
True,
144-
"Issue fixed",
140+
mock_service["issue_service"].answer_issue = mock.AsyncMock(
141+
return_value=(
142+
"feature/fix-42",
143+
"test patch",
144+
True,
145+
True,
146+
True,
147+
"Issue fixed",
148+
)
145149
)
146150

147151
test_payload = {
@@ -156,10 +160,11 @@ def test_answer_issue_with_container(mock_service):
156160
"test_commands": ["pytest ."],
157161
}
158162

159-
response = client.post("/issue/answer", json=test_payload)
163+
response = client.post("/issue/answer/", json=test_payload)
160164

161165
assert response.status_code == 200
162166
mock_service["issue_service"].answer_issue.assert_called_once_with(
167+
repository_id=1,
163168
repository=git_repo,
164169
knowledge_graph=knowledge_graph,
165170
issue_number=42,

tests/app/services/test_issue_service.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from prometheus.app.services.issue_service import IssueService
66
from prometheus.app.services.llm_service import LLMService
77
from prometheus.app.services.neo4j_service import Neo4jService
8+
from prometheus.app.services.repository_service import RepositoryService
89
from prometheus.git.git_repository import GitRepository
910
from prometheus.graph.knowledge_graph import KnowledgeGraph
1011
from prometheus.lang_graph.graphs.issue_state import IssueType
@@ -26,16 +27,24 @@ def mock_llm_service():
2627

2728

2829
@pytest.fixture
29-
def issue_service(mock_neo4j_service, mock_llm_service):
30+
def mock_repository_service():
31+
service = create_autospec(RepositoryService, instance=True)
32+
return service
33+
34+
35+
@pytest.fixture
36+
def issue_service(mock_neo4j_service, mock_llm_service, mock_repository_service):
3037
return IssueService(
31-
mock_neo4j_service,
32-
mock_llm_service,
38+
neo4j_service=mock_neo4j_service,
39+
llm_service=mock_llm_service,
40+
repository_service=mock_repository_service,
3341
max_token_per_neo4j_result=1000,
3442
working_directory="/tmp/working_dir/",
3543
)
3644

3745

38-
def test_answer_issue_with_general_container(issue_service, monkeypatch):
46+
@pytest.mark.asyncio
47+
async def test_answer_issue_with_general_container(issue_service, monkeypatch):
3948
# Setup
4049
mock_issue_graph = Mock()
4150
mock_issue_graph_class = Mock(return_value=mock_issue_graph)
@@ -64,7 +73,8 @@ def test_answer_issue_with_general_container(issue_service, monkeypatch):
6473
mock_issue_graph.invoke.return_value = mock_output_state
6574

6675
# Exercise
67-
result = issue_service.answer_issue(
76+
result = await issue_service.answer_issue(
77+
repository_id=1,
6878
repository=repository,
6979
knowledge_graph=knowledge_graph,
7080
issue_number=-1,
@@ -94,7 +104,8 @@ def test_answer_issue_with_general_container(issue_service, monkeypatch):
94104
assert result == (None, "test_patch", True, True, True, "test_response")
95105

96106

97-
def test_answer_issue_with_user_defined_container(issue_service, monkeypatch):
107+
@pytest.mark.asyncio
108+
async def test_answer_issue_with_user_defined_container(issue_service, monkeypatch):
98109
# Setup
99110
mock_issue_graph = Mock()
100111
mock_issue_graph_class = Mock(return_value=mock_issue_graph)
@@ -116,7 +127,8 @@ def test_answer_issue_with_user_defined_container(issue_service, monkeypatch):
116127
mock_issue_graph.invoke.return_value = mock_output_state
117128

118129
# Exercise
119-
result = issue_service.answer_issue(
130+
result = await issue_service.answer_issue(
131+
repository_id=1,
120132
repository=repository,
121133
knowledge_graph=knowledge_graph,
122134
issue_number=-1,

0 commit comments

Comments
 (0)