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.7 kB

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