Beispiel #1
0
def new():
    '''Create a new ticket.

    $EDITOR will be opened and used to edit the case. The case
    template has an "header" in .yaml format. "Title", "Project",
    "Area", "Files", etc. are all available fields.
    The body of the ticket is separated by "---".

    Example:
    >>> new
    '''

    tmpl = Template('''Title: <title>
Project: <project>
# Area: <area>
# Assign to: {{ user.fullname }}
# Priority: Need to fix
# Parent: <id>
# Milestone: Infrastructure and Internal Errors
# Tags: <list>

---

<Insert description here>

''')  # noqa

    header = tmpl.generate(user=CURRENT_USER).decode('utf-8')
    with editor.writing(header=header) as text:
        editor.abort_if_empty(text)
        params = text.get_params_for_new()
        FBCase.new(**params)
Beispiel #2
0
def reply(*args):
    '''Reply to comment.

    Call $EDITOR to write the comment and add the past comment, quoted.

    Example:
    >>> reply  # reply to latest
    >>> reply 1234  # reply to specific comment
    '''
    assert_current()

    if not args:
        event = CURRENT_CASE.events[-1]
    else:
        event_id = args[0]
        all_events = {
            e.id: e for e in CURRENT_CASE.events
        }
        event = all_events[int(event_id)]

    assert event.comment, 'Empty event'
    header = '\n'.join(
        '> {}'.format(line)
        for line in event.comment.splitlines()
    ) + '\n\n'
    with editor.writing(header) as text:
        editor.abort_if_empty(text)
        params = text.get_params_for_comment()
        CURRENT_CASE.edit(**params)
Beispiel #3
0
def comment():
    '''Add a comment to the current ticket.

    Call $EDITOR to write the comment.

    Example:
    >>> comment
    '''
    assert_current()
    with editor.writing() as text:
        editor.abort_if_empty(text)
        params = text.get_params_for_comment()
        CURRENT_CASE.edit(**params)
Beispiel #4
0
    def test_write_new(self):
        editor.clear()
        expected = '''
# Lines starting wth "#" will be ignored.
# Leave this file empty to abort action.
# It's possible to add metadata in the format of a header.
# Use "---" as separator between the header and the body.
# E.g. To upload files use:
#    Files:
#      - path_to_file_1
#      - path_to_file_2
'''

        with editor.writing():
            with open(editor.FNAME, 'r') as fid:
                body = fid.read()
            self.assertEqual(body, expected)
Beispiel #5
0
    def test_write_new(self):
        editor.clear()
        expected = '''
# Lines starting wth "#" will be ignored.
# Leave this file empty to abort action.
# It's possible to add metadata in the format of a header.
# Use "---" as separator between the header and the body.
# E.g. To upload files use:
#    Files:
#      - path_to_file_1
#      - path_to_file_2
'''

        with editor.writing():
            with open(editor.FNAME, 'r') as fid:
                body = fid.read()
            self.assertEqual(body, expected)