From c674b0046c45635c247e21d31be655decb997f65 Mon Sep 17 00:00:00 2001 From: Colin Brislawn Date: Wed, 8 Nov 2023 16:57:07 -0500 Subject: [PATCH] add mocked test_unite_get_tgz2 --- rescript/tests/test_get_unite.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rescript/tests/test_get_unite.py b/rescript/tests/test_get_unite.py index 5f0c6d0..ad7e62f 100644 --- a/rescript/tests/test_get_unite.py +++ b/rescript/tests/test_get_unite.py @@ -20,8 +20,7 @@ ) from urllib.request import urlopen -from unittest.mock import patch -import os +from unittest.mock import patch, Mock class TestGetUNITE(TestPluginBase): @@ -56,6 +55,19 @@ def test_unite_get_tgz(self): with self.assertRaisesRegex(ValueError, "File incomplete on try"): _unite_get_tgz("https://files.plutof.ut.ee/nope", tmpdirname) + def test_unite_get_tgz2(self): + with tempfile.TemporaryDirectory() as tmpdirname: + # mock the response object + mock_response = Mock() + mock_response.iter_content.return_value = [b"mock"] + mock_response.headers.get.return_value = "4" # matches content + # mock successful download + with patch("requests.get", return_value=mock_response): + _unite_get_tgz("fakeURL", tmpdirname) + # real failed download + with self.assertRaisesRegex(ValueError, "File incomplete on try"): + _unite_get_tgz("https://files.plutof.ut.ee/nope", tmpdirname) + def test_unite_get_artifacts(self): # Test on small data/unitefile.tgz with two items inside res_one, res_two = _unite_get_artifacts(