review/tests/test_delete.py @ 66463ec963b6

Merged in abegey/hg-review/issue-93 (pull request #10)

[index] Add the owner of the cset in a td beetween id and description
author Christophe de Vienne <cdevienne@gmail.com>
date Fri, 21 Nov 2014 19:01:07 +0100
parents bef3dce04be6
children (none)
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
from util import get_identifiers

from .. import messages

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_delete_invalid():
    should_fail_with(messages.REQUIRES_IDS, delete=True)
    should_fail_with(messages.UNKNOWN_ID % 'a', delete=True, args=['a'])

    review(comment=True, message='test')

    should_fail_with(messages.UNKNOWN_ID % 'z', delete=True, args=['z'])

    # Use the pidgeonhole princicple to create ambiguous identifiers.
    for i in range(17):
        review(comment=True, message='test%d' % i)

    ids = get_identifiers()
    id_map = {}
    for i in ids:
        id_map[i[0]] = id_map.get(i[0], 0) + 1
    i = str(filter(lambda k: id_map[k] > 1, id_map.keys())[0])

    should_fail_with(messages.AMBIGUOUS_ID % i, delete=True, args=[i])

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_delete_comment():
    def t(rev):
        review(rev=rev, comment=True, message='test')
        i = get_identifiers(rev)[0]

        output = review(delete=True, args=[i])
        assert not output
        output = review(rev=rev, verbose=True)
        assert '(%s)\n' % i not in output

        review(rev=rev, comment=True, message='test2')
        review(rev=rev, comment=True, message='test3')
        i1, i2 = get_identifiers(rev)

        output = review(delete=True, args=[i1])
        assert not output
        output = review(rev=rev, verbose=True)
        assert '(%s)\n' % i1 not in output
        assert '(%s)\n' % i2 in output

        review(rev=rev, comment=True, message='test4')
        i1, i2 = get_identifiers(rev)

        output = review(delete=True, args=[i1, i2])
        assert not output
        output = review(rev=rev, verbose=True)
        assert '(%s)\n' % i1 not in output
        assert '(%s)\n' % i2 not in output
    t('.')
    t('0')

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_delete_signoff():
    # TODO: test multiple signoff deletions
    review(signoff=True, message='test')
    i = get_identifiers()[0]

    output = review(delete=True, args=[i])
    assert not output
    output = review(verbose=True)
    assert '(%s)\n' % i not in output

    review(comment=True, message='test2')
    review(signoff=True, message='test3')
    i1, i2 = get_identifiers()

    output = review(delete=True, args=[i2])
    assert not output
    output = review(verbose=True)
    assert '(%s)\n' % i1 in output
    assert '(%s)\n' % i2 not in output

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_delete_both():
    def t(rev):
        review(rev=rev, signoff=True, message='test')
        review(rev=rev, comment=True, message='test')
        ids = get_identifiers(rev)

        output = review(rev=rev, delete=True, args=ids)
        assert not output
        output = review(rev=rev, verbose=True)
        assert '(%s)\n' % ids[0] not in output
        assert '(%s)\n' % ids[1] not in output

        review(rev=rev, signoff=True, message='test2')
        review(rev=rev, comment=True, message='test3')
        review(rev=rev, comment=True, message='test4')
        ids = get_identifiers(rev)

        output = review(rev=rev, delete=True, args=ids[:2])
        assert not output
        output = review(rev=rev, verbose=True)
        assert '(%s)\n' % ids[0] not in output
        assert '(%s)\n' % ids[1] not in output
        assert '(%s)\n' % ids[2] in output
    t('.')
    t('0')