blizzardapi2 2.1.18__tar.gz → 2.1.20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/workflows/black-check.yml +1 -0
  2. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/workflows/python-package.yml +30 -0
  3. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.pre-commit-config.yaml +1 -1
  4. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.release-it.json +1 -1
  5. blizzardapi2-2.1.20/CLAUDE.md +69 -0
  6. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/CONTRIBUTING.md +2 -2
  7. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/PKG-INFO +2 -8
  8. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2.egg-info/PKG-INFO +2 -8
  9. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2.egg-info/SOURCES.txt +10 -1
  10. blizzardapi2-2.1.20/blizzardapi2.egg-info/requires.txt +8 -0
  11. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/package.json +1 -1
  12. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/pyproject.toml +8 -10
  13. blizzardapi2-2.1.20/tests/__init__.py +0 -0
  14. blizzardapi2-2.1.20/tests/conftest.py +64 -0
  15. blizzardapi2-2.1.20/tests/test_base_api.py +326 -0
  16. blizzardapi2-2.1.20/tests/test_battlenet.py +152 -0
  17. blizzardapi2-2.1.20/tests/test_diablo3.py +207 -0
  18. blizzardapi2-2.1.20/tests/test_hearthstone.py +151 -0
  19. blizzardapi2-2.1.20/tests/test_starcraft2.py +168 -0
  20. blizzardapi2-2.1.20/tests/test_wow.py +274 -0
  21. blizzardapi2-2.1.18/blizzardapi2.egg-info/requires.txt +0 -14
  22. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  23. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  24. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/dependabot.yml +0 -0
  25. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.github/workflows/README.md +0 -0
  26. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/.gitignore +0 -0
  27. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/CODE_OF_CONDUCT.md +0 -0
  28. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/LICENSE +0 -0
  29. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/README.md +0 -0
  30. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/SECURITY.md +0 -0
  31. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/__init__.py +0 -0
  32. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/api.py +0 -0
  33. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/battlenet/__init__.py +0 -0
  34. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/battlenet/battlenet_api.py +0 -0
  35. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/battlenet/battlenet_oauth_api.py +0 -0
  36. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/blizzard_api.py +0 -0
  37. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/diablo3/__init__.py +0 -0
  38. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/diablo3/diablo3_api.py +0 -0
  39. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/diablo3/diablo3_community_api.py +0 -0
  40. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -0
  41. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/hearthstone/__init__.py +0 -0
  42. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/hearthstone/hearthstone_api.py +0 -0
  43. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/hearthstone/hearthstone_game_data_api.py +0 -0
  44. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/starcraft2/__init__.py +0 -0
  45. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/starcraft2/starcraft2_api.py +0 -0
  46. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/starcraft2/starcraft2_community_api.py +0 -0
  47. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -0
  48. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/types.py +0 -0
  49. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/wow/__init__.py +0 -0
  50. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/wow/wow_api.py +0 -0
  51. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/wow/wow_game_data_api.py +0 -0
  52. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2/wow/wow_profile_api.py +0 -0
  53. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2.egg-info/dependency_links.txt +0 -0
  54. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/blizzardapi2.egg-info/top_level.txt +0 -0
  55. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/battlenet/README.md +0 -0
  56. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/diablo3/README.md +0 -0
  57. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/hearthstone/README.md +0 -0
  58. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/pull_request_template.md +0 -0
  59. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/starcraft2/README.md +0 -0
  60. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/docs/wow/README.md +0 -0
  61. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/poetry.lock +0 -0
  62. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/setup.cfg +0 -0
  63. {blizzardapi2-2.1.18 → blizzardapi2-2.1.20}/uv.lock +0 -0
@@ -16,3 +16,4 @@ jobs:
16
16
  with:
17
17
  options: "--check --verbose"
18
18
  src: "."
19
+ version: "26.3.1"
@@ -6,6 +6,8 @@ name: Python package
6
6
  on:
7
7
  push:
8
8
  branches: ["main"]
9
+ pull_request:
10
+ branches: ["main"]
9
11
 
10
12
  # Add permissions block
11
13
  permissions:
@@ -14,7 +16,35 @@ permissions:
14
16
  id-token: write
15
17
 
