diff options
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('@') == '@') |