Beispiel #1
0
def test_variable_short():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/answer',
            "42\n",
            )
    result = util.clitest(
        args=[
            'show',
            'd239',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970

Oncolator segfaults on some inputs

--
answer=42
""")
Beispiel #2
0
def test_global_help():
    result = util.clitest(
        args=[
            '--help',
            ],
        )
    result.check_stdout(USAGE)
Beispiel #3
0
def test_description_whitespace():
    # not really sure how you could end up without a description, but
    # let's not totally fail
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            '\n',
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/number',
            '3431\n',
            )
    result = util.clitest(
        args=[
            'show',
            'd239',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970
number #3431

--
""")
Beispiel #4
0
def test_minimal_with_number():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/number',
            '3431\n',
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
    result = util.clitest(
        args=[
            'show',
            '#3431',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970
number #3431

Oncolator segfaults on some inputs

--
""")
Beispiel #5
0
def test_lookup_name():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/name/oncolator-segfault',
            '',
            )
    result = util.clitest(
        args=[
            'show',
            'oncolator-segfault',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970
name oncolator-segfault

Oncolator segfaults on some inputs

--
""")
Beispiel #6
0
def test_no_match():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/number',
            '3431\n',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/description',
            'I am not a xyzzy bug\n',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/quux',
            '',
            )
    result = util.clitest(
        args=[
            'list',
            '--tag=xyzzy',
            ],
        cwd=tmp,
        )
    result.check_stdout('')
Beispiel #7
0
def test_no_tags():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/description',
            """\
Oncolator segfaults on some inputs

The Oncolator service segfaults if I go to the web page,
login, choose quick oncolation from the radio buttons and
click the "Onc!" button.

I need to demo this to the Board of Directors on Monday, need a
fix quick! It crashed on me today around 9:20 am, you should be
able to find it in the server logs.
""",
            )
    result = util.clitest(
        args=[
            'list',
            ],
        cwd=tmp,
        )
    # with no number or name, default to 7-digit prefix of ticket,
    # similar to git rev-parse --short
    result.check_stdout("""\
f3da69c\tOncolator segfaults on some inputs
""")
Beispiel #8
0
def test_ambiguous():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Foo
""",
            )
        t.set(
            'd23959133fdca3611368d192bf6de4157a54d7a5/description',
            """\
Bar
""",
            )
    result = util.clitest(
        args=[
            'show',
            'd239'
            ],
        cwd=tmp,
        exit_status=1,
        allow_stderr=True,
        )
    result.check_stdout('')
    result.check_stderr("""\
bugit: Matches more than one ticket: d239
""")
Beispiel #9
0
def test_editor_noop():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    orig_head = storage.git_rev_parse(rev="bugit/HEAD", repo=tmp)

    class FakeTTYFileDescription(object):
        def isatty(self):
            return True

    FAKE_EDITOR = os.path.join(os.path.dirname(__file__), "editor-that-does-nothing")

    result = util.clitest(
        args=["new"], environ=dict(BUGIT_EDITOR=FAKE_EDITOR), stdin=FakeTTYFileDescription(), allow_stderr=True, cwd=tmp
    )
    result.check_stdout("")
    result.check_stderr(
        re.compile(
            r"""
^
bugit\ new:\ creating\ ticket\ ([0-9a-f]{40})\ \.\.\.\n
bugit\ new:\ file\ was\ not\ changed,\ discarding\n
$
""",
            re.VERBOSE,
        )
    )
    new_head = storage.git_rev_parse(rev="bugit/HEAD", repo=tmp)
    eq(orig_head, new_head)
Beispiel #10
0
def test_ticket_not_first_arg():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5/description',
            'old',
            )
    result = util.clitest(
        args=[
            'edit',
            '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5',
            ],
        stdin="""\
tags foo
ticket 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5

Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""",
        cwd=tmp,
        allow_stderr=True,
        exit_status=1,
        )
    result.check_stdout('')
    result.check_stderr("""\
bugit edit: updating ticket 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5 ...
bugit edit: ticket header not on first line
""")
    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(
            path='',
            repo=tmp,
            children=True,
            ):
            yield basename
    got = list(list_tickets())
    eq(got, ['29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5'])
    got = sorted(storage.ls(
            path='29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5',
            repo=tmp,
            ))
    eq(
        got,
        sorted([
                'description',
                #TODO 'tags/reporter:TODO'
                ]),
        )
    got = storage.get(
        path=os.path.join(
            '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5',
            'description',
            ),
        repo=tmp,
        )
    eq(got, 'old')
Beispiel #11
0
def test_unknown_ticket_arg():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=[
            'edit',
            '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5',
            ],
        stdin="""\
nop

Frobbing is borked
""",
        cwd=tmp,
        allow_stderr=True,
        exit_status=1,
        )
    result.check_stdout('')
    result.check_stderr("""\
bugit edit: Ticket not found: 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5
""")
    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(
            path='',
            repo=tmp,
            children=True,
            ):
            yield basename
    got = list(list_tickets())
    eq(got, [])
Beispiel #12
0
def test_simple_stdin_ticketAsArg():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5/description',
            'old',
            )
    TICKET = '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5'
    result = util.clitest(
        args=[
            'edit',
            TICKET,
            ],
        stdin="""\
