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. "strings"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
  13. req := NewRequest(t, "GET", path.Join(user, repo))
  14. resp := session.MakeRequest(t, req, http.StatusOK)
  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.tiny.compact.button").Parent().Attr("href")
  18. assert.True(t, exists, "The template has changed")
  19. if branch != "master" {
  20. link = strings.Replace(link, ":master", ":"+branch, 1)
  21. }
  22. req = NewRequest(t, "GET", link)
  23. resp = session.MakeRequest(t, req, http.StatusOK)
  24. // Submit the form for creating the pull
  25. htmlDoc = NewHTMLParser(t, resp.Body)
  26. link, exists = htmlDoc.doc.Find("form.ui.form").Attr("action")
  27. assert.True(t, exists, "The template has changed")
  28. req = NewRequestWithValues(t, "POST", link, map[string]string{
  29. "_csrf": htmlDoc.GetCSRF(),
  30. "title": "This is a pull title",
  31. })
  32. resp = session.MakeRequest(t, req, http.StatusFound)
  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, "user2", "repo1", "user1", "repo1")
  40. testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
  41. testPullCreate(t, session, "user1", "repo1", "master")
  42. }