-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest_git.py
executable file
·273 lines (243 loc) · 10.6 KB
/
test_git.py
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env python3
#
# Copyright 2017 Red Hat, Inc.
#
# Authors:
# Fam Zheng <[email protected]>
#
# This work is licensed under the MIT License. Please see the LICENSE file or
# http://opensource.org/licenses/MIT.
import os.path
import shutil
from api.models import Message, Result
from .patchewtest import PatchewTestCase, main
class GitTest(PatchewTestCase):
def setUp(self):
self.create_superuser()
self.cli_login()
self.repo = self.create_git_repo()
self.p = self.add_project("QEMU", "[email protected]", git_repo=self.repo)
self.p.config = {
"git": {
"push_to": self.repo,
"public_repo": self.repo,
"url_template": self.repo + " %t",
}
}
self.p.save()
self.PROJECT_BASE = "%sprojects/%d/" % (self.REST_BASE, self.p.id)
def cleanUp(self):
shutil.rmtree(self.repo)
def test_need_apply(self):
self.cli_import("0001-simple-patch.mbox.gz")
s = Message.objects.series_heads()[0]
self.assertEqual(s.is_complete, True)
self.assertEqual(s.git_result.status, Result.PENDING)
self.do_apply()
def test_need_apply_multiple(self):
self.cli_import("0004-multiple-patch-reviewed.mbox.gz")
s = Message.objects.series_heads()[0]
self.assertEqual(s.is_complete, True)
self.assertEqual(s.git_result.status, Result.PENDING)
self.do_apply()
def test_need_apply_incomplete(self):
self.cli_import("0012-incomplete-series.mbox.gz")
s = Message.objects.series_heads()[0]
self.assertEqual(s.is_complete, False)
self.assertEqual(s.git_result is None, True)
def test_apply(self):
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply()
s = Message.objects.series_heads()[0]
self.assertEqual(s.is_complete, True)
self.assertEqual(s.git_result.data["repo"], self.repo)
self.assertEqual(
s.git_result.data["tag"],
"refs/tags/patchew/[email protected]",
)
self.assertEqual(
s.git_result.data["url"],
self.repo + " patchew/[email protected]",
)
def test_apply_with_base(self):
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply()
self.cli_import("0014-bar-patch.mbox.gz")
self.do_apply()
s = Message.objects.series_heads().filter(
message_id="[email protected]"
)[0]
self.assertEqual(s.is_complete, True)
self.assertEqual(s.git_result.data["repo"], self.repo)
self.assertEqual(
s.git_result.data["tag"],
"refs/tags/patchew/[email protected]",
)
self.assertEqual(
s.git_result.data["url"],
self.repo + " patchew/[email protected]",
)
def test_apply_with_base_and_brackets(self):
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply()
self.cli_import("0015-bar-patch-with-brackets.mbox.gz")
self.do_apply()
s = Message.objects.series_heads().filter(
message_id="[email protected]"
)[0]
self.assertEqual(s.is_complete, True)
self.assertEqual(s.git_result.data["repo"], self.repo)
self.assertEqual(
s.git_result.data["tag"],
"refs/tags/patchew/[email protected]",
)
self.assertEqual(
s.git_result.data["url"],
self.repo + " patchew/[email protected]",
)
def test_rest_need_apply(self):
self.cli_import("0013-foo-patch.mbox.gz")
MESSAGE_ID = "[email protected]"
resp = self.api_client.get(
"%sseries/%s/results/git/" % (self.PROJECT_BASE, MESSAGE_ID)
)
self.assertEqual(resp.data["status"], "pending")
self.assertEqual(resp.data["log_url"], None)
self.assertEqual(resp.data["log"], None)
def test_rest_git_base(self):
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply()
self.cli_import("0014-bar-patch.mbox.gz")
MESSAGE_ID = "[email protected]"
resp = self.api_client.get("%sseries/%s/" % (self.PROJECT_BASE, MESSAGE_ID))
self.assertEqual(resp.data["is_complete"], True)
self.assertEqual(resp.data["based_on"]["repo"], self.repo)
self.assertEqual(
resp.data["based_on"]["tag"],
"refs/tags/patchew/[email protected]",
)
def test_rest_apply_failure(self):
self.cli_import("0014-bar-patch.mbox.gz")
self.do_apply()
MESSAGE_ID = "[email protected]"
resp = self.api_client.get("%sseries/%s/" % (self.PROJECT_BASE, MESSAGE_ID))
self.assertEqual(resp.data["is_complete"], True)
resp = self.api_client.get(
"%sseries/%s/results/" % (self.PROJECT_BASE, MESSAGE_ID)
)
self.assertEqual(resp.data["results"][0]["name"], "git")
self.assertEqual("log" in resp.data["results"][0], False)
self.assertEqual("log_url" in resp.data["results"][0], True)
resp = self.api_client.get(
"%sseries/%s/results/git/" % (self.PROJECT_BASE, MESSAGE_ID)
)
self.assertEqual(resp.data["status"], "failure")
self.assertEqual("repo" in resp.data, False)
self.assertEqual("tag" in resp.data, False)
log = self.client.get(resp.data["log_url"])
self.assertEqual(log.status_code, 200)
self.assertEqual(log.content.decode(), resp.data["log"])
def test_rest_apply_success(self):
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply()
MESSAGE_ID = "[email protected]"
resp = self.api_client.get("%sseries/%s/" % (self.PROJECT_BASE, MESSAGE_ID))
self.assertEqual(resp.data["is_complete"], True)
resp = self.api_client.get(
"%sseries/%s/results/git/" % (self.PROJECT_BASE, MESSAGE_ID)
)
self.assertEqual(resp.data["status"], "success")
self.assertEqual(resp.data["data"]["repo"], self.repo)
self.assertEqual(
resp.data["data"]["tag"],
"refs/tags/patchew/[email protected]",
)
log = self.client.get(resp.data["log_url"])
self.assertEqual(log.status_code, 200)
self.assertEqual(log.content.decode(), resp.data["log"])
def test_result_data_automatic_url(self):
self.cli_import("0001-simple-patch.mbox.gz")
self.api_client.login(username=self.user, password=self.password)
resp = self.api_client.put(
self.PROJECT_BASE
+ "series/[email protected]/results/git/",
{
"status": "success",
"data": {
"repo": self.repo,
"tag": "refs/tags/patchew/[email protected]",
},
},
format="json",
)
resp = self.api_client.get(
self.PROJECT_BASE
+ "series/[email protected]/results/git/"
)
self.assertIn("url", resp.data["data"])
def test_rest_unapplied_target_repo(self):
self.cli_import("0004-multiple-patch-reviewed.mbox.gz")
self.cli_import("0001-simple-patch.mbox.gz")
self.api_login()
self.api_client.put(
self.PROJECT_BASE
+ "series/[email protected]/results/git/",
{"status": "success"},
)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/?target_repo=blah")
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 0)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/?target_repo=" + os.path.dirname(self.repo))
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 1)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/?target_repo=" + os.path.dirname(self.repo) + '/')
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 1)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/?target_repo=" + self.repo)
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 1)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/?target_repo=" + self.repo + '/blah')
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 0)
def test_rest_unapplied(self):
self.cli_import("0004-multiple-patch-reviewed.mbox.gz")
self.cli_import("0001-simple-patch.mbox.gz")
self.api_client.login(username=self.user, password=self.password)
self.api_client.put(
self.PROJECT_BASE
+ "series/[email protected]/results/git/",
{"status": "success"},
)
resp = self.api_client.get(self.REST_BASE + "series/unapplied/")
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 1)
self.assertEquals(
resp.data["results"][0]["message_id"],
)
self.do_apply()
resp = self.api_client.get(self.REST_BASE + "series/unapplied/")
self.assertEqual(resp.status_code, 200)
self.assertEquals(len(resp.data["results"]), 0)
def test_git_push_options(self):
self.p.config["git"]["use_git_push_option"] = True
self.p.save()
self.cli_import("0013-foo-patch.mbox.gz")
out, err = self.do_apply(True)
self.assertNotIn("ci.skip", out)
# Getting a new reviewed-by shouldn't trigger re-test
self.cli_import("0025-foo-patch-review.mbox.gz")
out, err = self.do_apply(True)
self.assertIn("ci.skip", out)
def test_no_update_series_on_tags(self):
# No need to test the opposite (default value), implicitly tested before
self.p.config["git"]["update_series_on_tags"] = False
self.p.save()
self.cli_import("0013-foo-patch.mbox.gz")
self.do_apply(True)
# Getting a new reviewed-by shouldn't trigger re-push
self.cli_import("0025-foo-patch-review.mbox.gz")
out, err = self.do_apply(True)
self.assertIn("No series need apply", out)
if __name__ == "__main__":
main()