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
47 changes: 47 additions & 0 deletions tests/test_memorycache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import asyncio

from imoog.cache.memorycache import InMemoryCache


def run(coroutine):
return asyncio.run(coroutine)


def test_set_and_get_round_trip_image_and_mime():
cache = InMemoryCache()
run(cache.connect(max_cache_size=10))

run(cache.set(key="IMAGE123", image=b"image bytes", mime="image/png"))

assert run(cache.get("IMAGE123")) == (b"image bytes", "image/png")


def test_get_returns_none_when_image_or_mime_is_missing():
cache = InMemoryCache()
connection = run(cache.connect(max_cache_size=10))
connection["image-only"] = b"image bytes"
connection["mime-only__mime__"] = "image/png"

assert run(cache.get("unknown")) is None
assert run(cache.get("image-only")) is None
assert run(cache.get("mime-only")) is None


def test_delete_removes_image_and_mime_and_reports_result():
cache = InMemoryCache()
run(cache.connect(max_cache_size=10))
run(cache.set(key="IMAGE123", image=b"image bytes", mime="image/png"))

assert run(cache.delete("IMAGE123")) is True
assert run(cache.get("IMAGE123")) is None
assert run(cache.delete("IMAGE123")) is False


def test_cleanup_clears_all_cached_values():
cache = InMemoryCache()
connection = run(cache.connect(max_cache_size=10))
run(cache.set(key="IMAGE123", image=b"image bytes", mime="image/png"))

run(cache.cleanup())

assert connection == {}
28 changes: 28 additions & 0 deletions tests/test_opengraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from imoog.opengraph import generate_opengraph_tag, generate_tags_from_dict


def test_generate_opengraph_tag_prefixes_property_and_preserves_content():
tag = generate_opengraph_tag("image", "https://cdn.example/image.png?a=1&b=2")

assert tag == (
'<meta property="og:image" '
'content="https://cdn.example/image.png?a=1&b=2" />'
)


def test_generate_tags_from_dict_preserves_input_order():
properties = {
"title": "Example title",
"description": "Example description",
"type": "website",
}

assert generate_tags_from_dict(properties) == [
'<meta property="og:title" content="Example title" />',
'<meta property="og:description" content="Example description" />',
'<meta property="og:type" content="website" />',
]


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