1
0
Fork 0
forked from forgejo/forgejo

Consolidate boilerplate in integration tests (#1979)

This commit is contained in:
Ethan Koenig 2017-06-17 00:49:45 -04:00 committed by Lunny Xiao
parent a3868ef536
commit ce9b86082c
16 changed files with 147 additions and 166 deletions

View file

@ -5,9 +5,7 @@
package integrations
import (
"bytes"
"net/http"
"net/url"
"path"
"testing"
@ -20,8 +18,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
// Click the little green button to create a pull
htmlDoc, err := NewHtmlParser(resp.Body)
assert.NoError(t, err)
htmlDoc := NewHtmlParser(t, resp.Body)
link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
assert.True(t, exists, "The template has changed")
@ -30,16 +27,13 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
// Submit the form for creating the pull
htmlDoc, err = NewHtmlParser(resp.Body)
assert.NoError(t, err)
htmlDoc = NewHtmlParser(t, resp.Body)
link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
assert.True(t, exists, "The template has changed")
req = NewRequestBody(t, "POST", link,
bytes.NewBufferString(url.Values{
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
"title": []string{"This is a pull title"},
}.Encode()),
)
req = NewRequestWithValues(t, "POST", link, map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"title": "This is a pull title",
})
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
@ -51,7 +45,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
func TestPullCreate(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user1", "password")
session := loginUser(t, "user1")
testRepoFork(t, session)
testEditFile(t, session, "user1", "repo1", "master", "README.md")
testPullCreate(t, session, "user1", "repo1", "master")