mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(fastapi): add configurable commit hash display
Two new options have been added: - [devel] commit_url - URL including an %s format specifier that can be used to link to a webpage for the commit. - [devel] commit_hash - HEAD's commit hash (produced via `git rev-parse HEAD`) If a `[devel] commit_hash` is configured, a link to the commit based on `[devel] commit_url` will be displayed in the aurweb footer in the form: `HEAD@<commit_hash>`. If no `[devel] commit_url` is configured, a non-linked hash will be displayed. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
da55aa6491
commit
0d734eb07d
6 changed files with 82 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from aurweb import config, templates
|
||||
from aurweb.templates import register_filter, register_function
|
||||
from aurweb.testing.requests import Request
|
||||
|
||||
|
||||
@register_filter("func")
|
||||
|
@ -29,3 +31,42 @@ def test_register_function_exists_key_error():
|
|||
@register_function("function")
|
||||
def some_func():
|
||||
pass
|
||||
|
||||
|
||||
def test_commit_hash():
|
||||
# Hashes we'll use for this test. long_commit_hash should be
|
||||
# shortened to commit_hash for rendering.
|
||||
commit_hash = "abcdefg"
|
||||
long_commit_hash = commit_hash + "1234567"
|
||||
|
||||
def config_get_with_fallback(section: str, option: str,
|
||||
fallback: str = None) -> str:
|
||||
if section == "devel" and option == "commit_hash":
|
||||
return long_commit_hash
|
||||
return config.original_get_with_fallback(section, option, fallback)
|
||||
|
||||
# Fake config.get_with_fallback.
|
||||
config.original_get_with_fallback = config.get_with_fallback
|
||||
config.get_with_fallback = config_get_with_fallback
|
||||
|
||||
request = Request()
|
||||
context = templates.make_context(request, "Test Context")
|
||||
render = templates.render_raw_template(request, "index.html", context)
|
||||
|
||||
# We've faked config.get_with_fallback to return a "valid" commit_hash
|
||||
# when queried. Test that the expected render occurs.
|
||||
commit_url = config.get("devel", "commit_url")
|
||||
expected = commit_url % commit_hash
|
||||
assert expected in render
|
||||
assert f"HEAD@{commit_hash}" in render
|
||||
assert long_commit_hash not in render
|
||||
|
||||
# Restore config.get_with_fallback.
|
||||
config.get_with_fallback = config.original_get_with_fallback
|
||||
config.original_get_with_fallback = None
|
||||
|
||||
# Now, we no longer fake the commit_hash option: no commit
|
||||
# is displayed in the footer. Assert this expectation.
|
||||
context = templates.make_context(request, "Test Context")
|
||||
render = templates.render_raw_template(request, "index.html", context)
|
||||
assert commit_hash not in render
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue