| |
@@ -6,6 +6,7 @@
|
| |
import os.path
|
| |
import pytest
|
| |
from dingus import Dingus
|
| |
+ import mock
|
| |
|
| |
from libtaskotron import file_utils
|
| |
from libtaskotron.directives import distgit_directive
|
| |
@@ -137,3 +138,45 @@
|
| |
assert len(download_calls) == 1
|
| |
# self.ref_nvr was not touched, so if nvr parsing gets priority, the URL will not match
|
| |
assert download_calls[0][1][0] == self._get_url(self.ref_path[0])
|
| |
+
|
| |
+ def test_raises_on_404(self, monkeypatch):
|
| |
+ '''Directive must raise when file is missing in distgit (404)'''
|
| |
+ mock_download = mock.Mock(side_effect=exc.TaskotronRemoteError('', errno=404))
|
| |
+ monkeypatch.setattr(file_utils, 'download', mock_download)
|
| |
+
|
| |
+ with pytest.raises(exc.TaskotronRemoteError):
|
| |
+ self.helper.process(self.ref_input, None)
|
| |
+
|
| |
+ def test_ignore_404(self, monkeypatch):
|
| |
+ '''Directive ignores missing files (404) when ignore_missing is set to True'''
|
| |
+ mock_download = mock.Mock(side_effect=exc.TaskotronRemoteError('', errno=404))
|
| |
+ monkeypatch.setattr(file_utils, 'download', mock_download)
|
| |
+
|
| |
+ self.ref_input['ignore_missing'] = True
|
| |
+
|
| |
+ self.helper.process(self.ref_input, None)
|
| |
+
|
| |
+ mock_download.assert_called_once()
|
| |
+
|
| |
+ def test_raises_on_non_404_with_ignore(self, monkeypatch):
|
| |
+ '''Directive must raise if ignore_missing is set to True but error is not 404'''
|
| |
+ mock_download = mock.Mock(side_effect=exc.TaskotronRemoteError('', errno=503))
|
| |
+ monkeypatch.setattr(file_utils, 'download', mock_download)
|
| |
+
|
| |
+ self.ref_input['ignore_missing'] = True
|
| |
+
|
| |
+ with pytest.raises(exc.TaskotronRemoteError):
|
| |
+ self.helper.process(self.ref_input, None)
|
| |
+
|
| |
+ def test_ignore_404_on_some_files(self, monkeypatch):
|
| |
+ '''Directive returns list of downloaded files, missing files are ignored'''
|
| |
+ side_effects = [None, exc.TaskotronRemoteError('', errno=404)]
|
| |
+ mock_download = mock.Mock(side_effect=side_effects)
|
| |
+ monkeypatch.setattr(file_utils, 'download', mock_download)
|
| |
+
|
| |
+ self.ref_input['ignore_missing'] = True
|
| |
+ self.ref_input['path'] = ['foo.spec', 'foo.spek']
|
| |
+
|
| |
+ downloaded = self.helper.process(self.ref_input, None)
|
| |
+
|
| |
+ assert len(downloaded) == 1
|
| |
For #384
If param
ignore_missing
is set toTrue
and the requested files are missing in distgit (error code 404), no error is raised.