diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
commit | bad1f2370ba311bbe5981b204d4fa244b1d9a514 (patch) | |
tree | 9cb5d38aad2eb177d04a59e51a6c54aef07f69ab | |
parent | ce644b02862726e0d75a98d60703227de75012a7 (diff) |
import-orig: Handle download errors properly
This introduces tests that reach out to the network. These are disabled
by default.
-rw-r--r-- | HACKING | 5 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | gbp/scripts/common/import_orig.py | 3 | ||||
-rw-r--r-- | tests/24_test_gbp_import_orig.py | 23 | ||||
-rw-r--r-- | tests/testutils/debiangittestrepo.py | 4 |
5 files changed, 36 insertions, 2 deletions
@@ -12,6 +12,11 @@ via: This will fetch the necessary binary data for the DEB and RPM component tests, and the tests are from now on included within each regular test run. +Some tests reach out to the network. To run these in addition to all +other tests use: + + make all+net + Building the API Docs --------------------- @@ -1,5 +1,8 @@ all: syntax-check test +all+net: + $(MAKE) GBP_NETWORK_TESTS=1 all + test: export GIT_AUTHOR_NAME="Gbp Tests"; \ export GIT_AUTHOR_EMAIL=tests@example.com; \ diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index eaa38b77..66144e5b 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -167,7 +167,8 @@ def download_orig(url): try: with contextlib.closing(requests.get(url, verify=True, stream=True)) as r: - with contextlib.closing(open(target, 'w', CHUNK_SIZE)) as target_fd: + r.raise_for_status() + with open(target, 'w', CHUNK_SIZE) as target_fd: for d in r.iter_content(CHUNK_SIZE): target_fd.write(d) except Exception as e: diff --git a/tests/24_test_gbp_import_orig.py b/tests/24_test_gbp_import_orig.py index 93b656b0..4ec58478 100644 --- a/tests/24_test_gbp_import_orig.py +++ b/tests/24_test_gbp_import_orig.py @@ -1,7 +1,11 @@ # vim: set fileencoding=utf-8 : """Test L{gbp.command_wrappers.Command}'s tarball unpack""" +import os +import unittest + from gbp.scripts.import_orig import (ImportOrigDebianGitRepository, GbpError) +from gbp.scripts.common.import_orig import download_orig from . testutils import DebianGitTestRepo @@ -29,3 +33,22 @@ class TestImportOrigGitRepository(DebianGitTestRepo): def test_rrr_unknown_action(self): with self.assertRaisesRegexp(GbpError, "Unknown action unknown for tag doesnotmatter"): self.repo.rrr('doesnotmatter', 'unknown', 'tag') + + +@unittest.skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled") +class TestImportOrigDownload(DebianGitTestRepo): + HOST = 'git.sigxcpu.org' + + def setUp(self): + DebianGitTestRepo.setUp(self, ImportOrigDebianGitRepository) + os.chdir(self.repodir) + + def test_404_download(self): + with self.assertRaisesRegexp(GbpError, "404 Client Error: Not Found for url"): + download_orig("https://{host}/does_not_exist".format(host=self.HOST)) + + def test_200_download(self): + pkg = 'hello-debhelper_2.6.orig.tar.gz' + url = "https://{host}/cgit/gbp/deb-testdata/tree/dsc-3.0/{pkg}".format(host=self.HOST, + pkg=pkg) + self.assertEqual(download_orig(url).path, '../%s' % pkg) diff --git a/tests/testutils/debiangittestrepo.py b/tests/testutils/debiangittestrepo.py index 9a9ee07d..c52c5f17 100644 --- a/tests/testutils/debiangittestrepo.py +++ b/tests/testutils/debiangittestrepo.py @@ -12,12 +12,14 @@ class DebianGitTestRepo(unittest.TestCase): """Scratch repo for a single unit test""" def setUp(self, repo_cls=None): + name = 'test_repo' self.tmpdir = context.new_tmpdir(__name__) if repo_cls is None: repo_cls = gbp.deb.git.DebianGitRepository - repodir = self.tmpdir.join('test_repo') + repodir = self.tmpdir.join(name) + self.repodir = os.path.join(str(self.tmpdir), name) self.repo = repo_cls.create(repodir) def tearDown(self): |