def test_load_Check_JSON_inline(tf): tf.write('{"item1":{"name":"test"}}\n' 'h5. h5 task *assignee* {"item2": {"name": "test2"}}') assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 2, 'issuetype': 'Task', 'tmpl_ext': {'item1': {'name': 'test'}, 'item2': {'name': 'test2'}}}] == load(tf)
def test_load_redefine_issue_type(tf): tf.write('\n!define h4. Epic\n!define h5. Bug\n\n' 'h4. epic *user1*\nh5. bug *user2*') assert [{'markup': 'h4.', 'summary': 'epic', 'issuetype': 'Epic', 'assignee': 'user1', 'line_number': 5}, {'markup': 'h5.', 'summary': 'bug', 'issuetype': 'Bug', 'assignee': 'user2', 'line_number': 6}] == load(tf)
def test_json_var_must_be_replaced(tf): tf.write('{"item1":{"name":"test"}}' '\n{"item1":{"name":"newtest"}}' '\nh5. h5 task *assignee*') assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 3, 'issuetype': 'Task', 'tmpl_ext': {'item1': {'name': 'newtest'}}}] == load(tf)
def test_recognize_template_variables(tf): tf.write('[VAR1=1]\n[VAR2=2016]\n' 'h5. h5 task$VAR1 *assignee* %$VAR2-04-01%' '\n=line$VAR1 description') assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task1', 'line_number': 3, 'description': 'line1 description', 'duedate': '2016-04-01', 'issuetype': 'Task'}] == load(tf)
def test_load_Check_dueDate_and_JSON_in_one_line(tf): tf.write('h5. h5 task1 *assignee* %2017-04-01% {"item2":"test2"}\n' 'h5. h5 task2 *assignee*') assert load(tf) == \ [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task1', 'duedate': '2017-04-01', 'tmpl_ext': {"item2": "test2"}, 'issuetype': 'Task', 'line_number': 1}, {'assignee': 'assignee', 'markup': 'h5.', 'issuetype': 'Task', 'summary': 'h5 task2', 'line_number': 2}]
def test_load_existing_h4_task(tf): tf.write(".. JIRA-1234\n# test subtask *assignee*\nh5. h5 task *assignee*") assert load(tf) == \ [{'markup': '..', 'issue_key': 'JIRA-1234', 'line_number': 1}, {'assignee': 'assignee', 'line_number': 2, 'markup': '#', 'summary': 'test subtask', 'issuetype': 'Sub-task'}, {'assignee': 'assignee', 'line_number': 3, 'markup': 'h5.', 'summary': 'h5 task', 'issuetype': 'Task'}]
def test_h5_and_sub_task_with_empty_line(tf): tf.write("h5. h5 task *assignee*\n\n" "#* Sub-task 1 *assignee*\n\n" "#* Sub-task 2 *assignee*") assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 1, 'issuetype': 'Task'}, {'text': ''}, {'assignee': 'assignee', 'markup': '#*', 'summary': 'Sub-task 1', 'line_number': 3, 'issuetype': 'Sub-task'}, {'text': ''}, {'assignee': 'assignee', 'markup': '#*', 'summary': 'Sub-task 2', 'line_number': 5, 'issuetype': 'Sub-task'}] == load(tf)
def test_load_Check_JSON_inline_replacement(tf): tf.write('{"item1":{"name":"test"}}\n{"item2":"test2"}\n' 'h5. h5 task *assignee* {"item1":"test1"}\n' '#* Sub-task 1 *assignee*') assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 3, 'issuetype': 'Task', 'tmpl_ext': {'item1': 'test1', 'item2': 'test2'}}, {'assignee': 'assignee', 'markup': '#*', 'summary': 'Sub-task 1', 'line_number': 4, 'issuetype': 'Sub-task', 'tmpl_ext': {'item1': {'name': 'test'}, 'item2': 'test2'}}] == load(tf)
def test_variable_with_a_similar_name2(tf): tf.write("[VAR_VAR= task]\n[VAR=h5.]\n$VAR $VAR_VAR$VAR_VAR *assignee*") assert [{'assignee': 'assignee', 'markup': 'h5.', 'line_number': 3, 'summary': 'task task', 'issuetype': 'Task'}] == load(tf)
def test_text_replacement(tf): tf.write("[VAR1=h5.]\n[VAR2= h5 task]\n$VAR1$VAR2 *assignee*") assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 3, 'issuetype': 'Task'}] == load(tf)
def test_dueDate(tf): tf.write("h5. h5 task *assignee* %2017-04-01%\n=line1 description") assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 1, 'description': 'line1 description', 'duedate': '2017-04-01', 'issuetype': 'Task'}] == load(tf)
def test_h4_and_h5_with_empty_lines(tf): tf.write("\n\nh4. h4 task *assignee*\n\nh5. h5 task *assignee*") assert [{'assignee': 'assignee', 'markup': 'h4.', 'summary': 'h4 task', 'line_number': 3, 'issuetype': 'User Story'}, {'text': ''}, {'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 5, 'issuetype': 'Task'}] == load(tf)
def test_recognize_runtime_variables(tf): tf.write("\nh5. h5 task *assignee* [TASK_KEY]" "\n=line1 description") assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 2, 'description': 'line1 description', 'rt_ext': 'TASK_KEY', 'issuetype': 'Task'}] == load(tf)
def test_invalid_json(tf): tf.write('{fail test}') with pytest.raises(JBLDecodeError): load(tf)
def test_recognize_template_json(tf): tf.write('{"item1":{"name":"test"}}\nh5. h5 task *assignee*') assert [{'assignee': 'assignee', 'markup': 'h5.', 'summary': 'h5 task', 'line_number': 2, 'issuetype': 'Task', 'tmpl_ext': {'item1': {'name': 'test'}}}] == load(tf)