# Path: rebasehelper/constants.py
# ENCODING: str = locale.getpreferredencoding()
# 
# Path: rebasehelper/helpers/download_helper.py
# class DownloadHelper:
#         class FTPAdapter(requests.adapters.BaseAdapter):
#     def progress(download_total, downloaded, start_time, show_size=True):
#         def format_time(t):
#         def format_size(s):
#     def request(url, **kwargs):
#             def send(self, request, stream=False, timeout=None, verify=True,  # pylint: disable=unused-argument
#                      cert=None, proxies=None):  # pylint: disable=unused-argument
#             def close(self):
#     def download_file(url, destination_path, blocksize=8192):


import io
import os
import pytest  # type: ignore
from rebasehelper.constants import ENCODING
from rebasehelper.helpers.download_helper import DownloadHelper, DownloadError
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors: Petr Hráček <phracek@redhat.com>
#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>





class TestDownloadHelper:
    """ DownloadHelper tests """

    def test_keyboard_interrupt_situation(self, monkeypatch):
        """
        Test that the local file is deleted in case KeyboardInterrupt is raised during the download
        """
        KNOWN_URL = 'https://ftp.isc.org/isc/bind9/9.10.4-P1/srcid'
        LOCAL_FILE = os.path.basename(KNOWN_URL)

        def interrupter():
            raise KeyboardInterrupt

        # make sure that some function call inside tha actual download section raises the KeyboardInterrupt exception.
        monkeypatch.setattr('time.time', interrupter)

        with pytest.raises(KeyboardInterrupt):

# Path: rebasehelper/constants.py
# ENCODING: str = locale.getpreferredencoding()
# 
# Path: rebasehelper/helpers/download_helper.py
# class DownloadHelper:
#         class FTPAdapter(requests.adapters.BaseAdapter):
#     def progress(download_total, downloaded, start_time, show_size=True):
#         def format_time(t):
#         def format_size(s):
#     def request(url, **kwargs):
#             def send(self, request, stream=False, timeout=None, verify=True,  # pylint: disable=unused-argument
#                      cert=None, proxies=None):  # pylint: disable=unused-argument
#             def close(self):
#     def download_file(url, destination_path, blocksize=8192):


# Path: rebasehelper/tests/helpers/test_download_helper.py
import io
import os
import pytest  # type: ignore
from rebasehelper.constants import ENCODING
from rebasehelper.helpers.download_helper import DownloadHelper, DownloadError

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors: Petr Hráček <phracek@redhat.com>
#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>





class TestDownloadHelper:
    """ DownloadHelper tests """

    def test_keyboard_interrupt_situation(self, monkeypatch):
        """
        Test that the local file is deleted in case KeyboardInterrupt is raised during the download
        """
        KNOWN_URL = 'https://ftp.isc.org/isc/bind9/9.10.4-P1/srcid'
        LOCAL_FILE = os.path.basename(KNOWN_URL)

        def interrupter():
            raise KeyboardInterrupt

        # make sure that some function call inside tha actual download section raises the KeyboardInterrupt exception.
        monkeypatch.setattr('time.time', interrupter)

        with pytest.raises(KeyboardInterrupt):

            DownloadHelper.download_file(KNOWN_URL, LOCAL_FILE)