-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathtest_suggested_tasks.py
124 lines (111 loc) Β· 4.64 KB
/
test_suggested_tasks.py
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
123
124
from unittest.mock import AsyncMock
import pytest
from openhands.integrations.github.github_service import GitHubService
from openhands.integrations.service_types import TaskType, User
@pytest.mark.asyncio
async def test_get_suggested_tasks():
# Mock responses
mock_user = User(
id=1,
login='test-user',
avatar_url='https://example.com/avatar.jpg',
name='Test User',
)
# Mock GraphQL response
mock_graphql_response = {
'data': {
'user': {
'pullRequests': {
'nodes': [
{
'number': 1,
'title': 'PR with conflicts',
'repository': {'nameWithOwner': 'test-org/repo-1'},
'mergeable': 'CONFLICTING',
'commits': {
'nodes': [{'commit': {'statusCheckRollup': None}}]
},
'reviews': {'nodes': []},
},
{
'number': 2,
'title': 'PR with failing checks',
'repository': {'nameWithOwner': 'test-org/repo-1'},
'mergeable': 'MERGEABLE',
'commits': {
'nodes': [
{
'commit': {
'statusCheckRollup': {'state': 'FAILURE'}
}
}
]
},
'reviews': {'nodes': []},
},
{
'number': 4,
'title': 'PR with comments',
'repository': {'nameWithOwner': 'test-user/repo-2'},
'mergeable': 'MERGEABLE',
'commits': {
'nodes': [
{
'commit': {
'statusCheckRollup': {'state': 'SUCCESS'}
}
}
]
},
'reviews': {'nodes': [{'state': 'CHANGES_REQUESTED'}]},
},
]
},
'issues': {
'nodes': [
{
'number': 3,
'title': 'Assigned issue 1',
'repository': {'nameWithOwner': 'test-org/repo-1'},
},
{
'number': 5,
'title': 'Assigned issue 2',
'repository': {'nameWithOwner': 'test-user/repo-2'},
},
]
},
}
}
}
# Create service instance with mocked methods
service = GitHubService()
service.get_user = AsyncMock(return_value=mock_user)
service.execute_graphql_query = AsyncMock(return_value=mock_graphql_response)
# Call the function
tasks = await service.get_suggested_tasks()
# Verify the results
assert len(tasks) == 5 # Should have 5 tasks total
# Verify each task type is present
task_types = [task.task_type for task in tasks]
assert TaskType.MERGE_CONFLICTS in task_types
assert TaskType.FAILING_CHECKS in task_types
assert TaskType.UNRESOLVED_COMMENTS in task_types
assert TaskType.OPEN_ISSUE in task_types
assert (
len([t for t in task_types if t == TaskType.OPEN_ISSUE]) == 2
) # Should have 2 open issues
# Verify repositories are correct
repos = {task.repo for task in tasks}
assert 'test-org/repo-1' in repos
assert 'test-user/repo-2' in repos
# Verify specific tasks
conflict_pr = next(t for t in tasks if t.task_type == TaskType.MERGE_CONFLICTS)
assert conflict_pr.issue_number == 1
assert conflict_pr.title == 'PR with conflicts'
failing_pr = next(t for t in tasks if t.task_type == TaskType.FAILING_CHECKS)
assert failing_pr.issue_number == 2
assert failing_pr.title == 'PR with failing checks'
commented_pr = next(t for t in tasks if t.task_type == TaskType.UNRESOLVED_COMMENTS)
assert commented_pr.issue_number == 4
assert commented_pr.title == 'PR with comments'