Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

pull_create_test.go 1.6KB

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