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

1""" 

2Tests for get_request_type.py script. 

3""" 

4 

5import sys 

6import json 

7from pathlib import Path 

8from unittest.mock import patch, MagicMock 

9 

10import pytest 

11 

12# Add scripts directory to path 

13sys.path.insert(0, str(Path(__file__).parent.parent / 'scripts')) 

14 

15 

16def test_get_request_type(mock_jira_client): 

17 """Test fetching request type details.""" 

18 from get_request_type import get_request_type 

19 

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 } 

28 

29 with patch('get_request_type.get_jira_client', return_value=mock_jira_client): 

30 result = get_request_type("1", "25") 

31 

32 assert result is not None 

33 assert result['id'] == "25" 

34 assert result['name'] == "Get IT help" 

35 

36 

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 

40 

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 } 

49 

50 with patch('get_request_type.get_jira_client', return_value=mock_jira_client): 

51 result = get_request_type("1", "25") 

52 

53 assert 'id' in result 

54 assert 'name' in result 

55 assert 'description' in result 

56 assert 'issueTypeId' in result 

57 

58 

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 

62 

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 } 

71 

72 format_request_type_text(request_type) 

73 

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 

78 

79 

80def test_format_json_output(mock_jira_client): 

81 """Test JSON output format.""" 

82 from get_request_type import format_request_type_json 

83 

84 request_type = { 

85 "id": "25", 

86 "name": "Get IT help", 

87 "description": "Request help from IT" 

88 } 

89 

90 json_output = format_request_type_json(request_type) 

91 parsed = json.loads(json_output) 

92 

93 assert parsed['id'] == "25" 

94 assert parsed['name'] == "Get IT help" 

95 

96 

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 

101 

102 mock_jira_client.get_request_type.side_effect = JiraError("Request type not found") 

103 

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") 

107 

108 

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 

112 

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 } 

119 

120 format_request_type_text(request_type) 

121 

122 captured = capsys.readouterr() 

123 assert 'Help Text' in captured.out or 'Please provide detailed' in captured.out 

124 

125 

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 

129 

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 } 

143 

144 format_request_type_text(request_type) 

145 

146 captured = capsys.readouterr() 

147 assert 'Icon' in captured.out or '10000' in captured.out