From 951da45fe3e52fd0b4ce9a1aa99aa5bd9389d55e Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Apr 16 2019 09:58:32 +0000 Subject: [PATCH 1/2] Unit tests download_file with errors status code --- diff --git a/tests/test_cli/test_download_file.py b/tests/test_cli/test_download_file.py index 4abdf71..3f96d10 100644 --- a/tests/test_cli/test_download_file.py +++ b/tests/test_cli/test_download_file.py @@ -3,6 +3,9 @@ import mock import six import shutil import tempfile +import os +import requests_mock +import requests try: import unittest2 as unittest except ImportError: @@ -153,5 +156,31 @@ class TestDownloadProgress(unittest.TestCase): self.assertMultiLineEqual(actual, expected) +class TestDownloadFileError(unittest.TestCase): + """Check error status code and text in download_file.""" + filename = '/tmp/tmp-download' + + @requests_mock.Mocker() + def test_handle_download_file_error_404(self, m): + m.get("http://url", text='Not Found\n', status_code=404) + with self.assertRaises(requests.HTTPError): + download_file("http://url", self.filename) + try: + self.assertFalse(os.path.exists(self.filename)) + except AssertionError: + os.unlink(self.filename) + raise + + @requests_mock.Mocker() + def test_handle_download_file_error_500(self, m): + m.get("http://url", text='Internal Server Error\n', status_code=500) + with self.assertRaises(requests.HTTPError): + download_file("http://url", self.filename) + try: + self.assertFalse(os.path.exists(self.filename)) + except AssertionError: + os.unlink(self.filename) + raise + if __name__ == '__main__': unittest.main() From 4ed5b2ef7a64829b29355731bcb705f79b2be5a8 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Apr 16 2019 09:59:49 +0000 Subject: [PATCH 2/2] update jenkins setup Some libraries dropped py2.6 support, so put there version limits for pip in CI. Update documentation for requests-mock. --- diff --git a/docs/source/writing_koji_code.rst b/docs/source/writing_koji_code.rst index 1106145..c21737e 100644 --- a/docs/source/writing_koji_code.rst +++ b/docs/source/writing_koji_code.rst @@ -676,6 +676,7 @@ You will need to install the following packages to actually run the tests. * ``python-mock`` * ``python-psycopg2`` * ``python-requests`` + * ``python-requests-mock`` * ``python-qpid-proton`` Please note that it is currently not supported to use *virtualenv* when hacking