code: def test_HTMLFormAuthenticator_httpretty(d=None):
      fpath = opj(d, "crap.txt")
  
      credential = FakeCredential1(name="test", url=None)
      credentials = credential()
  
      def request_post_callback(request, uri, headers):
          post_params = request.parsed_body
          assert_equal(
              credentials["password"], post_params["password"][0]
          )
          assert_equal(credentials["user"], post_params["username"][0])
          assert_not_in("Cookie", request.headers)
          return (
              200,
              headers,
              "Got {} response from {}".format(request.method, uri),
          )
  
      def request_get_callback(request, uri, headers):
          assert_equal(request.body, b"")
          assert_in("Cookie", request.headers)
          assert_equal(request.headers["Cookie"], test_cookie)
          return (200, headers, "correct body")
  
      # SCENARIO 1
      # callback to verify that correct credentials are provided
      # and then returns the cookie to test again for 'GET'ing
      httpretty.register_uri(
          httpretty.POST,
          url,
          body=request_post_callback,
          set_cookie=test_cookie,
      )
      # then in GET verify that correct cookie was provided and
      # that no credentials are there
      httpretty.register_uri(
          httpretty.GET, url, body=request_get_callback
      )
  
      # SCENARIO 2
      # outdated cookie provided to GET -- must return 403 (access denied)
      # then our code should POST credentials again and get a new cookies
      # which is then provided to GET
  
      # SCENARIO 3
      # outdated cookie
      # outdated credentials
      # it should ask for new credentials (FakeCredential1 already mocks for that)
      # and then SCENARIO1 must work again
  
      # SCENARIO 4
      # cookie and credentials expired, user provided new bad credential
  
      # Also we want to test how would it work if cookie is available (may be)
      # TODO: check with correct and incorrect credential
      authenticator = HTMLFormAuthenticator(
          dict(
              username="{user}",
              password="{password}",
              submit="CustomLogin",
          )
      )
      # TODO: with success_re etc
      # This is a "success test" which should be tested in various above scenarios
      downloader = HTTPDownloader(
          credential=credential, authenticator=authenticator
      )
      downloader.download(url, path=d)
  
      content = read_file(fpath)
      assert_equal(content, "correct body")
  
imports: import builtins
  import os
  import re
  import time
  from calendar import timegm
  from os.path import join
  from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import download_url, get_url_straight_filename
  from datalad.utils import ensure_unicode
  from ...support.exceptions import AccessFailedError
  from ..base import BaseDownloader, DownloadError, IncompleteDownloadError, NoneAuthenticator
  from ..credentials import LORIS_Token, Token, UserPassword
  from ..http import HTMLFormAuthenticator, HTTPBaseAuthenticator, HTTPBearerTokenAuthenticator, HTTPDownloader, process_www_authenticate
  from unittest.mock import patch
  from ...support.exceptions import AccessDeniedError, AnonymousAccessDeniedError
  from ...support.network import get_url_disposition_filename
  from ...support.status import FileStatus
  from ...tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_greater, assert_in, assert_not_in, assert_raises, known_failure_githubci_win, ok_file_has_content, serve_path_via_http, skip_if, skip_if_no_network, swallow_logs, swallow_outputs, use_cassette, with_fake_cookies_db, with_memory_keyring, with_tempfile, with_testsui, with_tree, without_http_proxy
  from ...utils import read_file
label_desc: Use image node_id 15 for calling a global function with example usage: test_HTMLFormAuthenticator_httpretty(d) and returns: int,  headers,  str, int,  headers,  str