Skip to content

Commit

Permalink
add mocked test_unite_get_tgz2
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbrislawn committed Nov 8, 2023
1 parent 8747b47 commit c674b00
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rescript/tests/test_get_unite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c674b00

Please sign in to comment.