Skip to content

Commit 033aaf4

Browse files
typelessappleboy
authored andcommitted
Add pull-create integration test (#1972)
1 parent 2691673 commit 033aaf4

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

integrations/pull_create_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"bytes"
9+
"net/http"
10+
"net/url"
11+
"path"
12+
"testing"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) {
18+
req := NewRequest(t, "GET", path.Join(user, repo))
19+
resp := session.MakeRequest(t, req)
20+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21+
22+
// Click the little green button to craete a pull
23+
htmlDoc, err := NewHtmlParser(resp.Body)
24+
assert.NoError(t, err)
25+
link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
26+
assert.True(t, exists, "The template has changed")
27+
28+
req = NewRequest(t, "GET", link)
29+
resp = session.MakeRequest(t, req)
30+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
31+
32+
// Submit the form for creating the pull
33+
htmlDoc, err = NewHtmlParser(resp.Body)
34+
assert.NoError(t, err)
35+
link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
36+
assert.True(t, exists, "The template has changed")
37+
req = NewRequestBody(t, "POST", link,
38+
bytes.NewBufferString(url.Values{
39+
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
40+
"title": []string{"This is a pull title"},
41+
}.Encode()),
42+
)
43+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
44+
resp = session.MakeRequest(t, req)
45+
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
46+
47+
//TODO check the redirected URL
48+
}
49+
50+
func TestPullCreate(t *testing.T) {
51+
prepareTestEnv(t)
52+
session := loginUser(t, "user1", "password")
53+
testRepoFork(t, session)
54+
testEditFile(t, session, "user1", "repo1", "master", "README.md")
55+
testPullCreate(t, session, "user1", "repo1", "master")
56+
}

0 commit comments

Comments
 (0)