2017-06-15 12:31:51 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-12-04 04:16:01 +05:30
|
|
|
"net/http/httptest"
|
2017-06-15 12:31:51 +05:30
|
|
|
"path"
|
2017-06-21 06:30:03 +05:30
|
|
|
"strings"
|
2017-06-15 12:31:51 +05:30
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-12-04 04:16:01 +05:30
|
|
|
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *httptest.ResponseRecorder {
|
2017-06-15 12:31:51 +05:30
|
|
|
req := NewRequest(t, "GET", path.Join(user, repo))
|
2017-07-08 01:06:47 +05:30
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-15 12:31:51 +05:30
|
|
|
|
2017-06-15 15:08:54 +05:30
|
|
|
// Click the little green button to create a pull
|
2017-06-17 21:59:59 +05:30
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-08-14 04:19:38 +05:30
|
|
|
link, exists := htmlDoc.doc.Find("button.ui.green.tiny.compact.button").Parent().Attr("href")
|
2017-06-15 12:31:51 +05:30
|
|
|
assert.True(t, exists, "The template has changed")
|
2017-06-21 06:30:03 +05:30
|
|
|
if branch != "master" {
|
|
|
|
link = strings.Replace(link, ":master", ":"+branch, 1)
|
|
|
|
}
|
2017-06-15 12:31:51 +05:30
|
|
|
|
|
|
|
req = NewRequest(t, "GET", link)
|
2017-07-08 01:06:47 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2017-06-15 12:31:51 +05:30
|
|
|
|
|
|
|
// Submit the form for creating the pull
|
2017-06-17 21:59:59 +05:30
|
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
2017-06-15 12:31:51 +05:30
|
|
|
link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
2017-06-17 10:19:45 +05:30
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"title": "This is a pull title",
|
|
|
|
})
|
2017-07-08 01:06:47 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
2017-06-15 12:31:51 +05:30
|
|
|
|
2017-06-15 16:50:39 +05:30
|
|
|
return resp
|
2017-06-15 12:31:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullCreate(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
2017-06-17 10:19:45 +05:30
|
|
|
session := loginUser(t, "user1")
|
2017-10-15 20:36:07 +05:30
|
|
|
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
2017-10-16 03:24:53 +05:30
|
|
|
testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
|
2018-01-05 16:26:52 +05:30
|
|
|
resp := testPullCreate(t, session, "user1", "repo1", "master")
|
|
|
|
|
|
|
|
// check the redirected URL
|
|
|
|
url := resp.HeaderMap.Get("Location")
|
|
|
|
assert.Regexp(t, "^/user2/repo1/pulls/[0-9]*$", url)
|
|
|
|
|
|
|
|
// check .diff can be accessed and matches performed change
|
|
|
|
req := NewRequest(t, "GET", url+".diff")
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
assert.Regexp(t, "\\+Hello, World \\(Edited\\)", resp.Body)
|
|
|
|
assert.Regexp(t, "^diff", resp.Body)
|
|
|
|
assert.NotRegexp(t, "diff.*diff", resp.Body) // not two diffs, just one
|
2017-06-15 12:31:51 +05:30
|
|
|
}
|