Skip to content

Commit 13be3c9

Browse files
committed
Support README.adoc as fallback for library descriptions
1 parent c71187c commit 13be3c9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

libraries/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def get_description(self, client, tag="develop"):
341341
"""
342342
content = None
343343
# File paths/names where description data might be stored.
344-
files = ["doc/library-detail.adoc", "README.md"]
344+
files = ["doc/library-detail.adoc", "README.md", "README.adoc"]
345345

346346
# Try to get the content from the cache first
347347
static_content_cache = caches["static_content"]

libraries/tests/test_models.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import datetime
2+
from unittest.mock import MagicMock, patch
3+
4+
import pytest
5+
from django.core.cache import caches
26
from django.db.models import Sum
37
from model_bakery import baker
48

9+
from core.models import RenderedContent
510
from libraries.models import CommitAuthor
611
from mailing_list.models import EmailData
712

@@ -140,6 +145,37 @@ def test_library_version_first_boost_version_property(library):
140145
assert library.first_boost_version == version_3
141146

142147

148+
DESCRIPTION_FILES = ["doc/library-detail.adoc", "README.md", "README.adoc"]
149+
150+
151+
@pytest.mark.parametrize(
152+
"first_available, expected",
153+
[(0, "<p>adoc</p>"), (1, "<p>md</p>"), (2, "<p>adoc</p>"), (None, None)],
154+
ids=["library-detail.adoc", "README.md-fallback", "README.adoc-fallback", "none"],
155+
)
156+
@patch("libraries.models.process_md", return_value=("", "<p>md</p>"))
157+
@patch("libraries.models.write_content_to_tempfile")
158+
@patch("libraries.models.convert_adoc_to_html", return_value="<p>adoc</p>")
159+
def test_get_description_file_priority(
160+
mock_adoc, mock_tempfile, mock_md, library, first_available, expected
161+
):
162+
"""Files are tried in order; the first available file wins."""
163+
caches["static_content"].clear()
164+
RenderedContent.objects.all().delete()
165+
mock_tempfile.return_value.name = "/tmp/fake"
166+
167+
available = {
168+
f: b"content" if first_available is not None and i >= first_available else None
169+
for i, f in enumerate(DESCRIPTION_FILES)
170+
}
171+
client = MagicMock()
172+
client.get_file_content.side_effect = (
173+
lambda repo_slug, tag, file_path: available.get(file_path)
174+
)
175+
176+
assert library.get_description(client) == expected
177+
178+
143179
def test_merge_author_deletes_author():
144180
author_1_email = baker.make("libraries.CommitAuthorEmail")
145181
author_1 = author_1_email.author

0 commit comments

Comments
 (0)