Example #1
0
def test_GetDefaultGithubAccessToken_from_GITHUB_ACCESS_TOKEN(
  tempdir: pathlib.Path,
):
  with test.TemporaryEnv() as env:
    env["GITHUB_ACCESS_TOKEN"] = "1234"
    source, token = api.GetDefaultGithubAccessToken()

  assert source == "$GITHUB_ACCESS_TOKEN"
  assert token == "1234"
Example #2
0
def test_GetDefaultGithubAccessToken_from_extra_paths(tempdir: pathlib.Path):
  path = tempdir / "access_token_path.txt"
  fs.Write(path, "1234".encode("utf-8"))

  source, token = api.GetDefaultGithubAccessToken(
    extra_access_token_paths=[path]
  )

  assert source == str(path)
  assert token == "1234"
Example #3
0
def test_GetDefaultGithubAccessToken_from_github_access_token_flag(
  tempdir: pathlib.Path,
):
  FLAGS.unparse_flags()
  FLAGS(["argv[0]", "--github_access_token", "1234"])

  source, token = api.GetDefaultGithubAccessToken()

  assert source == "--github_access_token"
  assert token == "1234"
Example #4
0
def test_GetDefaultGithubAccessToken_from_GITHUB_ACCESS_TOKEN_PATH(
  tempdir: pathlib.Path,
):
  path = tempdir / "access_token_path.txt"
  fs.Write(path, "1234".encode("utf-8"))
  with test.TemporaryEnv() as env:
    env["GITHUB_ACCESS_TOKEN_PATH"] = str(path)
    source, token = api.GetDefaultGithubAccessToken()

  assert source == f"$GITHUB_ACCESS_TOKEN_PATH={path}"
  assert token == "1234"
Example #5
0
def test_GetDefaultGithubAccessToken_from_github_access_token_path_flag(
  tempdir: pathlib.Path,
):
  path = tempdir / "access_token_path.txt"
  fs.Write(path, "1234".encode("utf-8"))

  FLAGS.unparse_flags()
  FLAGS(["argv[0]", "--github_access_token_path", str(path)])

  source, token = api.GetDefaultGithubAccessToken()

  assert source == f"--github_access_token_path={path}"
  assert token == "1234"
Example #6
0
def test_GetDefaultGithubAccessToken_from_GITHUB_ACCESS_TOKEN_PATH_invalid_file(
  tempdir: pathlib.Path,
):
  path = tempdir / "access_token_path.txt"
  path.touch()
  with test.TemporaryEnv() as env:
    env["GITHUB_ACCESS_TOKEN_PATH"] = str(path)
    with test.Raises(api.BadCredentials) as e_ctx:
      api.GetDefaultGithubAccessToken()

  assert str(e_ctx.value) == (
    f"Invalid credentials file $GITHUB_ACCESS_TOKEN_PATH={path}: "
    "Access token not found in file"
  )
Example #7
0
def test_GetDefaultGithubAccessToken_invalid_github_access_token_path_flag(
  tempdir: pathlib.Path,
):
  path = tempdir / "access_token_path.txt"
  path.touch()

  FLAGS.unparse_flags()
  FLAGS(["argv[0]", "--github_access_token_path", str(path)])

  with test.Raises(api.BadCredentials) as e_ctx:
    api.GetDefaultGithubAccessToken()

  assert str(e_ctx.value) == (
    f"Invalid credentials file --github_access_token_path={path}: "
    "Access token not found in file"
  )