File: fetch_files_test.py

package info (click to toggle)
kiwi-boxed-plugin 0.2.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,016 kB
  • sloc: python: 1,996; makefile: 235; sh: 182
file content (40 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import io
from mock import (
    Mock, MagicMock, patch
)

from kiwi_boxed_plugin.utils.fetch_files import FetchFiles


class TestFetchFiles:
    def setup(self):
        self.fetcher = FetchFiles()

    def setup_method(self, cls):
        self.setup()

    @patch('kiwi_boxed_plugin.utils.fetch_files.requests')
    @patch('kiwi_boxed_plugin.utils.fetch_files.progressbar')
    def test_wget(self, mock_progressbar, mock_requests):
        response = Mock()
        response.headers.get.return_value = 4
        response.iter_content.return_value = [b'data']
        mock_requests.request.return_value = response
        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value
            self.fetcher.wget('http://foo', 'bar')
            mock_open.assert_called_once_with(
                'bar', 'wb'
            )
            file_handle.write.assert_called_once_with(b'data')
            mock_progressbar.ProgressBar.assert_called_once_with(
                maxval=4,
                widgets=[
                    'Loading: ',
                    mock_progressbar.Percentage.return_value, ' ',
                    mock_progressbar.Bar(marker='#', left='[', right=']'), ' ',
                    mock_progressbar.ETA.return_value, ' ',
                    mock_progressbar.FileTransferSpeed.return_value
                ]
            )