Coverage for tests / test_get_request_type.py: 100%
57 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"""
2Tests for get_request_type.py script.
3"""
5import sys
6import json
7from pathlib import Path
8from unittest.mock import patch, MagicMock
10import pytest
12# Add scripts directory to path
13sys.path.insert(0, str(Path(__file__).parent.parent / 'scripts'))
16def test_get_request_type(mock_jira_client):
17 """Test fetching request type details."""
18 from get_request_type import get_request_type
20 mock_jira_client.get_request_type.return_value = {
21 "id": "25",
22 "name": "Get IT help",
23 "description": "Request help from IT",
24 "helpText": "Please provide details",
25 "issueTypeId": "10001",
26 "serviceDeskId": "1"
27 }
29 with patch('get_request_type.get_jira_client', return_value=mock_jira_client):
30 result = get_request_type("1", "25")
32 assert result is not None
33 assert result['id'] == "25"
34 assert result['name'] == "Get IT help"
37def test_request_type_details(mock_jira_client):
38 """Test that all detail fields are present."""
39 from get_request_type import get_request_type
41 mock_jira_client.get_request_type.return_value = {
42 "id": "25",
43 "name": "Get IT help",
44 "description": "Request help from IT",
45 "helpText": "Please provide details",
46 "issueTypeId": "10001",
47 "serviceDeskId": "1"
48 }
50 with patch('get_request_type.get_jira_client', return_value=mock_jira_client):
51 result = get_request_type("1", "25")
53 assert 'id' in result
54 assert 'name' in result
55 assert 'description' in result
56 assert 'issueTypeId' in result
59def test_format_text_output(mock_jira_client, capsys):
60 """Test human-readable output with full details."""
61 from get_request_type import format_request_type_text
63 request_type = {
64 "id": "25",
65 "name": "Get IT help",
66 "description": "Request help from IT",
67 "helpText": "Please provide details",
68 "issueTypeId": "10001",
69 "serviceDeskId": "1"
70 }
72 format_request_type_text(request_type)
74 captured = capsys.readouterr()
75 assert 'Request Type Details' in captured.out
76 assert 'Get IT help' in captured.out
77 assert 'Request help from IT' in captured.out
80def test_format_json_output(mock_jira_client):
81 """Test JSON output format."""
82 from get_request_type import format_request_type_json
84 request_type = {
85 "id": "25",
86 "name": "Get IT help",
87 "description": "Request help from IT"
88 }
90 json_output = format_request_type_json(request_type)
91 parsed = json.loads(json_output)
93 assert parsed['id'] == "25"
94 assert parsed['name'] == "Get IT help"
97def test_request_type_not_found(mock_jira_client):
98 """Test error when request type doesn't exist."""
99 from get_request_type import get_request_type
100 from error_handler import JiraError
102 mock_jira_client.get_request_type.side_effect = JiraError("Request type not found")
104 with patch('get_request_type.get_jira_client', return_value=mock_jira_client):
105 with pytest.raises(JiraError, match="Request type not found"):
106 get_request_type("1", "999")
109def test_show_help_text(mock_jira_client, capsys):
110 """Test showing request type help text for customers."""
111 from get_request_type import format_request_type_text
113 request_type = {
114 "id": "25",
115 "name": "Get IT help",
116 "description": "Request help from IT",
117 "helpText": "Please provide detailed information about your issue"
118 }
120 format_request_type_text(request_type)
122 captured = capsys.readouterr()
123 assert 'Help Text' in captured.out or 'Please provide detailed' in captured.out
126def test_show_icon_info(mock_jira_client, capsys):
127 """Test showing request type icon information."""
128 from get_request_type import format_request_type_text
130 request_type = {
131 "id": "25",
132 "name": "Get IT help",
133 "description": "Request help from IT",
134 "icon": {
135 "id": "10000",
136 "_links": {
137 "iconUrls": {
138 "48x48": "https://example.com/icon.png"
139 }
140 }
141 }
142 }
144 format_request_type_text(request_type)
146 captured = capsys.readouterr()
147 assert 'Icon' in captured.out or '10000' in captured.out