fix: prevent source state writes in dry-run
This commit is contained in:
@@ -35,6 +35,49 @@ def test_state_file_absent_empty_state(tmp_path: Path) -> None:
|
||||
assert state.get_cache_headers() == (None, None)
|
||||
|
||||
|
||||
def test_disabled_persistence_keeps_updates_in_memory_without_creating_file(tmp_path: Path) -> None:
|
||||
"""Vérifie que la persistance désactivée conserve l'état uniquement en mémoire.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "state.json"
|
||||
state = BlogRSSState(state_file, persistence_enabled=False)
|
||||
|
||||
state.add_guids(["guid-1"])
|
||||
state.update_cache_headers("etag-123", "Wed, 01 Sep 2026 GMT")
|
||||
|
||||
assert state.get_known_guids() == frozenset({"guid-1"})
|
||||
assert state.get_cache_headers() == ("etag-123", "Wed, 01 Sep 2026 GMT")
|
||||
assert not state_file.exists()
|
||||
|
||||
|
||||
def test_disabled_persistence_preserves_existing_file(tmp_path: Path) -> None:
|
||||
"""Vérifie que la persistance désactivée ne modifie pas l'état déjà stocké.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "state.json"
|
||||
original_content = json.dumps(
|
||||
{
|
||||
"version": 1,
|
||||
"known_guids": ["existing-guid"],
|
||||
"etag": "old-etag",
|
||||
"last_modified": "Tue, 31 Aug 2026 GMT",
|
||||
}
|
||||
)
|
||||
state_file.write_text(original_content, encoding="utf-8")
|
||||
state = BlogRSSState(state_file, persistence_enabled=False)
|
||||
|
||||
state.add_guids(["new-guid"])
|
||||
state.update_cache_headers("new-etag", "Wed, 01 Sep 2026 GMT")
|
||||
|
||||
assert state.get_known_guids() == frozenset({"existing-guid", "new-guid"})
|
||||
assert state.get_cache_headers() == ("new-etag", "Wed, 01 Sep 2026 GMT")
|
||||
assert state_file.read_text(encoding="utf-8") == original_content
|
||||
|
||||
|
||||
def test_add_guids_persists(tmp_path: Path) -> None:
|
||||
"""Vérifie que l'ajout de GUID persiste dans le fichier JSON.
|
||||
|
||||
|
||||
@@ -37,6 +37,90 @@ def test_load_no_file_returns_none(tmp_path: Path) -> None:
|
||||
assert state.load() is None
|
||||
|
||||
|
||||
def test_disabled_persistence_keeps_credentials_in_memory_without_creating_file(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Vérifie que la persistance désactivée conserve les credentials en mémoire.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "auth.json"
|
||||
credentials = {
|
||||
"pronote_url": "https://example.com/pronote",
|
||||
"username": "parent-1",
|
||||
"password": "token-123", # pragma: allowlist secret
|
||||
"uuid": "uuid-456",
|
||||
}
|
||||
state = PronoteAuthState(state_file, persistence_enabled=False)
|
||||
|
||||
state.save(credentials)
|
||||
|
||||
assert state.load() == credentials
|
||||
assert not state_file.exists()
|
||||
|
||||
|
||||
def test_disabled_persistence_preserves_existing_file(tmp_path: Path) -> None:
|
||||
"""Vérifie que la persistance désactivée garde les nouveaux credentials en mémoire.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "auth.json"
|
||||
original_credentials = {
|
||||
"pronote_url": "https://example.com/pronote",
|
||||
"username": "parent-1",
|
||||
"password": "old-token", # pragma: allowlist secret
|
||||
"uuid": "old-uuid",
|
||||
}
|
||||
original_content = json.dumps({"version": 1, "credentials": original_credentials}).encode()
|
||||
new_credentials = {
|
||||
"pronote_url": "https://example.com/pronote",
|
||||
"username": "parent-1",
|
||||
"password": "new-token", # pragma: allowlist secret
|
||||
"uuid": "new-uuid",
|
||||
}
|
||||
state_file.write_bytes(original_content)
|
||||
state = PronoteAuthState(state_file, persistence_enabled=False)
|
||||
|
||||
assert state.load() == original_credentials
|
||||
|
||||
state.save(new_credentials)
|
||||
|
||||
assert state.load() == new_credentials
|
||||
assert state_file.read_bytes() == original_content
|
||||
|
||||
|
||||
def test_disabled_persistence_clear_discards_in_memory_credentials_only(tmp_path: Path) -> None:
|
||||
"""Vérifie que clear oublie l'état en mémoire sans modifier le fichier existant.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "auth.json"
|
||||
original_credentials = {
|
||||
"pronote_url": "https://example.com/pronote",
|
||||
"username": "parent-1",
|
||||
"password": "old-token", # pragma: allowlist secret
|
||||
"uuid": "old-uuid",
|
||||
}
|
||||
original_content = json.dumps({"version": 1, "credentials": original_credentials}).encode()
|
||||
credentials = {
|
||||
"pronote_url": "https://example.com/pronote",
|
||||
"username": "parent-1",
|
||||
"password": "new-token", # pragma: allowlist secret
|
||||
"uuid": "new-uuid",
|
||||
}
|
||||
state_file.write_bytes(original_content)
|
||||
state = PronoteAuthState(state_file, persistence_enabled=False)
|
||||
|
||||
state.save(credentials)
|
||||
state.clear()
|
||||
|
||||
assert state.load() is None
|
||||
assert state_file.read_bytes() == original_content
|
||||
|
||||
|
||||
def test_save_then_load_roundtrip(tmp_path: Path) -> None:
|
||||
"""Vérifie que des credentials sauvegardés sont rechargés à l'identique.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user