16
18
  jobs:
19
+ test:
20
+ runs-on: ubuntu-latest
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ python-version: ["3.11", "3.12", "3.13"]
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ uses: actions/setup-python@v5
30
+ with:
31
+ python-version: ${{ matrix.python-version }}
32
+
33
+ - name: Install uv
34
+ run: |
35
+ curl -LsSf https://astral.sh/uv/install.sh | sh
36
+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
37
+
38
+ - name: Create venv and install dev deps
39
+ run: |
40
+ uv venv
41
+ uv pip install -e ".[dev]"
42
+
43
+ - name: Run tests
44
+ run: uv run pytest tests/ -v
45
+
17
46
  publish:
47
+ needs: test
18
48
  if: github.ref == 'refs/heads/main'
19
49
  runs-on: ubuntu-latest
20
50
  steps:
@@ -1,6 +1,6 @@
1
1
  repos:
2
2
  - repo: https://github.com/psf/black
3
- rev: 25.1.0
3
+ rev: 26.3.1
4
4
  hooks:
5
5
  - id: black
6
6
  language_version: python3
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "hooks": {
15
15
  "after:bump": [
16
- "sed -i 's/version = \".*\"/version = \"${version}\"/' pyproject.toml"
16
+ "sed -i 's/^version = \".*\"/version = \"${version}\"/' pyproject.toml"
17
17
  ]
18
18
  }
19
19
  }
