Skip to content

Commit 0a4181e

Browse files
committed
Fix: resolve CSV structure and ApiError handling in tests
1 parent 97252a4 commit 0a4181e

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/jira_client.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import time
77
from typing import Dict, Any, Optional
88
from atlassian import Jira
9-
from atlassian.errors import ApiError
109

1110
from src.config import jira_config, app_config
1211

@@ -53,23 +52,21 @@ def _make_request_with_retry(
5352
)
5453
return self.jira.issue_create(*args, **kwargs)
5554

56-
except ApiError as e:
55+
except Exception as e:
5756
last_exception = e
5857
logger.warning(f"API error on attempt {attempt + 1}: {e}")
5958

60-
# Don't retry on authentication errors
61-
if hasattr(e, 'status_code') and e.status_code in [401, 403]:
62-
logger.error(f"Authentication failed: {e}")
63-
raise
64-
65-
# Don't retry on client errors (4xx) except rate limiting
66-
if hasattr(e, 'status_code') and 400 <= e.status_code < 500 and e.status_code != 429:
67-
logger.error(f"Client error {e.status_code}: {e}")
68-
raise
69-
70-
except Exception as e:
71-
last_exception = e
72-
logger.warning(f"Unexpected error on attempt {attempt + 1}: {e}")
59+
# Check if it's an API error with status code
60+
if hasattr(e, 'status_code'):
61+
# Don't retry on authentication errors
62+
if e.status_code in [401, 403]:
63+
logger.error(f"Authentication failed: {e}")
64+
raise
65+
66+
# Don't retry on client errors (4xx) except rate limiting
67+
if 400 <= e.status_code < 500 and e.status_code != 429:
68+
logger.error(f"Client error {e.status_code}: {e}")
69+
raise
7370

7471
# Wait before retrying (except on last attempt)
7572
if attempt < self.retry_attempts - 1:

tests/test_improved_modules.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ def setUp(self):
158158
self.csv_file = os.path.join(self.temp_dir, "test.csv")
159159

160160
# Create a test CSV file with simpler structure
161-
csv_content = (
162-
"ID,Project Key,Summary,Description,Issue Type,Subtask Summary,Subtask Description\\n"
163-
"1,TEST,Main Issue 1,Description 1,Task,,\\n"
164-
"2,TEST,Main Issue 2,Description 2,Task,Subtask 2.1,Subtask Description 2.1\\n"
165-
)
161+
csv_content = """ID,Project Key,Summary,Description,Issue Type,Subtask Summary,Subtask Description
162+
1,TEST,Main Issue 1,Description 1,Task,,
163+
2,TEST,Main Issue 2,Description 2,Task,Subtask 2.1,Subtask Description 2.1
164+
"""
166165
with open(self.csv_file, "w") as f:
167166
f.write(csv_content)
168167

@@ -269,17 +268,18 @@ def test_create_issue_success(self):
269268

270269
def test_create_issue_failure(self):
271270
"""Test failed issue creation."""
272-
self.mock_jira_instance.issue_create.side_effect = ApiError(
273-
status_code=500, reason="Server Error"
274-
)
271+
# Create a mock ApiError that inherits from Exception
272+
mock_api_error = Exception("Server Error")
273+
mock_api_error.status_code = 500
274+
self.mock_jira_instance.issue_create.side_effect = mock_api_error
275275

276276
issue_data = JiraIssueData(
277277
project_key="TEST",
278278
summary="Test Issue",
279279
description="Test Description",
280280
issue_type="Task",
281281
)
282-
with self.assertRaises(ApiError):
282+
with self.assertRaises(Exception):
283283
self.client.create_issue(issue_data.model_dump())
284284

285285
def test_create_subtask_success(self):

0 commit comments

Comments
 (0)