Exemple #1
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)
Exemple #2
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)
Exemple #3
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
Exemple #4
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
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)