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

52 lines
1.6 KiB

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