Coverage for tests / conftest.py: 79%
52 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 10:07 -0500
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 10:07 -0500
1"""
2Shared pytest fixtures for jira-jsm skill tests.
4Provides mock JIRA Service Management API responses and client fixtures
5for testing JSM functionality without hitting real JIRA instance.
6"""
8import pytest
9from unittest.mock import Mock
10import sys
11from pathlib import Path
13# Add shared lib to path so imports work in tests
14shared_lib_path = str(Path(__file__).parent.parent.parent.parent / 'shared' / 'scripts' / 'lib')
15if shared_lib_path not in sys.path:
16 sys.path.insert(0, shared_lib_path)
18# Add scripts to path for importing
19scripts_path = str(Path(__file__).parent.parent / 'scripts')
20if scripts_path not in sys.path:
21 sys.path.insert(0, scripts_path)
24@pytest.fixture
25def mock_jira_client():
26 """Mock JiraClient for testing JSM without API calls."""
27 client = Mock()
28 client.base_url = "https://test.atlassian.net"
29 client.email = "test@example.com"
30 client.close = Mock()
32 # Mock service desk methods
33 client.get_service_desks.return_value = {
34 "size": 3,
35 "start": 0,
36 "limit": 50,
37 "isLastPage": True,
38 "values": [
39 {
40 "id": "1",
41 "projectId": "10000",
42 "projectName": "IT Service Desk",
43 "projectKey": "ITS"
44 },
45 {
46 "id": "2",
47 "projectId": "10001",
48 "projectName": "HR Service Desk",
49 "projectKey": "HR"
50 },
51 {
52 "id": "3",
53 "projectId": "10002",
54 "projectName": "Facilities",
55 "projectKey": "FAC"
56 }
57 ]
58 }
60 client.get_service_desk.return_value = {
61 "id": "1",
62 "projectId": "10000",
63 "projectName": "IT Service Desk",
64 "projectKey": "ITS"
65 }
67 client.get_request_types.return_value = {
68 "size": 2,
69 "start": 0,
70 "limit": 50,
71 "isLastPage": True,
72 "values": [
73 {
74 "id": "25",
75 "name": "Get IT help",
76 "description": "Request help from your IT team",
77 "issueTypeId": "10001"
78 },
79 {
80 "id": "26",
81 "name": "Report incident",
82 "description": "Report a system problem",
83 "issueTypeId": "10002"
84 }
85 ]
86 }
88 client.get_request_type.return_value = {
89 "id": "25",
90 "name": "Get IT help",
91 "description": "Request help from your IT team",
92 "helpText": "Please provide detailed information",
93 "issueTypeId": "10001",
94 "serviceDeskId": "1"
95 }
97 client.get_request_type_fields.return_value = {
98 "requestTypeFields": [
99 {
100 "fieldId": "summary",
101 "name": "Summary",
102 "description": "Brief description",
103 "required": True,
104 "jiraSchema": {"type": "string"}
105 },
106 {
107 "fieldId": "description",
108 "name": "Description",
109 "description": "Detailed description",
110 "required": False,
111 "jiraSchema": {"type": "string"}
112 }
113 ],
114 "canRaiseOnBehalfOf": False,
115 "canAddRequestParticipants": True
116 }
118 client.create_service_desk.return_value = {
119 "id": "5",
120 "projectId": "10005",
121 "projectName": "New Service Desk",
122 "projectKey": "NSD"
123 }
125 return client
128@pytest.fixture
129def sample_customer_response():
130 """Sample JSM API response for a customer."""
131 return {
132 "accountId": "5b10ac8d82e05b22cc7d4ef5",
133 "name": "John Customer",
134 "emailAddress": "john@example.com",
135 "displayName": "John Customer",
136 "active": True,
137 "timeZone": "America/New_York",
138 "_links": {
139 "jiraRest": "https://test.atlassian.net/rest/api/2/user?accountId=5b10ac8d82e05b22cc7d4ef5",
140 "self": "https://test.atlassian.net/rest/servicedeskapi/customer/5b10ac8d82e05b22cc7d4ef5"
141 }
142 }
145@pytest.fixture
146def sample_customers_list_response():
147 """Sample JSM API response for listing customers."""
148 return {
149 "size": 3,
150 "start": 0,
151 "limit": 50,
152 "isLastPage": True,
153 "_links": {
154 "base": "https://test.atlassian.net/rest/servicedeskapi",
155 "context": "",
156 "self": "https://test.atlassian.net/rest/servicedeskapi/servicedesk/1/customer"
157 },
158 "values": [
159 {
160 "accountId": "5b10ac8d82e05b22cc7d4ef5",
161 "name": "John Customer",
162 "emailAddress": "john@example.com",
163 "displayName": "John Customer",
164 "active": True
165 },
166 {
167 "accountId": "5b109f2e9729b51b54dc274d",
168 "name": "Jane Smith",
169 "emailAddress": "jane@example.com",
170 "displayName": "Jane Smith",
171 "active": True
172 },
173 {
174 "accountId": "5b108c2e9729b51b54dc2751",
175 "name": "Bob Johnson",
176 "emailAddress": "bob@example.com",
177 "displayName": "Bob Johnson",
178 "active": False
179 }
180 ]
181 }
184@pytest.fixture
185def sample_service_desk_response():
186 """Sample JSM API response for a service desk."""
187 return {
188 "id": "1",
189 "projectId": "10000",
190 "projectKey": "SD",
191 "projectName": "IT Service Desk",
192 "_links": {
193 "self": "https://test.atlassian.net/rest/servicedeskapi/servicedesk/1"
194 }
195 }
198@pytest.fixture
199def mock_config_manager(mock_jira_client):
200 """Mock config_manager.get_jira_client() to return mock client."""
201 def _get_jira_client(profile=None):
202 return mock_jira_client
203 return _get_jira_client
206@pytest.fixture
207def sample_request_type_response():
208 """Sample JSM API response for a request type."""
209 return {
210 "id": "10",
211 "name": "Incident",
212 "description": "Report an incident",
213 "helpText": "Use this for urgent issues",
214 "serviceDeskId": "1",
215 "groupIds": [],
216 "_links": {
217 "self": "https://test.atlassian.net/rest/servicedeskapi/servicedesk/1/requesttype/10"
218 }
219 }
222@pytest.fixture
223def sample_request_response():
224 """Sample JSM API response for a created request."""
225 return {
226 "issueId": "10010",
227 "issueKey": "SD-101",
228 "requestTypeId": "10",
229 "requestType": {
230 "id": "10",
231 "name": "Incident",
232 "description": "Report an incident"
233 },
234 "serviceDeskId": "1",
235 "createdDate": {
236 "iso8601": "2025-01-15T10:30:00+0000",
237 "epochMillis": 1736936400000,
238 "friendly": "Today 10:30 AM"
239 },
240 "reporter": {
241 "accountId": "557058:abc123",
242 "displayName": "Alice Reporter",
243 "emailAddress": "alice@example.com"
244 },
245 "requestFieldValues": [
246 {
247 "fieldId": "summary",
248 "label": "Summary",
249 "value": "Email not working"
250 },
251 {
252 "fieldId": "description",
253 "label": "Description",
254 "value": "Cannot send emails since this morning"
255 }
256 ],
257 "currentStatus": {
258 "status": "Waiting for support",
259 "statusCategory": "NEW",
260 "statusDate": {
261 "iso8601": "2025-01-15T10:30:00+0000",
262 "epochMillis": 1736936400000
263 }
264 },
265 "_links": {
266 "self": "https://test.atlassian.net/rest/servicedeskapi/request/SD-101",
267 "web": "https://test.atlassian.net/servicedesk/customer/portal/1/SD-101",
268 "agent": "https://test.atlassian.net/browse/SD-101"
269 }
270 }
273@pytest.fixture
274def sample_request_with_sla():
275 """Sample request response with SLA information."""
276 return {
277 "issueKey": "SD-101",
278 "issueId": "10010",
279 "requestTypeId": "10",
280 "serviceDeskId": "1",
281 "currentStatus": {
282 "status": "In Progress",
283 "statusCategory": "IN_PROGRESS"
284 },
285 "sla": {
286 "values": [
287 {
288 "id": "1",
289 "name": "Time to First Response",
290 "ongoingCycle": {
291 "breached": False,
292 "goalDuration": {"millis": 3600000},
293 "elapsedTime": {"millis": 900000},
294 "remainingTime": {"millis": 2700000}
295 }
296 },
297 {
298 "id": "2",
299 "name": "Time to Resolution",
300 "ongoingCycle": {
301 "breached": False,
302 "goalDuration": {"millis": 14400000},
303 "elapsedTime": {"millis": 12600000},
304 "remainingTime": {"millis": 1800000}
305 }
306 }
307 ]
308 }
309 }
312@pytest.fixture
313def sample_status_history():
314 """Sample status history response."""
315 return {
316 "values": [
317 {
318 "status": "Open",
319 "statusCategory": "NEW",
320 "statusDate": {
321 "iso8601": "2025-01-15T10:30:00+0000",
322 "epochMillis": 1736936400000,
323 "friendly": "Today 10:30 AM"
324 }
325 },
326 {
327 "status": "In Progress",
328 "statusCategory": "IN_PROGRESS",
329 "statusDate": {
330 "iso8601": "2025-01-15T11:00:00+0000",
331 "epochMillis": 1736938200000,
332 "friendly": "Today 11:00 AM"
333 }
334 },
335 {
336 "status": "Resolved",
337 "statusCategory": "DONE",
338 "statusDate": {
339 "iso8601": "2025-01-15T14:30:00+0000",
340 "epochMillis": 1736950800000,
341 "friendly": "Today 2:30 PM"
342 }
343 }
344 ]
345 }
348@pytest.fixture
349def sample_transitions_response():
350 """Sample transitions response."""
351 return {
352 "values": [
353 {
354 "id": "11",
355 "name": "Start Progress",
356 "to": {
357 "id": "3",
358 "name": "In Progress"
359 }
360 },
361 {
362 "id": "21",
363 "name": "Waiting for Customer",
364 "to": {
365 "id": "10",
366 "name": "Waiting for customer"
367 }
368 },
369 {
370 "id": "31",
371 "name": "Resolve",
372 "to": {
373 "id": "5",
374 "name": "Resolved"
375 }
376 }
377 ]
378 }