Skip to content

Commit

Permalink
Test make_user_agent()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Nov 3, 2023
1 parent 1006aa9 commit 801e5b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ghreq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def make_user_agent(
s += f"/{version}"
if url is not None:
s += f" ({url})"
s += "requests/{} {}/{}".format(
s += " requests/{} {}/{}".format(
requests.__version__,
platform.python_implementation(),
platform.python_version(),
Expand Down
27 changes: 26 additions & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
import platform
import pytest
from ghreq import get_github_api_url
import requests
from ghreq import get_github_api_url, make_user_agent


def test_get_github_api_url_no_envvar(monkeypatch: pytest.MonkeyPatch) -> None:
Expand All @@ -16,3 +18,26 @@ def test_get_github_api_url_empty_envvar(monkeypatch: pytest.MonkeyPatch) -> Non
def test_get_github_api_url_from_envvar(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GITHUB_API_URL", "https://github.example.com/api")
assert get_github_api_url() == "https://github.example.com/api"


@pytest.mark.parametrize(
"version,url,start",
[
(
"1.2.3",
"https://my.site/myclient",
"myclient/1.2.3 (https://my.site/myclient)",
),
(None, "https://my.site/myclient", "myclient (https://my.site/myclient)"),
("1.2.3", None, "myclient/1.2.3"),
(None, None, "myclient"),
],
)
def test_make_user_agent(version: str | None, url: str | None, start: str) -> None:
expected = start + " requests/{} {}/{}".format(
requests.__version__,
platform.python_implementation(),
platform.python_version(),
)
s = make_user_agent("myclient", version, url)
assert s == expected

0 comments on commit 801e5b7

Please sign in to comment.