tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_utils.py (918B)


      1 #!/usr/bin/env python
      2 import os
      3 import shutil
      4 from unittest import mock
      5 
      6 import mozunit
      7 from mozproxy.utils import download_file_from_url
      8 from support import tempdir
      9 
     10 here = os.path.dirname(__file__)
     11 
     12 
     13 def urlretrieve(*args, **kw):
     14    def _urlretrieve(url, local_dest):
     15        # simply copy over our tarball
     16        shutil.copyfile(os.path.join(here, "archive.tar.gz"), local_dest)
     17        return local_dest, {}
     18 
     19    return _urlretrieve
     20 
     21 
     22 @mock.patch("mozproxy.utils.urlretrieve", new_callable=urlretrieve)
     23 def test_download_file(*args):
     24    with tempdir() as dest_dir:
     25        dest = os.path.join(dest_dir, "archive.tar.gz")
     26        download_file_from_url("http://example.com/archive.tar.gz", dest, extract=True)
     27        # archive.tar.gz contains hey.txt, if it worked we should see it
     28        assert os.path.exists(os.path.join(dest_dir, "hey.txt"))
     29 
     30 
     31 if __name__ == "__main__":
     32    mozunit.main(runwith="pytest")