You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pull_create_test.go 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. package integrations
  5. import (
  6. "bytes"
  7. "net/http"
  8. "net/url"
  9. "path"
  10. "testing"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
  14. req := NewRequest(t, "GET", path.Join(user, repo))
  15. resp := session.MakeRequest(t, req)
  16. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  17. // Click the little green button to create a pull
  18. htmlDoc, err := NewHtmlParser(resp.Body)
  19. assert.NoError(t, err)
  20. link, exists := htmlDoc.doc.Find("button.ui.green.small.button").Parent().Attr("href")
  21. assert.True(t, exists, "The template has changed")
  22. req = NewRequest(t, "GET", link)
  23. resp = session.MakeRequest(t, req)
  24. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  25. // Submit the form for creating the pull
  26. htmlDoc, err = NewHtmlParser(resp.Body)
  27. assert.NoError(t, err)
  28. link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
  29. assert.True(t, exists, "The template has changed")
  30. req = NewRequestBody(t, "POST", link,
  31. bytes.NewBufferString(url.Values{
  32. "_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
  33. "title": []string{"This is a pull title"},
  34. }.Encode()),
  35. )
  36. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  37. resp = session.MakeRequest(t, req)
  38. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  39. //TODO check the redirected URL
  40. return resp
  41. }
  42. func TestPullCreate(t *testing.T) {
  43. prepareTestEnv(t)
  44. session := loginUser(t, "user1", "password")
  45. testRepoFork(t, session)
  46. testEditFile(t, session, "user1", "repo1", "master", "README.md")
  47. testPullCreate(t, session, "user1", "repo1", "master")
  48. }