Commits

Alexander Dudko  committed 5722ce8

h4-h5 link error fixed, switched to pytest

  • Participants
  • Parent commits 33ed910
  • Tags 0.1.6

Comments (0)

Files changed (6)

File jirabulkloader/task_extractor.py

 
 class TaskExtractor:
 
-    def __init__(self, jira_url, username, password, options, dry_run = False):
-        self.h5_tasks_to_link_to_h4_task = [] # will be used to link h5-tasks to the root task
+    def __init__(self, jira_url, username, password, options = {}, dry_run = False):
         self.tmpl_vars = {} # template variables dict
         self.tmpl_json = {} # template json structures, for example {"project": {"key": "KEY"}}
         self.rt_vars = {} # run-time variables (issueIDs)
                         h5_summary_list = self._h5_task_completion(h5_task_key, h5_task_caption, h5_task_desc, h5_task_ext)
                         summary = '\n'.join([summary, h5_summary_list]) if summary else h5_summary_list
                         h5_task_ext = ''
-                    h5_task_key, h5_task_caption, h5_task_desc = self._create_h5_task_and_return_key_caption_description(line)
+                    h4_link = h4_task_key if 'h4_task_key' in vars() else None
+                    h5_task_key, h5_task_caption, h5_task_desc = self._create_h5_task_and_return_key_caption_description(line, h4_link)
                 elif line['markup'][0] == '#':
                     if 'h5_task_key' in vars():
                         sub_task_caption = self._create_sub_task_and_return_caption(line, h5_task_key)
         sub_task_key = self.create_issue(sub_task_json)
         return self._make_task_caption(sub_task_json,  sub_task_key)
 
-    def _create_h5_task_and_return_key_caption_description(self, h5_task_json):
+    def _create_h5_task_and_return_key_caption_description(self, h5_task_json, h4_link):
         h5_task_json['issuetype'] = 'Task'
         h5_task_key = self.create_issue(h5_task_json)
-        self.h5_tasks_to_link_to_h4_task.append(h5_task_key)
+        if h4_link is not None: self.create_link(h4_link, h5_task_key)
         h5_task_caption = self._make_task_caption(h5_task_json,  h5_task_key)
         h5_task_desc = h5_task_json['description'] if 'description' in h5_task_json else None
         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'] = 'User 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)
         return (h4_task_key, self._make_task_caption(h4_task_json,  h4_task_key))
 
 # end of create_tasks() helpers

File jirabulkloader/test/conftest.py

+
+import pytest
+
+
+@pytest.fixture
+def te():
+    """TaskExtractor instance"""
+    from jirabulkloader.task_extractor import TaskExtractor
+    return TaskExtractor("http://jira.atlassian.com", "", "", dry_run = True)    
+
+
+@pytest.fixture(scope='session')
+def dry_run_key():
+    """return the string 'DRY-RUN-XXXX'"""
+    return 'DRY-RUN-XXXX'
+
+
+@pytest.fixture(scope='session')
+def std_te_input():
+    """Standard input test for TaskExtractor.load testing"""
+    import textwrap
+    return textwrap.dedent( """
+    h4. h4 task *assignee*
+    =h4 task description
+    # h4 sub-task *assignee*
+    =h4 sub-task desc
+    h5. h5.1 task *assignee*
+    =h5.1 task desc
+    # h5.1 sub-task *assignee*
+    =h5.1 sub-task desc
+    h5. h5.2 task *assignee*
+    =h5.2 task desc
+    # h5.2 sub-task *assignee*
+    =h5.2 sub-task desc line1
+    =h5.2 sub-task desc line2
+    """ )
+
+
+@pytest.fixture
+def std_te_tasks():
+    """Standard set of tasks for TaskExtractor.create_tasks testing"""
+    return [
+            {'assignee': 'assignee', 'markup': 'h4.', 'description': 'h4 task description', 'summary': 'h4 task', 'line_number': 2}, \
+            {'assignee': 'assignee', 'markup': '#', 'summary': 'h4 sub-task', 'line_number': 4, 'description': 'h4 sub-task desc'}, \
+            {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5.1 task', 'line_number': 6, 'description': 'h5.1 task desc'}, \
+            {'assignee': 'assignee', 'markup': '#', 'description': 'h5.1 sub-task desc', 'summary': 'h5.1 sub-task', 'line_number': 8}, \
+            {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5.2 task', 'line_number': 10, 'description': 'h5.2 task desc'}, \
+            {'assignee': 'assignee', 'markup': '#', 'description': 'h5.2 sub-task desc line1\nh5.2 sub-task desc line2', \
+            'summary': 'h5.2 sub-task', 'line_number': 12}, \
+            ]
+

File jirabulkloader/test/test_task_extractor.py

 ##########################################################
 ### load
 
-  def test_load_Using_simple_text(self):
-    input_text = """
-h4. h4 task *assignee*
-=h4 task description
-# sub-task1 *assignee*
-h5. h5 task *assignee*
-# sub-task2 *assignee*
-=line1 description
-=line2 description
-"""
-    excpected_result = [{'assignee': 'assignee', 'markup': 'h4.', \
-        'description': 'h4 task description', 'summary': 'h4 task', 'line_number': 2}, \
-        {'assignee': 'assignee', 'markup': '#', 'summary': 'sub-task1', 'line_number': 4}, \
-        {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 5}, \
-        {'assignee': 'assignee', 'markup': '#', \
-        'description': 'line1 description\nline2 description', 'summary': 'sub-task2', 'line_number': 6}]
-    self.assertEquals(excpected_result, self.te.load(input_text))
-
   def test_load_Text_h4_and_h5_with_empty_line(self):
     input_text = "\n\nh4. h4 task *assignee*\n\nh5. h5 task *assignee*"
     excpected_result = [{'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task', 'line_number': 3}, \

File jirabulkloader/test/test_te_link.py

+
+import pytest
+
+def test_links_between_h4_and_h5_tasks( te, std_te_tasks, dry_run_key ):
+    from mock import MagicMock, call
+    te.create_link = MagicMock()
+    te.create_tasks( std_te_tasks )
+    assert te.create_link.call_args_list == [call(dry_run_key, dry_run_key), call(dry_run_key, dry_run_key)]
+

File jirabulkloader/test/test_te_load.py

+
+import pytest
+
+def test_load( te, std_te_input, std_te_tasks ):
+    assert te.load(std_te_input) == std_te_tasks
+
+
 
 setup(
     name='jira-bulk-loader',
-    version='0.1.5',
+    version='0.1.6',
     packages=['jirabulkloader','jirabulkloader.test',],
     author='Alexander Dudko',
     author_email='alex.dudko@gmail.com',
         "simplejson >= 3.3.0",
         "requests >= 1.2.3",
         "argparse >= 1.2.1",
+        "pytest >= 2.3.5",
     ],
     classifiers=[
         'Development Status :: 5 - Production/Stable',