Skip to content

Commit

Permalink
Fixed #1459 -- Fixed get_all_doc_versions template tag.
Browse files Browse the repository at this point in the history
Regression in 7596a1f.
  • Loading branch information
felixxm committed Jan 3, 2024
1 parent 7596a1f commit b15ab7d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
31 changes: 31 additions & 0 deletions docs/fixtures/doc_test_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
"status": "f"
}
},
{
"model": "releases.release",
"pk": "1.11",
"fields": {
"major": 1,
"is_lts": true,
"date": "2017-04-04",
"iteration": 0,
"micro": 0,
"minor": 11,
"status": "f"
}
},
{
"fields": {
"lang": "en",
Expand Down Expand Up @@ -153,5 +166,23 @@
},
"model": "docs.documentrelease",
"pk": 14
},
{
"fields": {
"lang": "en",
"is_default": true,
"release": "1.11"
},
"model": "docs.documentrelease",
"pk": 15
},
{
"fields": {
"lang": "fr",
"is_default": false,
"release": "1.11"
},
"model": "docs.documentrelease",
"pk": 16
}
]
2 changes: 1 addition & 1 deletion docs/templatetags/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_all_doc_versions(context, url=None):

# Save the versions into the context
versions = sorted(get_version_tuple(x) for x in versions if x != "dev")
return [str(x) for x in versions] + ["dev"]
return [".".join([str(part) for part in x]) for x in versions] + ["dev"]


class PygmentsNode(template.Node):
Expand Down
14 changes: 12 additions & 2 deletions docs/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import os
import shutil
import tempfile
from http import HTTPStatus
from operator import attrgetter
from pathlib import Path
Expand Down Expand Up @@ -195,9 +197,17 @@ def test_empty_get(self):
class TemplateTagTests(TestCase):
fixtures = ["doc_test_fixtures"]

def test_get_all_doc_versions(self):
def test_get_all_doc_versions_empty(self):
with self.assertNumQueries(1):
get_all_doc_versions({})
self.assertEqual(get_all_doc_versions({}), ["dev"])

def test_get_all_doc_versions(self):
tmp_docs_build_root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, tmp_docs_build_root)
os.makedirs(tmp_docs_build_root.joinpath("en", "1.8", "_built", "json"))
os.makedirs(tmp_docs_build_root.joinpath("en", "1.11", "_built", "json"))
with self.settings(DOCS_BUILD_ROOT=tmp_docs_build_root):
self.assertEqual(get_all_doc_versions({}), ["1.8", "1.11", "dev"])

def test_pygments_template_tag(self):
template = Template(
Expand Down

0 comments on commit b15ab7d

Please sign in to comment.