nop

Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""",
        cwd=tmp,
        allow_stderr=True,
        )
    result.check_stdout('')
    result.check_stderr("""\
bugit edit: updating ticket %s ...
bugit edit: saved
""" % TICKET)
    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(
            path='',
            repo=tmp,
            children=True,
            ):
            yield basename
    got = list(list_tickets())
    eq(got, [TICKET])
    got = sorted(storage.ls(
            path=TICKET,
            repo=tmp,
            ))
    eq(
        got,
        sorted([
                'description',
                #TODO 'tags/reporter:TODO'
                ]),
        )
    got = storage.get(
        path=os.path.join(TICKET, 'description'),
        repo=tmp,
        )
    eq(got, """\
Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""")
Beispiel #13
0
def test_header():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=["new"],
        stdin="""\
tags qwark

Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""",
        cwd=tmp,
        allow_stderr=True,
    )
    result.check_stdout("")
    m = result.check_stderr(
        re.compile(
            r"""
^
bugit\ new:\ creating\ ticket\ ([0-9a-f]{40})\ \.\.\.\n
bugit\ new:\ saved\n
$
""",
            re.VERBOSE,
        )
    )
    ticket = m.group(1)

    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(path="", repo=tmp, children=True):
            yield basename

    got = list(list_tickets())
    eq(got, [ticket])
    got = sorted(storage.ls(path=ticket, repo=tmp))
    eq(
        got,
        sorted(
            [
                "description",
                # TODO 'tags/reporter:TODO'
                "tags/qwark",
            ]
        ),
    )
    got = storage.get(path=os.path.join(ticket, "description"), repo=tmp)
    eq(
        got,
        """\
Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""",
    )
    got = storage.get(path=os.path.join(ticket, "tags/qwark"), repo=tmp)
    eq(got, "")
Beispiel #14
0
def test_help():
    result = util.clitest(args=["new", "--help"])
    result.check_stdout(
        """\
Usage: bugit new [REV..] [--] [VARIABLE=VALUE..]

Options:
  -h, --help  show this help message and exit
"""
    )
Beispiel #15
0
def test_repeat():
    tmp = util.maketemp()
    storage.git_init(tmp)
    result = util.clitest(
        args=[
            'init',
            ],
        cwd=tmp,
        )
    result.check_stdout('')
    util.check_bugit_repository(repo=tmp)
    result = util.clitest(
        args=[
            'init',
            ],
        cwd=tmp,
        )
    result.check_stdout('')
    util.check_bugit_repository(repo=tmp)
Beispiel #16
0
def test_editor_simple():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)

    class FakeTTYFileDescription(object):
        def isatty(self):
            return True

    FAKE_EDITOR = os.path.join(os.path.dirname(__file__), "editor-append")

    result = util.clitest(
        args=["new"], environ=dict(BUGIT_EDITOR=FAKE_EDITOR), stdin=FakeTTYFileDescription(), allow_stderr=True, cwd=tmp
    )
    result.check_stdout("")
    m = result.check_stderr(
        re.compile(
            r"""
^
bugit\ new:\ creating\ ticket\ ([0-9a-f]{40})\ \.\.\.\n
bugit\ new:\ saved\n
$
""",
            re.VERBOSE,
        )
    )
    ticket = m.group(1)

    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(path="", repo=tmp, children=True):
            yield basename

    got = list(list_tickets())
    eq(got, [ticket])
    got = sorted(storage.ls(path=ticket, repo=tmp))
    eq(
        got,
        sorted(
            [
                "description",
                # TODO 'tags/reporter:TODO'
            ]
        ),
    )
    got = storage.get(path=os.path.join(ticket, "description"), repo=tmp)
    eq(
        got,
        """\
Enter description here, with a short first paragraph.

Separate variables from main description with "--".
Kilroy was here
""",
    )
Beispiel #17
0
def test_empty():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=[
            'list',
            ],
        cwd=tmp,
        )
    result.check_stdout('')
Beispiel #18
0
def test_tag_wrap():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/number',
            '3431\n',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/description',
            """\
Oncolator segfaults on some inputs

The Oncolator service segfaults if I go to the web page,
login, choose quick oncolation from the radio buttons and
click the "Onc!" button.

