Use Etag in GitHub coordinator updates (#64449)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
1ffc2a05db
commit
e272ab7a29
11 changed files with 1541 additions and 48 deletions
|
@ -1,14 +1,17 @@
|
|||
"""Common helpers for GitHub integration tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.github.const import CONF_REPOSITORIES
|
||||
from homeassistant.components.github.const import CONF_REPOSITORIES, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
MOCK_ACCESS_TOKEN = "gho_16C7e42F292c6912E7710c838347Ae178B4a"
|
||||
TEST_REPOSITORY = "octocat/Hello-World"
|
||||
|
||||
|
||||
async def setup_github_integration(
|
||||
|
@ -17,19 +20,22 @@ async def setup_github_integration(
|
|||
aioclient_mock: AiohttpClientMocker,
|
||||
) -> None:
|
||||
"""Mock setting up the integration."""
|
||||
repository_id = 1
|
||||
for repository in mock_config_entry.options[CONF_REPOSITORIES]:
|
||||
headers = json.loads(load_fixture("base_headers.json", DOMAIN))
|
||||
for idx, repository in enumerate(mock_config_entry.options[CONF_REPOSITORIES]):
|
||||
aioclient_mock.get(
|
||||
f"https://api.github.com/repos/{repository}",
|
||||
json={"full_name": repository, "id": repository_id},
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={
|
||||
**json.loads(load_fixture("repository.json", DOMAIN)),
|
||||
"full_name": repository,
|
||||
"id": idx,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
repository_id += 1
|
||||
for endpoint in ("issues", "pulls", "releases", "commits"):
|
||||
aioclient_mock.get(
|
||||
f"https://api.github.com/repos/{repository}/{endpoint}",
|
||||
json=[],
|
||||
headers={"Content-Type": "application/json"},
|
||||
json=json.loads(load_fixture(f"{endpoint}.json", DOMAIN)),
|
||||
headers=headers,
|
||||
)
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue