summaryrefslogtreecommitdiffstats
path: root/tests/log_page_test.py
blob: 041544eaf404a42737fcf7fca5596d0f601e2b1e (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from g2h.log_page import LogPage
from unittest.mock import MagicMock

def test_init():
    page = LogPage('test/log', 'log test', None, None, None, '')
    assert(page.name == 'log test')
    assert(page.out_file_path == 'test/log/l.md')
    assert(page.template.name == 'log.md')

def test_context_no_commits():
    page = LogPage('test/log', 'log test', None, None, None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [])

def test_context_no_branches_and_tags():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    page = LogPage('test/log', 'log test', [commit], None, None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])

def test_context_matching_branch_no_tags():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    branch = MagicMock()
    branch.commit.hexsha = commit.hexsha
    branch.name = 'mock branch'
    page = LogPage('test/log', 'log test', [commit], [branch], None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch'], 'summary': 'mock commit'}])

def test_context_unmatching_branch_no_tags():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    branch = MagicMock()
    branch.commit.hexsha = 4321
    branch.name = 'mock branch'
    page = LogPage('test/log', 'log test', [commit], [branch], None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])

def test_context_no_branch_matching_tag():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    tag = MagicMock()
    tag.commit.hexsha = commit.hexsha
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit], None, [tag], '')
    context = page.context()
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock tag'], 'summary': 'mock commit'}])

def test_context_no_branch_no_matching_tag():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    tag = MagicMock()
    tag.commit.hexsha = 4321
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit], None, [tag], '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])

def test_context_no_matching_branch_no_matching_tag():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    branch = MagicMock()
    branch.commit.hexsha = 321
    branch.name = 'mock branch'
    tag = MagicMock()
    tag.commit.hexsha = 4321
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])

def test_context_matching_branch_matching_tag():
    commit = MagicMock()
    commit.summary = 'mock commit'
    commit.hexsha = 1234;
    commit.committed_datetime = 0
    branch = MagicMock()
    branch.commit.hexsha = commit.hexsha
    branch.name = 'mock branch'
    tag = MagicMock()
    tag.commit.hexsha = commit.hexsha
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}])

def test_multiple_commits():
    commit1 = MagicMock()
    commit1.summary = 'mock commit 1'
    commit1.hexsha = 1;
    commit1.committed_datetime = 0
    commit2 = MagicMock()
    commit2.summary = 'mock commit 2'
    commit2.hexsha = 2;
    commit2.committed_datetime = 1
    page = LogPage('test/log', 'log test', [commit1, commit2], None, None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [
        {'committed_datetime': 0, 'hexsha': 1, 'refs': [], 'summary': 'mock commit 1'},
        {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
    ])

def test_multiple_commits_branch():
    commit1 = MagicMock()
    commit1.summary = 'mock commit 1'
    commit1.hexsha = 1;
    commit1.committed_datetime = 0
    commit2 = MagicMock()
    commit2.summary = 'mock commit 2'
    commit2.hexsha = 2;
    commit2.committed_datetime = 1
    branch = MagicMock()
    branch.commit.hexsha = 1
    branch.name = 'mock branch'
    page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None, '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [
        {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
        {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
    ])

def test_multiple_commits_tag():
    commit1 = MagicMock()
    commit1.summary = 'mock commit 1'
    commit1.hexsha = 1;
    commit1.committed_datetime = 0
    commit2 = MagicMock()
    commit2.summary = 'mock commit 2'
    commit2.hexsha = 2;
    commit2.committed_datetime = 1
    tag = MagicMock()
    tag.commit.hexsha = 1
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag], '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [
        {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock tag'], 'summary': 'mock commit 1'},
        {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
    ])

def test_multiple_commits_branch_and_tag():
    commit1 = MagicMock()
    commit1.summary = 'mock commit 1'
    commit1.hexsha = 1;
    commit1.committed_datetime = 0
    commit2 = MagicMock()
    commit2.summary = 'mock commit 2'
    commit2.hexsha = 2;
    commit2.committed_datetime = 1
    branch = MagicMock()
    branch.commit.hexsha = 1
    branch.name = 'mock branch'
    tag = MagicMock()
    tag.commit.hexsha = 2
    tag.name = 'mock tag'
    page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag], '')
    context = page.context()
    assert(context['title'] == 'log test: Log')
    assert(context['commits'] == [
        {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
        {'committed_datetime': 1, 'hexsha': 2, 'refs': ['mock tag'], 'summary': 'mock commit 2'}
    ])