@@ -0,0 +1,69 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project
6
+
7
+ `blizzardapi2` is a published PyPI package (synchronous client wrapper around Blizzard's Battle.net APIs). Public API surface is `from blizzardapi2 import BlizzardApi`. Treat the package boundary as load-bearing — every name, parameter shape, and return type is part of the contract for external users.
8
+
9
+ Python 3.11+ only. Uses `requests` synchronously today; `aiohttp` and `pydantic` are declared dependencies but not yet integrated into the public surface.
10
+
11
+ ## Common commands
12
+
13
+ Use `uv` for environment management (matches CI):
14
+
15
+ ```bash
16
+ uv venv
17
+ uv pip install -e ".[dev]"
18
+ ```
19
+
20
+ Lint / format:
21
+
22
+ ```bash
23
+ ruff check . # lint (line-length 120, see caveat below)
24
+ ruff format . # format
25
+ black . # pre-commit also runs black with --line-length=88 (mismatch — see below)
26
+ ```
27
+
28
+ Tests: **there is no `test_project/` directory in the repo despite CONTRIBUTING.md referencing it**, and no test job in CI. If you add tests, use `pytest` / `pytest-mock` / `pytest-asyncio` (already in `[dev]`) and configure a workflow.
29
+
30
+ Release: do not bump versions by hand. Pushing to `main` triggers `.github/workflows/python-package.yml`, which builds, publishes to PyPI, then runs `release-it` to tag and create a GitHub release. `release-it`'s `after:bump` hook `sed`s `pyproject.toml`'s `version = "..."`.
31
+
32
+ ## Architecture
33
+
34
+ Single base class + one facade per game, each game facade composing sub-APIs:
35
+
36
+ ```
37
+ BlizzardApi (blizzard_api.py)
38
+ ├── wow → WowApi → { game_data: WowGameDataApi, profile: WowProfileApi }
39
+ ├── diablo3 → Diablo3Api → { community, game_data }
40
+ ├── hearthstone, starcraft2, battlenet → similar pattern
41
+ ```
42
+
43
+ All API classes inherit `BaseApi` (`api.py`). New endpoint methods are thin wrappers: build a `resource` path + `query_params` dict (typically `{"namespace": f"static-{region}", "locale": locale}`), then call `super().get_resource(...)` or `super().get_oauth_resource(...)`. Patterns are most clearly visible in `wow/wow_game_data_api.py`.
44
+
45
+ ### Token handling — the non-obvious part
46
+
47
+ `BaseApi._make_request` has a deliberate indirection: callers pass user OAuth tokens **inside `query_params` under the key `"access_token"`**. `_make_request` `.pop()`s that key and moves the value into the `Authorization: Bearer <token>` header. This keeps tokens out of URL query strings (visible in logs/proxies). Preserve this when adding OAuth-protected endpoints — see `battlenet/battlenet_oauth_api.py:get_user_info` for the canonical shape. Don't add a separate `access_token` keyword argument to `_make_request`; the pop-from-params pattern is the contract.
48
+
49
+ Client-credentials tokens are managed automatically: `_ensure_valid_token` lazily fetches and caches them, with a 5-minute refresh buffer (`TOKEN_REFRESH_BUFFER`). On a 401 with a client-credentials token, `_make_request` refreshes and retries once. User-supplied OAuth tokens are never refreshed by the library.
50
+
51
+ ### Region URL routing
52
+
53
+ `BaseApi.OAUTH_URLS` and `API_URLS` route China (`"cn"`) to `*.battlenet.com.cn` hosts, all other regions to `oauth.battle.net` and `{region}.api.blizzard.com`. Always use `_build_oauth_url` / `_build_api_url` rather than f-stringing URLs by hand.
54
+
55
+ ### Independent token caches per sub-API
56
+
57
+ Each game's facade instantiates its sub-APIs with `client_id`/`client_secret`, so `WowGameDataApi`, `WowProfileApi`, `Diablo3CommunityApi`, etc. each maintain their **own** `_session` and `_access_token`. There is no shared token cache across sub-APIs. This is fine for the current API surface but worth knowing if you're debugging unexpected token-fetch behavior.
58
+
59
+ ### `Region` / `Locale` enums
60
+
61
+ `types.py` defines `Region` and `Locale` as `str` enums. Most current endpoint methods are typed as `region: str, locale: str` and accept either bare strings or enum members (since enums subclass `str`). Newer code (e.g., `BattlenetOAuthApi`) uses the enums in signatures — prefer that for new code.
62
+
63
+ ## Conventions and gotchas
64
+
65
+ - **`blizzardapi2/_version.py` is auto-generated** by `setuptools_scm` (`write_to` configured in `pyproject.toml`). Never edit by hand; don't import it as authoritative — `pyproject.toml`'s `version` is what `release-it` mutates.
66
+ - **`tool.ruff.target-version` in `pyproject.toml` is currently `"2.1.18"`** (the package version). The release-it `sed` hook replaces every `version = "..."` line and clobbers it. If you touch ruff config, restore this to `"py311"` and consider tightening the sed to `^version =` to prevent recurrence.
67
+ - **Black line-length mismatch:** pre-commit runs `black --line-length=88`, but `tool.ruff.line-length = 120`. Don't reformat existing files just to "fix" this — it'll churn diffs. Match surrounding style.
68
+ - Inherit from `Api`/`BaseApi` (not `BaseApi` plus a separate base) — see CONTRIBUTING.md "Import Fixes" section.
69
+ - Commit style is conventional commits (`feat:`, `fix:`, `chore:`, etc.) — release notes are auto-generated from them.
@@ -131,7 +131,7 @@ Use conventional commit messages:
131
131
  pytest
132
132
 
133
133
  # Run specific test file
134
- pytest test_project/test_wow.py
134
+ pytest tests/test_wow.py
135
135
 
136
136
  # Run with verbose output
137
137
  pytest -v
@@ -139,7 +139,7 @@ pytest -v
139
139
 
140
140
  ### Writing Tests
141
141
 
142
- - Place tests in the `test_project/` directory
142
+ - Place tests in the `tests/` directory
143
143
  - Use descriptive test names
144
144
  - Include both positive and negative test cases
145
145
  - Mock external API calls
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blizzardapi2
3
- Version: 2.1.18
3
+ Version: 2.1.20
4
4
  Summary: A Python wrapper for Blizzard API
5
5
  Author-email: lostcol0ny <c098os0k@4wrd.cc>
6
6
  License-Expression: MIT
@@ -13,17 +13,11 @@ Requires-Python: >=3.11
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: requests<3.0.0,>=2.32.3
16
- Requires-Dist: black<27.0.0,>=24.4.2
17
- Requires-Dist: pytest<10.0.0,>=8.2.2
18
- Requires-Dist: pytest-mock<4.0.0,>=3.14.0
19
- Requires-Dist: ruff<1.0.0,>=0.3.0
20
- Requires-Dist: pydantic>=2.11.6
21
- Requires-Dist: aiohttp>=3.12.12
22
16
  Provides-Extra: dev
23
17
  Requires-Dist: pytest<10.0.0,>=8.2.2; extra == "dev"
24
18
  Requires-Dist: pytest-mock<4.0.0,>=3.14.0; extra == "dev"
25
19
  Requires-Dist: pytest-asyncio<2.0.0,>=0.23.5; extra == "dev"
26
- Requires-Dist: black<27.0.0,>=24.4.2; extra == "dev"
20
+ Requires-Dist: black<27.0.0,>=26.3.1; extra == "dev"
27
21
  Requires-Dist: ruff<1.0.0,>=0.3.0; extra == "dev"
28
22
  Dynamic: license-file
29
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blizzardapi2
3
- Version: 2.1.18
3
+ Version: 2.1.20
4
4
  Summary: A Python wrapper for Blizzard API
5
5
  Author-email: lostcol0ny <c098os0k@4wrd.cc>
6
6
  License-Expression: MIT
@@ -13,17 +13,11 @@ Requires-Python: >=3.11
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: requests<3.0.0,>=2.32.3
16
- Requires-Dist: black<27.0.0,>=24.4.2
17
- Requires-Dist: pytest<10.0.0,>=8.2.2
18
- Requires-Dist: pytest-mock<4.0.0,>=3.14.0
19
- Requires-Dist: ruff<1.0.0,>=0.3.0
20
- Requires-Dist: pydantic>=2.11.6
21
- Requires-Dist: aiohttp>=3.12.12
22
16
  Provides-Extra: dev
23
17
  Requires-Dist: pytest<10.0.0,>=8.2.2; extra == "dev"
24
18
  Requires-Dist: pytest-mock<4.0.0,>=3.14.0; extra == "dev"
25
19
  Requires-Dist: pytest-asyncio<2.0.0,>=0.23.5; extra == "dev"
26
- Requires-Dist: black<27.0.0,>=24.4.2; extra == "dev"
20
+ Requires-Dist: black<27.0.0,>=26.3.1; extra == "dev"
27
21
  Requires-Dist: ruff<1.0.0,>=0.3.0; extra == "dev"
28
22
  Dynamic: license-file
29
23
 
@@ -1,6 +1,7 @@
1
1
  .gitignore
2
2
  .pre-commit-config.yaml
3
3
  .release-it.json
4
+ CLAUDE.md
4
5
  CODE_OF_CONDUCT.md
5
6
  CONTRIBUTING.md
6
7
  LICENSE
@@ -48,4 +49,12 @@ docs/battlenet/README.md
48
49
  docs/diablo3/README.md
49
50
  docs/hearthstone/README.md
50
51
  docs/starcraft2/README.md
51
- docs/wow/README.md
52
+ docs/wow/README.md
53
+ tests/__init__.py
54
+ tests/conftest.py
55
+ tests/test_base_api.py
56
+ tests/test_battlenet.py
57
+ tests/test_diablo3.py
58
+ tests/test_hearthstone.py
59
+ tests/test_starcraft2.py
60
+ tests/test_wow.py
@@ -0,0 +1,8 @@
1
+ requests<3.0.0,>=2.32.3
2
+
3
+ [dev]
4
+ pytest<10.0.0,>=8.2.2
5
+ pytest-mock<4.0.0,>=3.14.0
6
+ pytest-asyncio<2.0.0,>=0.23.5
7
+ black<27.0.0,>=26.3.1
8
+ ruff<1.0.0,>=0.3.0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blizzardapi2",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
4
4
  "scripts": {
5
5
  "release": "release-it"
6
6
  },
@@ -1,18 +1,12 @@
1
1
  [project]
2
2
  name = "blizzardapi2"
3
- version = "2.1.18"
3
+ version = "2.1.20"
4
4
  description = "A Python wrapper for Blizzard API"
5
5
  authors = [{ name = "lostcol0ny", email = "c098os0k@4wrd.cc" }]
6
6
  license = "MIT"
7
7
  readme = "README.md"
8
8
  dependencies = [
9
9
  "requests>=2.32.3,<3.0.0",
10
- "black>=24.4.2,<27.0.0",
11
- "pytest>=8.2.2,<10.0.0",
12
- "pytest-mock>=3.14.0,<4.0.0",
13
- "ruff>=0.3.0,<1.0.0",
14
- "pydantic>=2.11.6",
15
- "aiohttp>=3.12.12",
16
10
  ]
17
11
  requires-python = ">=3.11"
18
12
  classifiers = [
@@ -35,12 +29,16 @@ include = ["blizzardapi2*"]
35
29
  write_to = "blizzardapi2/_version.py"
36
30
  local_scheme = "node-and-timestamp"
37
31
 
32
+ [tool.pytest.ini_options]
33
+ testpaths = ["tests"]
34
+ pythonpath = ["."]
35
+
38
36
  [project.optional-dependencies]
39
37
  dev = [
40
38
  "pytest>=8.2.2,<10.0.0",
41
39
  "pytest-mock>=3.14.0,<4.0.0",
42
40
  "pytest-asyncio>=0.23.5,<2.0.0",
43
- "black>=24.4.2,<27.0.0",
41
+ "black>=26.3.1,<27.0.0",
44
42
  "ruff>=0.3.0,<1.0.0",
45
43
  ]
46
44
 
@@ -76,10 +74,10 @@ exclude = [
76
74
  ]
77
75
 
78
76
  # Same as Black.
79
- line-length = 120
77
+ line-length = 88
80
78
 
81
79
  # Assume Python 3.11
82
- target-version = "2.1.18"
80
+ target-version = "py311"
83
81
 
84
82
  # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
85
83
  select = ["E4", "E7", "E9", "F"]
File without changes
@@ -0,0 +1,64 @@
1
+ """Shared pytest fixtures for blizzardapi2 tests.
2
+
3
+ The Blizzard API client is a thin wrapper around `requests`. Tests verify URL
4
+ construction, query-parameter shape, and token handling — never live HTTP. All
5
+ network is patched at the `requests.Session` boundary.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from datetime import UTC, datetime, timedelta
11
+ from typing import Any
12
+ from unittest.mock import MagicMock
13
+
14
+ import pytest
15
+
16
+ CLIENT_ID = "test_client_id"
17
+ CLIENT_SECRET = "test_client_secret"
18
+ FAKE_TOKEN = "fake_access_token"
19
+
20
+
21
+ @pytest.fixture
22
+ def fake_credentials() -> tuple[str, str]:
23
+ """Stable (client_id, client_secret) pair for instantiating API clients."""
24
+ return CLIENT_ID, CLIENT_SECRET
25
+
26
+
27
+ @pytest.fixture
28
+ def mock_get(mocker) -> MagicMock:
29
+ """Patch `requests.Session.get` globally with a 200 + empty-dict response.
30
+
31
+ Tests typically inspect `mock_get.call_args` to assert URL, params, and
32
+ headers. Override `return_value.json.return_value` per-test for shaped data.
33
+ """
34
+ mock = mocker.patch("requests.Session.get")
35
+ mock.return_value.status_code = 200
36
+ mock.return_value.json.return_value = {}
37
+ return mock
38
+
39
+
40
+ @pytest.fixture
41
+ def mock_post(mocker) -> MagicMock:
42
+ """Patch `requests.Session.post` to return a fake OAuth token response.
43
+
44
+ BaseApi calls POST only for `/oauth/token` (client-credentials flow).
45
+ """
46
+ mock = mocker.patch("requests.Session.post")
47
+ mock.return_value.status_code = 200
48
+ mock.return_value.json.return_value = {
49
+ "access_token": FAKE_TOKEN,
50
+ "token_type": "bearer",
51
+ "expires_in": 86400,
52
+ }
53
+ return mock
54
+
55
+
56
+ def prime_token(
57
+ api_instance: Any, token: str = FAKE_TOKEN, expires_in: int = 86400
58
+ ) -> None:
59
+ """Pre-populate an API instance with a non-expired client-credentials token.
60
+
61
+ Lets tests skip the token POST when they only care about the GET request.
62
+ """
63
+ api_instance._access_token = token
64
+ api_instance._token_expires_at = datetime.now(UTC) + timedelta(seconds=expires_in)