Files
website-v2/core/tests/test_tasks.py
Gavin Wahl cb25772a13 AsciiDoc use the embedded option (#1344)
Instead of parsing out the HTML body from the full HTML document.

All adoc parsing now goes through `convert_adoc_to_html`. I removed the
`adoc_to_html` task because it was never `.delay`ed, probably because it
doesn't necessarily work: it expects content to be passed in a temp
file, which might not exist on the worker processing the task. The new
function passes the content as a string instead of a temp file.

This removes the `div#header` and `div#content` containers from the
output. It's wrong to have IDs in embeddable html because multiple
asciidoc outputs might be included on the same page, resulting in
duplicate IDs. I couldn't find a place where these containers are
necessary, though, because markdown output doesn't include them,
resulting in a discrepancy in the output for markdown vs asciidoc that
is now fixed. If we need to include the containers, I'd wrap the
asciidoc output in the template where it is used rather than expecting
it to be returned by `convert_adoc_to_html`.

Fixes #1302
2024-10-11 10:34:04 -06:00

54 lines
1.7 KiB
Python

from model_bakery import baker
from django.core.cache import caches
from django.test import override_settings
from core.models import RenderedContent
from core.tasks import (
clear_rendered_content_cache_by_cache_key,
clear_rendered_content_cache_by_content_type,
)
TEST_CACHES = {
"static_content": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "third-unique-snowflake",
"TIMEOUT": "60", # Cache timeout in seconds: 1 minute
},
}
@override_settings(CACHES=TEST_CACHES)
def test_clear_rendered_content_by_content_type():
baker.make("core.RenderedContent", content_type="keep", cache_key="keep")
baker.make("core.RenderedContent", content_type="clear", cache_key="clear")
cache = caches["static_content"]
cache.set("keep", "keep")
cache.set("clear", "clear")
assert cache.get("keep") == "keep"
assert cache.get("clear") == "clear"
clear_rendered_content_cache_by_content_type("clear")
assert cache.get("keep") == "keep"
assert cache.get("clear") is None
assert RenderedContent.objects.filter(content_type="keep").exists()
assert not RenderedContent.objects.filter(content_type="clear").exists()
@override_settings(CACHES=TEST_CACHES)
def test_clear_rendered_content_by_cache_key():
obj = baker.make("core.RenderedContent", cache_key="clear")
cache_key = obj.cache_key
cache = caches["static_content"]
cache.set(cache_key, "sample content")
assert cache.get(cache_key) == "sample content"
clear_rendered_content_cache_by_cache_key(cache_key)
assert not cache.get(cache_key)
assert not RenderedContent.objects.filter(cache_key=cache_key).exists()