mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
An http_regex source read one document, so a tag whose parts upstream keeps in two files could only carry the second part as a literal. Every pin also fetched its document on its own: a failed request left one pin of a release behind while the others moved. url now takes a list whose bodies are searched as one text, and every document is fetched once per run, so all pins that read it resolve against the same snapshot. The HTTP reads move into utils/update/fetch.py. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
import unittest.mock as mock
|
|
|
|
from utils.update import fetch as module
|
|
|
|
BODIES = {
|
|
"https://example.test/tags": b"core v1.0.0",
|
|
"https://example.test/compose": b"image: example/app:v1.0.0-1.29",
|
|
}
|
|
|
|
|
|
class TestDocuments(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
module.document.cache_clear()
|
|
self.addCleanup(module.document.cache_clear)
|
|
|
|
def test_several_documents_are_read_as_one_text(self) -> None:
|
|
with mock.patch.object(module, "get", side_effect=BODIES.__getitem__):
|
|
self.assertEqual(
|
|
module.documents(list(BODIES)),
|
|
"core v1.0.0\nimage: example/app:v1.0.0-1.29",
|
|
)
|
|
self.assertEqual(
|
|
module.documents("https://example.test/tags"), "core v1.0.0"
|
|
)
|
|
|
|
def test_a_document_is_fetched_once_per_run(self) -> None:
|
|
with mock.patch.object(module, "get", side_effect=BODIES.__getitem__) as get:
|
|
module.documents(list(BODIES))
|
|
module.documents("https://example.test/tags")
|
|
module.documents("https://example.test/compose")
|
|
|
|
self.assertEqual(get.call_count, 2)
|
|
|
|
def test_a_failed_fetch_is_tried_again(self) -> None:
|
|
with mock.patch.object(module, "get", side_effect=OSError("down")):
|
|
with self.assertRaises(OSError):
|
|
module.documents("https://example.test/tags")
|
|
with mock.patch.object(module, "get", side_effect=BODIES.__getitem__):
|
|
self.assertEqual(
|
|
module.documents("https://example.test/tags"), "core v1.0.0"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|