I need to demo this to the Board of Directors on Monday, need a
fix quick! It crashed on me today around 9:20 am, you should be
able to find it in the server logs.
""",
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/priority:high',
            '',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/denial-of-service',
            '',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/security',
            '',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/lots-of-long-tickets',
            '',
            )
        t.set(
            'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/tags/blah-blah-blah',
            '',
            )
    result = util.clitest(
        args=[
            'list',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
#3431\tOncolator segfaults on some inputs
  priority:high blah-blah-blah denial-of-service lots-of-long-tickets
  security
""")
Beispiel #19
0
def test_help():
    result = util.clitest(
        args=[
            'init',
            '--help',
            ],
        )
    result.check_stdout("""\
Usage: bugit init

Options:
  -h, --help  show this help message and exit
""")
Beispiel #20
0
def test_bad_command():
    result = util.clitest(
        args=[
            'xyzzy',
            ],
        allow_stderr=True,
        exit_status=2,
        )
    result.check_stdout('')
    result.check_stderr("""\
Usage: bugit COMMAND [ARGS]

bugit: error: Unknown command: xyzzy
""")
Beispiel #21
0
def test_bad_too_many_args():
    result = util.clitest(
        args=[
            'init',
            'foo',
            ],
        exit_status=2,
        allow_stderr=True,
        )
    result.check_stdout('')
    result.check_stderr("""\
Usage: bugit init

bugit: error: too many arguments
""")
Beispiel #22
0
def test_help():
    result = util.clitest(
        args=[
            'edit',
            '--help',
            ],
        )
    result.check_stdout("""\
Usage: bugit edit [TICKET]

Options:
  -h, --help  show this help message and exit
  --replace   replace ticket fully with input
  --update    update ticket based on input, preserving anything not included
""")
Beispiel #23
0
def test_not_found_number():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=[
            'show',
            '#11'
            ],
        cwd=tmp,
        exit_status=1,
        allow_stderr=True,
        )
    result.check_stdout('')
    result.check_stderr("""\
bugit: Ticket not found: #11
""")
Beispiel #24
0
def test_variable_long():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/ashortone',
            # just short enough not to wrap
            ((70 - len('something=')) * 'x') + '\n',
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/longerone',
            # just one too long
            ((71 - len('longerone=')) * 'x') + '\n',
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/toolong',
            50*'foo ',
            )
    result = util.clitest(
        args=[
            'show',
            'd239',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970

Oncolator segfaults on some inputs

--
ashortone=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
longerone=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
toolong=foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
\tfoo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
\tfoo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
\tfoo
""")
Beispiel #25
0
def test_help():
    result = util.clitest(
        args=[
            'list',
            '--help',
            ],
        )
    result.check_stdout("""\
Usage: bugit list [OPTS] [--] [SEARCH..]

Options:
  -h, --help     show this help message and exit
  -v, --verbose  show more information
  --tag=TAG      only list tickets having this tag
  --order=ORDER  sort listing according to criteria
  --hide=FIELD   hide field from listing
  --show=FIELD   show field in listing
""")
Beispiel #26
0
def test_bad_no_default_ticket():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=[
            'show',
            ],
        cwd=tmp,
        exit_status=2,
        allow_stderr=True,
        )
    result.check_stdout('')
    result.check_stderr("""\
Usage: bugit show [OPTS] [TICKET]

bugit: error: no default ticket set
""")
Beispiel #27
0
def test_help():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=[
            'show',
            '--help',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
Usage: bugit show [OPTS] [TICKET]

Options:
  -h, --help       show this help message and exit
  -v, --verbose    show more information
  --format=FORMAT  show output in this format
""")
Beispiel #28
0
def test_variable_multiline():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/multiline',
            """\
I consist of
multiple lines
and my formatting
is precious and
dear to author
"""
            )
    result = util.clitest(
        args=[
            'show',
            'd239',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970

Oncolator segfaults on some inputs

--
multiline=
\tI consist of
\tmultiple lines
\tand my formatting
\tis precious and
\tdear to author
""")
Beispiel #29
0
def test_header_bad_ticket():
    # can't include ticket sha for "bugit new"
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    result = util.clitest(
        args=["new"],
        stdin="""\
ticket 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5
tags qwark

Frobbing is borked

I ran frob and it was supposed to blarb, but it qwarked.
""",
        cwd=tmp,
        allow_stderr=True,
        exit_status=1,
    )
    result.check_stdout("")
    m = result.check_stderr(
        re.compile(
            r"""
^
bugit\ new:\ creating\ ticket\ ([0-9a-f]{40})\ \.\.\.\n
bugit\ new:\ cannot\ include\ ticket\ identity\ when\ creating\ ticket\n
$
""",
            re.VERBOSE,
        )
    )
    ticket = m.group(1)

    def list_tickets():
        # TODO share me
        for (mode, type_, object, basename) in storage.git_ls_tree(path="", repo=tmp, children=True):
            yield basename

    got = list(list_tickets())
    eq(got, [])
Beispiel #30
0
def test_multiple():
    tmp = util.maketemp()
    storage.git_init(tmp)
    storage.init(tmp)
    with storage.Transaction(repo=tmp) as t:
        t.set(
            'd239371f3b6b61ca1076bb460e331b3edb412970/description',
            """\
Oncolator segfaults on some inputs
""",
            )
        t.set(
            'b6de831319bcac7de17dbd85432792daae5925dc/description',
            """\
Frob is kabork.
""",
            )
    result = util.clitest(
        args=[
            'show',
            'd239',
            'b6de831319bca',
            ],
        cwd=tmp,
        )
    result.check_stdout("""\
ticket d239371f3b6b61ca1076bb460e331b3edb412970

Oncolator segfaults on some inputs

--
---
ticket b6de831319bcac7de17dbd85432792daae5925dc

Frob is kabork.

--
""")