diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/component/rpm/test_import_orig_rpm.py | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/tests/component/rpm/test_import_orig_rpm.py b/tests/component/rpm/test_import_orig_rpm.py index e53d00c2..dd672620 100644 --- a/tests/component/rpm/test_import_orig_rpm.py +++ b/tests/component/rpm/test_import_orig_rpm.py @@ -39,6 +39,18 @@ from tests.component.rpm import RPM_TEST_DATA_DIR DATA_DIR = os.path.join(RPM_TEST_DATA_DIR, 'orig') +DUMMY_SPEC = """ +Name: dummy +Version: 1.0 +Release: 0 +License: GPL-2.0 +Summary: Dummy package +Source: %(source)s + +%%description +Dummy package generated by unit tests +""" + def mock_import(args, stdin_data="\n\n", cwd=None): """Wrapper for import-orig-rpm for feeding mock stdin data to it""" old_cwd = os.path.abspath(os.path.curdir) @@ -111,6 +123,13 @@ class TestImportOrig(ImportOrigTestBase): repo.commit_all('First commit') return repo + @staticmethod + def _create_dummy_spec(path, **kwargs): + """Create a dummy spec file""" + with open(path, 'w') as fobj: + print kwargs + fobj.write(DUMMY_SPEC % kwargs) + def test_invalid_args(self): """ See that import-orig-rpm fails gracefully when called with invalid args @@ -118,10 +137,6 @@ class TestImportOrig(ImportOrigTestBase): repo = GitRepository.create('.') origs = [os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2'), os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')] - # Test empty args - eq_(mock_import([]), 1) - self._clear_log() - # Test multiple archives eq_(mock_import([] + origs), 1) self._check_log(0, 'gbp:error: More than one archive specified') @@ -383,6 +398,30 @@ class TestImportOrig(ImportOrigTestBase): # Other parts of the import should've succeeded self._check_repo_state(repo, 'master', ['master', 'upstream']) + def test_archive_from_spec(self): + """Test taking archive file path from spec file""" + repo = GitRepository.create('.') + orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2') + + # Test non-existent spec file + eq_(mock_import([]), 1) + self._check_log(0, '.*No archive to import specified and no spec file') + + # Test non-existent archive + self._create_dummy_spec('dummy.spec', source='non-existent.tar.gz') + eq_(mock_import([]), 1) + self._check_log(-1, '.*unable to find \S+non-existent.tar.gz') + + # Test failing download + self._create_dummy_spec('dummy.spec', source='foo://bar.tar.gz') + eq_(mock_import([]), 1) + self._check_log(-1, '.*Download failed') + + # Test existing archive + self._create_dummy_spec('dummy.spec', source=orig) + eq_(mock_import([]), 0) + self._check_repo_state(repo, None, ['upstream'], ['dummy.spec']) + class TestPristineTar(ImportOrigTestBase): """ |