code: def test_datalad_credential_helper(path=None):
      ds = Dataset(path).create()
  
      # tell git to use git-credential-datalad
      ds.config.add("credential.helper", "datalad", scope="local")
      ds.config.add(
          "datalad.credentials.githelper.noninteractive",
          "true",
          scope="global",
      )
  
      from datalad.downloaders.providers import Providers
  
      url1 = "https://datalad-test.org/some"
      url2 = "https://datalad-test.org/other"
      provider_name = "datalad-test.org"
  
      # `Providers` code is old and only considers a dataset root based on PWD
      # for config lookup. contextmanager below can be removed once the
      # provider/credential system is redesigned.
      with chpwd(ds.path):
          gitcred = GitCredentialInterface(url=url1, repo=ds)
  
          # There's nothing set up yet, helper should return empty
          gitcred.fill()
          eq_(gitcred["username"], "")
          eq_(gitcred["password"], "")
  
          # store new credentials
          # Note, that `Providers.enter_new()` currently uses user-level config
          # files for storage only. TODO: make that an option!
          # To not mess with existing ones, fail if it already exists:
  
          cfg_file = (
              Path(Providers._get_providers_dirs()["user"])
              / f"{provider_name}.cfg"
          )
          assert_false(cfg_file.exists())
  
          # Make sure we clean up
          from datalad.tests import _TEMP_PATHS_GENERATED
  
          _TEMP_PATHS_GENERATED.append(str(cfg_file))
  
          # Give credentials to git and ask it to store them:
          gitcred = GitCredentialInterface(
              url=url1, username="dl-user", password="dl-pwd", repo=ds
          )
          gitcred.approve()
  
          assert_true(cfg_file.exists())
          providers = Providers.from_config_files()
          p1 = providers.get_provider(url=url1, only_nondefault=True)
          assert_is_instance(p1.credential, UserPassword)
          eq_(p1.credential.get("user"), "dl-user")
          eq_(p1.credential.get("password"), "dl-pwd")
  
          # default regex should be host only, so matching url2, too
          p2 = providers.get_provider(url=url2, only_nondefault=True)
          assert_is_instance(p1.credential, UserPassword)
          eq_(p1.credential.get("user"), "dl-user")
          eq_(p1.credential.get("password"), "dl-pwd")
  
          # git, too, should now find it for both URLs
          gitcred = GitCredentialInterface(url=url1, repo=ds)
          gitcred.fill()
          eq_(gitcred["username"], "dl-user")
          eq_(gitcred["password"], "dl-pwd")
  
          gitcred = GitCredentialInterface(url=url2, repo=ds)
          gitcred.fill()
          eq_(gitcred["username"], "dl-user")
          eq_(gitcred["password"], "dl-pwd")
  
          # Rejection must not currently lead to deleting anything, since we would
          # delete too broadly.
          gitcred.reject()
          assert_true(cfg_file.exists())
          gitcred = GitCredentialInterface(url=url1, repo=ds)
          gitcred.fill()
          eq_(gitcred["username"], "dl-user")
          eq_(gitcred["password"], "dl-pwd")
          dlcred = UserPassword(name=provider_name)
          eq_(dlcred.get("user"), "dl-user")
          eq_(dlcred.get("password"), "dl-pwd")
  
imports: from datalad.api import Dataset
  from datalad.downloaders.credentials import UserPassword
  from datalad.local.gitcredential import GitCredentialInterface
  from datalad.tests.utils_pytest import assert_false, assert_is_instance, assert_not_in, assert_true, eq_, with_tempfile
  from datalad.utils import Path, chpwd
label_desc: Use image node_id 2 for calling a global function with example usage: test_datalad_credential_helper(path) without return types