From cc80122d86f2f0dc4e12d8a112db61c01ea4c776 Mon Sep 17 00:00:00 2001 From: autotest Date: Fri, 31 Jul 2026 12:17:56 +0000 Subject: [PATCH] Add tests generated by autotest --- tests/test_memorycache.py | 36 ++++++++++++++++++++++++++++++++++++ tests/test_opengraph.py | 25 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/test_memorycache.py create mode 100644 tests/test_opengraph.py diff --git a/tests/test_memorycache.py b/tests/test_memorycache.py new file mode 100644 index 0000000..ba97caf --- /dev/null +++ b/tests/test_memorycache.py @@ -0,0 +1,36 @@ +import asyncio + +from imoog.cache.memorycache import InMemoryCache + + +def test_cache_round_trip_and_delete(): + async def exercise_cache(): + cache = InMemoryCache() + connection = await cache.connect(max_cache_size=10) + + assert connection == {} + assert await cache.get("missing") is None + + await cache.set("logo", b"image data", "image/png") + assert await cache.get("logo") == (b"image data", "image/png") + assert await cache.delete("logo") is True + assert await cache.get("logo") is None + assert await cache.delete("logo") is False + + asyncio.run(exercise_cache()) + + +def test_cleanup_removes_cached_images_and_mime_metadata(): + async def exercise_cache(): + cache = InMemoryCache() + await cache.connect(max_cache_size=10) + await cache.set("first", b"first image", "image/jpeg") + await cache.set("second", b"second image", "image/webp") + + await cache.cleanup() + + assert cache._connection == {} + assert await cache.get("first") is None + assert await cache.get("second") is None + + asyncio.run(exercise_cache()) diff --git a/tests/test_opengraph.py b/tests/test_opengraph.py new file mode 100644 index 0000000..a8b8625 --- /dev/null +++ b/tests/test_opengraph.py @@ -0,0 +1,25 @@ +from imoog.opengraph import generate_opengraph_tag, generate_tags_from_dict + + +def test_generate_opengraph_tag_adds_namespace_and_content(): + assert generate_opengraph_tag("title", "Imoog CDN") == ( + '' + ) + + +def test_generate_tags_from_dict_preserves_property_order(): + properties = { + "title": "Imoog CDN", + "description": "A database-backed CDN", + "type": "website", + } + + assert generate_tags_from_dict(properties) == [ + '', + '', + '', + ] + + +def test_generate_tags_from_empty_dict_returns_empty_list(): + assert generate_tags_from_dict({}) == []