Alexander Dudko avatar Alexander Dudko committed b0a415a

new exception for incorrect Jira host

Comments (0)

Files changed (4)

bin/jira-bulk-loader.py

 
 import argparse
 from jirabulkloader.task_extractor import TaskExtractor
-from jirabulkloader.task_extractor_exceptions import TaskExtractorTemplateErrorProject, TaskExtractorJiraValidationError, TaskExtractorTemplateErrorJson, TaskExtractorJiraCreationError
+from jirabulkloader.task_extractor_exceptions import TaskExtractorTemplateErrorProject, TaskExtractorJiraValidationError, TaskExtractorTemplateErrorJson, TaskExtractorJiraCreationError, TaskExtractorJiraHostProblem
 from requests.exceptions import ConnectionError
 
 prg_description="""Uses template file to create many tasks in Jira at once.
 
     print "Creating tasks.."
     breakdown = task_ext.create_tasks(tasks)
-except TaskExtractorTemplateErrorProject, e:
-    print e.message
-    exit(1)
-except TaskExtractorJiraValidationError, e:
-    print e.message
-    exit(1)
-except TaskExtractorJiraCreationError, e:
+
+except (TaskExtractorTemplateErrorProject, TaskExtractorJiraValidationError, TaskExtractorJiraCreationError, TaskExtractorJiraHostProblem) as e:
     print e.message
     exit(1)
 except TaskExtractorTemplateErrorJson, e:

jirabulkloader/task_extractor.py

 import base64
 from urllib2 import Request, urlopen, URLError
 import simplejson as json
-from task_extractor_exceptions import TaskExtractorTemplateErrorProject, TaskExtractorTemplateErrorJson, TaskExtractorJiraValidationError, TaskExtractorJiraCreationError
+from task_extractor_exceptions import TaskExtractorTemplateErrorProject, TaskExtractorTemplateErrorJson, TaskExtractorJiraValidationError, TaskExtractorJiraCreationError, TaskExtractorJiraHostProblem
 
 
 class TaskExtractor:
 
         full_url = "%s/rest/api/2/user/assignable/search?username=%s&project=%s" % (self.jira_url, user, project)
         try:
-            result = json.load(self._jira_request(full_url, None, 'GET'))
+           result = json.load(self._jira_request(full_url, None, 'GET'))
         except URLError, e:
             if hasattr(e, 'code'):
                 if e.code == 403 or e.code == 401:
                 else:
                     error_message = "The username '%s' and the project '%s' can not be validated.\nJira response: Error %s, %s" % (user, project, e.code, e.read())
                     raise TaskExtractorJiraValidationError(error_message)
+            elif hasattr(e, 'reason'):
+                error_message = "%s: %s" % (e.reason, self.jira_url)
+                raise TaskExtractorJiraHostProblem(error_message)
         if len(result) == 0: # the project is okay but username is missing n Jira
             error_message = "ERROR: the username '%s' specified in template can not be validated." % user
             raise TaskExtractorJiraValidationError(error_message)
         return (h5_task_key, h5_task_caption, h5_task_desc)
 
     def _create_h4_task_and_return_key_caption(self, h4_task_json):
-        h4_task_json['issuetype'] = 'Task'
+        h4_task_json['issuetype'] = 'Epic Story'
         h4_task_key = self.create_issue(h4_task_json)
         for key in self.h5_tasks_to_link_to_h4_task:
             self.create_link(h4_task_key, key)

jirabulkloader/task_extractor_exceptions.py

     def __init__(self, arg):
         self.error_element = arg
 
+class TaskExtractorJiraHostProblem(Exception):
+    def __init__(self, arg):
+        self.message = arg
+
 

jirabulkloader/test/test_task_extractor.py

   def test_create_tasks_Single_h4_task(self):
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}]
-    expected_result = {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}
+    input_list = [{'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}]
+    expected_result = {'issuetype': 'Epic Story', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}
     expected_output = 'h4. h4 task (DRY-RUN-XXXX)'
     self.assertEquals(self.te.create_tasks(input_list), expected_output)
     self.te.create_issue.assert_called_once_with(expected_result)
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
     self.te.update_issue_desc = MagicMock()
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'description': 'h5 task description', 'summary': 'h5 task'}]
+    input_list = [{'assignee': 'assignee', 'markup': 'h5.', 'description': 'h5 task description', 'summary': 'h5 task'}]
     expected_result = {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'description': 'h5 task description', 'summary': 'h5 task'}
     expected_output = 'h5. h5 task (DRY-RUN-XXXX)\nh5 task description'
     self.assertEquals(self.te.create_tasks(input_list), expected_output)
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
     self.te.update_issue_desc = MagicMock()
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}, \
-      {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'description': 'h5 task description'}, \
-      {'issuetype': 'Sub-task', 'assignee': 'assignee', 'markup': '#', 'description': 'line1 description\nline2 description', 'summary': 'sub-task'}]
+    input_list = [{'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'}, \
+      {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'description': 'h5 task description'}, \
+      {'assignee': 'assignee', 'markup': '#', 'description': 'line1 description\nline2 description', 'summary': 'sub-task'}]
     expected_result = [call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'description': 'h5 task description', 'summary': 'h5 task'}),
         call({'description': 'line1 description\nline2 description', 'parent': 'DRY-RUN-XXXX', 'markup': '#', 'summary': 'sub-task', 'assignee': 'assignee', \
             'issuetype': 'Sub-task'}),
-        call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'})]
+        call({'issuetype': 'Epic Story', 'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task'})]
     self.te.create_tasks(input_list)
     self.assertEquals(self.te.create_issue.call_args_list, expected_result)
     MagicMock.assert_called_once_with(self.te.update_issue_desc, 'DRY-RUN-XXXX', 'h5 task description\n# sub-task (DRY-RUN-XXXX)')
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
     self.te.update_issue_desc = MagicMock()
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'}, \
-      {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task'}, \
-      {'issuetype': 'Sub-task', 'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task'}]
+    input_list = [{'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'}, \
+      {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task'}, \
+      {'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task'}]
     expected_result = [call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task'}),
         call({'parent': 'DRY-RUN-XXXX', 'markup': '#', 'summary': 'sub-task', 'assignee': 'assignee', 'issuetype': 'Sub-task'}),
-        call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'})]
+        call({'issuetype': 'Epic Story', 'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'})]
     expected_output = 'h4. h4 task (DRY-RUN-XXXX)\nh5. h5 task (DRY-RUN-XXXX)\n# sub-task (DRY-RUN-XXXX)'
     self.assertEquals(self.te.create_tasks(input_list), expected_output)
     self.assertEquals(self.te.create_issue.call_args_list, expected_result)
   def test_create_tasks_Tasks_with_text(self):
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'}, \
-        {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'description':'h5 desc'}, {'text':'text line'}, \
-        {'issuetype': 'Sub-task', 'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task'}]
+    input_list = [{'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task'}, \
+        {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'description':'h5 desc'}, {'text':'text line'}, \
+        {'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task'}]
     expected_result = 'h4. h4 task (DRY-RUN-XXXX)\nh5. h5 task (DRY-RUN-XXXX)\nh5 desc\ntext line\n# sub-task (DRY-RUN-XXXX)'
     self.assertEquals(self.te.create_tasks(input_list), expected_result)
 
   def test_create_tasks_Tasks_with_no_h4_task(self):
     self.te.create_issue = MagicMock()
     self.te.create_issue.return_value = 'DRY-RUN-XXXX'
-    input_list = [{'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 1'}, \
-        {'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 2'}, \
-        {'issuetype': 'Sub-task', 'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task of h5 task 2'}]
+    input_list = [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 1'}, \
+        {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 2'}, \
+        {'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task of h5 task 2'}]
     expected_result = [call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 1'}), \
         call({'issuetype': 'Task', 'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task 2'}), \
         call({'parent': 'DRY-RUN-XXXX', 'markup': '#', 'summary': 'sub-task of h5 task 2', 'assignee': 'assignee', 'issuetype': 'Sub-task'})]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.