blob: b32901e718b51258cd65eed3bf34483352f88950 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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('@') == '@')
|