diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-08-31 01:09:37 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-08-31 15:53:33 +0200 |
| commit | 284f3972844ea124c0cd9ee5500e99440bb96aac (patch) | |
| tree | b8dee22222c38b12cc00daf98280e1b2060bcca7 /tests/commit_page_test.py | |
| parent | b06dbf67b9ac9e329922d7911ee7a9b09419c5f0 (diff) | |
| download | git2hugo-284f3972844ea124c0cd9ee5500e99440bb96aac.tar.gz | |
g2h: Add file page
Also move helpers to dedicated files.
Diffstat (limited to 'tests/commit_page_test.py')
| -rw-r--r-- | tests/commit_page_test.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/commit_page_test.py b/tests/commit_page_test.py new file mode 100644 index 0000000..839d493 --- /dev/null +++ b/tests/commit_page_test.py @@ -0,0 +1,37 @@ +from g2h.commit_page import CommitPage, redact_email +from unittest.mock import MagicMock + +def test_init(): + commit = MagicMock() + commit.hexsha = '123' + page = CommitPage('test/commit', 'commit test', commit, '') + assert(page.name == 'commit test') + assert(page.out_file_path == 'test/commit/123/_index.md') + assert(page.template.name == 'commit.md') + +def test_context(): + commit = MagicMock() + commit.hexsha = '123' + commit.author.email = 'unit@te.st' + page = CommitPage('test/commit', 'commit test', commit, 'commit/content') + context = page.context() + assert(context['title'] == 'commit test: 123') + assert(context['commit'] == commit) + assert(context['redacted_email'] == 'u...t@te...st') + assert(context['content_subdir'] == 'commit/content') + +def test_redacting_email(): + assert(redact_email(None) == '') + assert(redact_email('') == '') + assert(redact_email('a') == 'a...a') + assert(redact_email('az') == 'a...z') + assert(redact_email('root') == 'r...t') + assert(redact_email('root@localhost') == 'r...t@localhost') + assert(redact_email('test@example.com') == 't...t@example...com') + assert(redact_email('test@sub.example.com') == 't...t@sub...example...com') + assert(redact_email('az@example.com') == 'a...z@example...com') + assert(redact_email('a@example.com') == 'a...a@example...com') + assert(redact_email('@example.com') == '@example...com') + assert(redact_email('test@') == 't...t@') + assert(redact_email('az@') == 'a...z@') + assert(redact_email('@') == '@') |