Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/test_memorycache.py
Original file line number Diff line number Diff line change
@@ -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())
25 changes: 25 additions & 0 deletions tests/test_opengraph.py
Original file line number Diff line number Diff line change
@@ -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") == (
'<meta property="og:title" content="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) == [
'<meta property="og:title" content="Imoog CDN" />',
'<meta property="og:description" content="A database-backed CDN" />',
'<meta property="og:type" content="website" />',
]


def test_generate_tags_from_empty_dict_returns_empty_list():
assert generate_tags_from_dict({}) == []