Render blog posts from Forgejo
This commit is contained in:
parent
6671a01d26
commit
0a9b052beb
6 changed files with 366 additions and 48 deletions
75
tests/test_live_prototype.py
Normal file
75
tests/test_live_prototype.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
from live_prototype import _post_card, _summarize_repo
|
||||
|
||||
|
||||
class LivePrototypeTestCase(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_blog_folder_becomes_renderable_post_card(self) -> None:
|
||||
client = _FakeContentClient()
|
||||
summary = await _summarize_repo(
|
||||
client,
|
||||
{
|
||||
"name": "robot-u-site",
|
||||
"full_name": "Robot-U/robot-u-site",
|
||||
"description": "Robot U site source",
|
||||
"updated_at": "2026-04-13T00:00:00Z",
|
||||
"owner": {"login": "Robot-U"},
|
||||
},
|
||||
)
|
||||
|
||||
self.assertIsNotNone(summary)
|
||||
assert summary is not None
|
||||
self.assertEqual(summary["blog_count"], 1)
|
||||
post = _post_card(summary["blog_posts"][0])
|
||||
self.assertEqual(post["title"], "Building Robot U")
|
||||
self.assertEqual(post["slug"], "building-robot-u-site")
|
||||
self.assertEqual(post["repo"], "Robot-U/robot-u-site")
|
||||
self.assertEqual(post["path"], "blogs/building-robot-u-site")
|
||||
self.assertIn("thin layer over Forgejo", post["body"])
|
||||
|
||||
|
||||
class _FakeContentClient:
|
||||
async def list_directory(
|
||||
self,
|
||||
_owner: str,
|
||||
_repo: str,
|
||||
path: str = "",
|
||||
) -> list[dict[str, Any]]:
|
||||
entries = {
|
||||
"": [{"type": "dir", "name": "blogs"}],
|
||||
"blogs": [{"type": "dir", "name": "building-robot-u-site"}],
|
||||
"blogs/building-robot-u-site": [
|
||||
{
|
||||
"type": "file",
|
||||
"name": "index.md",
|
||||
"html_url": "https://aksal.cloud/Robot-U/robot-u-site/src/branch/main/blogs/building-robot-u-site/index.md",
|
||||
},
|
||||
],
|
||||
}
|
||||
return entries.get(path, [])
|
||||
|
||||
async def get_file_content(self, _owner: str, _repo: str, path: str) -> dict[str, str]:
|
||||
return {
|
||||
"name": "index.md",
|
||||
"path": path,
|
||||
"html_url": "https://aksal.cloud/Robot-U/robot-u-site/src/branch/main/blogs/building-robot-u-site/index.md",
|
||||
"content": "\n".join(
|
||||
[
|
||||
"---",
|
||||
"title: Building Robot U",
|
||||
"summary: How the site became a thin layer over Forgejo.",
|
||||
"---",
|
||||
"",
|
||||
"# Building Robot U",
|
||||
"",
|
||||
"The site is a thin layer over Forgejo.",
|
||||
],
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue