aboutsummaryrefslogtreecommitdiff
path: root/tests/component/deb/test_import_orig.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/component/deb/test_import_orig.py')
-rw-r--r--tests/component/deb/test_import_orig.py91
1 files changed, 88 insertions, 3 deletions
diff --git a/tests/component/deb/test_import_orig.py b/tests/component/deb/test_import_orig.py
index 6ed5da8..f5698ea 100644
--- a/tests/component/deb/test_import_orig.py
+++ b/tests/component/deb/test_import_orig.py
@@ -18,17 +18,28 @@
import os
+from mock import patch, DEFAULT
+
from tests.component import ComponentTestBase
from tests.component.deb import DEB_TEST_DATA_DIR
+from gbp.scripts.import_dsc import main as import_dsc
from gbp.scripts.import_orig import main as import_orig
-from gbp.git.repository import GitRepository
+from gbp.git.repository import GitRepository, GitRepositoryError
from nose.tools import ok_
+def raise_if_tag_match(match):
+ def wrapped(*args, **kwargs):
+ if len(args) > 0 and args[0].startswith(match) or kwargs.get('name', '').startswith(match):
+ raise GitRepositoryError('this is a create tag error mock for %s %s' % (match, kwargs))
+ return DEFAULT
+ return wrapped
+
+
class TestImportOrig(ComponentTestBase):
- """Test importing of new upstream sources"""
+ """Test importing of new upstream versions"""
pkg = "hello-debhelper"
def_branches = ['master', 'upstream', 'pristine-tar']
@@ -38,6 +49,11 @@ class TestImportOrig(ComponentTestBase):
'dsc-3.0',
'%s_%s.orig.tar.gz' % (self.pkg, version))
+ def _dsc(self, version):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-3.0',
+ '%s_%s.dsc' % (self.pkg, version))
+
def test_initial_import(self):
"""Test that importing into an empty repo works"""
repo = GitRepository.create(self.pkg)
@@ -48,8 +64,20 @@ class TestImportOrig(ComponentTestBase):
self._check_repo_state(repo, 'master', self.def_branches,
tags=['upstream/2.6'])
+ def test_update(self):
+ repo = GitRepository.create(self.pkg)
+ os.chdir(self.pkg)
+
+ dsc = self._dsc('2.6-2')
+ ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'])
+
+ self._orig('2.8')
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
+ tags=['debian/2.6-2', 'upstream/2.6'])
+
def test_tag_exists(self):
- """Test that importing an already importet version fails"""
+ """Test that importing an already imported version fails"""
repo = GitRepository.create(self.pkg)
os.chdir(self.pkg)
orig = self._orig('2.6')
@@ -61,3 +89,60 @@ class TestImportOrig(ComponentTestBase):
self._check_log(0, "gbp:error: Upstream tag 'upstream/2.6' already exists")
# Check that the second import didn't change any refs
self.check_refs(repo, heads)
+
+ def test_update_fail_create_upstream_tag(self):
+ repo = GitRepository.create(self.pkg)
+ os.chdir(self.pkg)
+
+ dsc = self._dsc('2.6-2')
+ ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'])
+
+ heads = self.rem_refs(repo, self.def_branches)
+
+ orig = self._orig('2.8')
+ with patch('gbp.git.repository.GitRepository.create_tag',
+ side_effect=GitRepositoryError('this is a create tag error mock')):
+ ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 1)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
+ tags=['debian/2.6-2', 'upstream/2.6'])
+ self.check_refs(repo, heads)
+
+ def test_update_fail_merge(self):
+ repo = GitRepository.create(self.pkg)
+ os.chdir(self.pkg)
+
+ dsc = self._dsc('2.6-2')
+ ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'])
+
+ heads = self.rem_refs(repo, self.def_branches)
+
+ orig = self._orig('2.8')
+ with patch('gbp.scripts.import_orig.debian_branch_merge',
+ side_effect=GitRepositoryError('this is a fail merge error mock')):
+ ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 1)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
+ tags=['debian/2.6-2', 'upstream/2.6'])
+ self.check_refs(repo, heads)
+
+ @patch('gbp.git.repository.GitRepository.create_tag',
+ side_effect=raise_if_tag_match('upstream/'))
+ def test_initial_import_fail_create_upstream_tag(self, RepoMock):
+ repo = GitRepository.create(self.pkg)
+ os.chdir(self.pkg)
+ orig = self._orig('2.6')
+ ok_(import_orig(['arg0', '--no-interactive', orig]) == 1)
+
+ self._check_repo_state(repo, None, [], tags=[])
+
+ def test_initial_import_fail_create_debian_branch(self):
+ repo = GitRepository.create(self.pkg)
+ os.chdir(self.pkg)
+ orig = self._orig('2.6')
+
+ with patch('gbp.git.repository.GitRepository.create_branch',
+ side_effect=GitRepositoryError('this is a create branch error mock')):
+ ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 1)
+
+ self._check_repo_state(repo, None, [], tags=[])