Files
git-upstream/tests/test_drop.py
Davide Guerri 24df2f38af Add drop and supersede commands
* supersede command allows the marking of commits as superceded by a
  set of upstream changes
* drop command allows the marking of commits that should be dropped

Both commands add git notes to a given sha1 in the upstream-merge
namespace (refs/notes/upstream-merge).
The notes are read by the import-upstream command during import and
the appropriate actions are then taken.

Add functional and unit tests for the two newly created commands.

JIRA: CICD-248
Change-Id: I6f69dd890af18e77a9affdb958afde1ec8b1cab8
2014-02-17 15:03:49 +00:00

68 lines
2.3 KiB
Python

#
# Copyright (c) 2012, 2013 Hewlett-Packard Development Company, L.P.
#
# Confidential computer software. Valid license from HP required for
# possession, use or copying. Consistent with FAR 12.211 and 12.212,
# Commercial Computer Software, Computer Software Documentation, and
# Technical Data for Commercial Items are licensed to the U.S. Government
# under vendor's standard commercial license.
#
"""Tests the drop module"""
import testtools
from ghp.commands import drop as d
from git import repo as r
from git import GitCommandError
class TestDrop(testtools.TestCase):
"""Test case for Drop class"""
first_commit = "bd6b9eefe961abe8c15cb5dc6905b92e14714a4e"
second_commit = "05fac847a5629e36050dcd69b9a782b2645d3cc7"
invalid_commit = "this_is_an_invalid_commit"
author="Walter White <heisenberg@hp.com>"
note_ref = 'refs/notes/upstream-merge'
def test_valid_parameters(self):
"""Test drop initialization and read properties"""
repo=r.Repo('.')
automatic_author='%s <%s>' % (repo.git.config('user.name'),
repo.git.config('user.email'))
t = d.Drop(git_object=TestDrop.first_commit)
self.assertEquals(t.author, automatic_author)
t = d.Drop(git_object=TestDrop.first_commit, author=TestDrop.author)
self.assertEquals(t.author, TestDrop.author)
def test_invalid_commit(self):
"""Test drop initialization with invalid commit"""
self.assertRaises(d.DropError, d.Drop,
git_object=TestDrop.invalid_commit)
def test_mark(self):
"""Test drop mark"""
t = d.Drop(git_object=TestDrop.first_commit, author=TestDrop.author)
repo = r.Repo('.')
try:
# Older git versions don't support --ignore-missing so we need to
# catch GitCommandError exception
repo.git.notes('--ref', TestDrop.note_ref, 'remove',
TestDrop.first_commit)
except GitCommandError:
pass
t.mark()
self.assertRegexpMatches(
'^Dropped: %s' % TestDrop.author,
repo.git.notes('--ref', TestDrop.note_ref, 'show',
TestDrop.first_commit)
)
repo.git.notes('--ref', TestDrop.note_ref, 'remove',
TestDrop.first_commit)