コード例 #1
0
    def test_download_authorized(self, bottle_server):
        # Not authorized
        dest = os.path.join(temp_folder(), "manual.html")
        conanfile = ConanFileMock()
        conanfile._conan_requester = requests
        with pytest.raises(AuthenticationException):
            download(conanfile,
                     "http://localhost:%s/basic-auth/user/passwd" %
                     bottle_server.port,
                     dest,
                     retry=0,
                     retry_wait=0)

        # Authorized
        download(conanfile,
                 "http://localhost:%s/basic-auth/user/passwd" %
                 bottle_server.port,
                 dest,
                 auth=("user", "passwd"),
                 retry=0,
                 retry_wait=0)

        # Authorized using headers
        download(conanfile,
                 "http://localhost:%s/basic-auth/user/passwd" %
                 bottle_server.port,
                 dest,
                 headers={"Authorization": "Basic dXNlcjpwYXNzd2Q="},
                 retry=0,
                 retry_wait=0)
コード例 #2
0
 def test_get_filename_error(self, bottle_server_zip):
     # Test: File name cannot be deduced from '?file=1'
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     with pytest.raises(ConanException) as error:
         get(conanfile,
             "http://localhost:%s/?file=1" % bottle_server_zip.port)
     assert "Cannot deduce file name from the url" in str(error.value)
コード例 #3
0
 def test_get_gunzip(self, bottle_server_zip):
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     tmp_folder = temp_folder()
     with chdir(tmp_folder):
         get(conanfile,
             "http://localhost:%s/test.txt.gz" % bottle_server_zip.port,
             retry=0,
             retry_wait=0)
         assert load("test.txt") == "hello world zipped!"
コード例 #4
0
 def test_get_tgz(self, bottle_server_zip):
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     tmp_folder = temp_folder()
     with chdir(tmp_folder):
         get(conanfile,
             "http://localhost:%s/sample.tgz" % bottle_server_zip.port,
             retry=0,
             retry_wait=0)
         assert load("test_folder/myfile.txt") == "myfile contents!"
コード例 #5
0
 def test_download_forbidden(self, bottle_server):
     dest = os.path.join(temp_folder(), "manual.html")
     # Not authorized
     with pytest.raises(AuthenticationException) as exc:
         conanfile = ConanFileMock()
         conanfile._conan_requester = requests
         download(conanfile,
                  "http://localhost:%s/forbidden" % bottle_server.port,
                  dest)
     assert "403: Forbidden" in str(exc.value)
コード例 #6
0
 def test_download_no_retries_errors(self, bottle_server):
     # Not found error will not retry
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     file_path = os.path.join(temp_folder(), "file.txt")
     with pytest.raises(ConanException):
         download(conanfile,
                  "http://localhost:%s/notexisting" % bottle_server.port,
                  file_path,
                  retry=2,
                  retry_wait=0)
     assert "Waiting" not in str(conanfile.output)
     assert "retry" not in str(conanfile.output)
コード例 #7
0
 def test_download_retries_500_errors(self, bottle_server):
     # 500 internal also retries
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     file_path = os.path.join(temp_folder(), "file.txt")
     with pytest.raises(ConanException):
         download(conanfile,
                  "http://localhost:%s/error_url" % bottle_server.port,
                  file_path,
                  retry=1,
                  retry_wait=0)
     assert str(
         conanfile.output).count("Waiting 0 seconds to retry...") == 1
コード例 #8
0
 def test_download_retries_errors(self):
     # unreachable server will retry
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     file_path = os.path.join(temp_folder(), "file.txt")
     with pytest.raises(ConanException):
         download(conanfile,
                  "http://fakeurl3.es/nonexists",
                  file_path,
                  retry=2,
                  retry_wait=1)
     assert str(
         conanfile.output).count("Waiting 1 seconds to retry...") == 2
コード例 #9
0
 def test_download_iterate_url(self, bottle_server):
     dest = os.path.join(temp_folder(), "manual.html")
     conanfile = ConanFileMock()
     conanfile._conan_requester = requests
     download(conanfile, [
         "invalid",
         "http://localhost:%s/manual.html" % bottle_server.port
     ],
              dest,
              retry=3,
              retry_wait=0)
     content = load(dest)
     assert content == "this is some content"
     assert "Trying another mirror." in str(conanfile.output)
コード例 #10
0
    def test_download(self, bottle_server):
        dest = os.path.join(temp_folder(), "manual.html")
        conanfile = ConanFileMock()
        conanfile._conan_requester = requests
        download(conanfile,
                 "http://localhost:%s/manual.html" % bottle_server.port,
                 dest,
                 retry=3,
                 retry_wait=0)
        content = load(dest)
        assert content == "this is some content"

        # Can re-download
        download(conanfile,
                 "http://localhost:%s/manual.html" % bottle_server.port,
                 dest,
                 retry=3,
                 retry_wait=0)