summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2017-06-08 19:15:41 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-08 19:15:41 +0800
commit662b8bc2a2ae45b720003cf9437c70991781479b (patch)
tree4c0e8de4427f8a41b4b8a896ac8c90a551a1035a /integrations
parentafe1f1c4af079ff564c67552a4e559409712c11b (diff)
downloadgitea-662b8bc2a2ae45b720003cf9437c70991781479b.tar.gz
gitea-662b8bc2a2ae45b720003cf9437c70991781479b.zip
Add integration test for file editing (#1907)
Diffstat (limited to 'integrations')
-rw-r--r--integrations/editor_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/integrations/editor_test.go b/integrations/editor_test.go
index df0cfaa291..976def89eb 100644
--- a/integrations/editor_test.go
+++ b/integrations/editor_test.go
@@ -8,6 +8,7 @@ import (
"bytes"
"net/http"
"net/url"
+ "path"
"testing"
"github.com/stretchr/testify/assert"
@@ -104,3 +105,47 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
// Check body for error message
assert.Contains(t, string(resp.Body), "Can not commit to protected branch &#39;master&#39;.")
}
+
+func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath string) {
+
+ newContent := "Hello, World (Edited)\n"
+
+ // Get to the 'edit this file' page
+ req, err := http.NewRequest("GET", path.Join(user, repo, "_edit", branch, filePath), nil)
+ assert.NoError(t, err)
+ resp := session.MakeRequest(t, req)
+ assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
+
+ htmlDoc, err := NewHtmlParser(resp.Body)
+ assert.NoError(t, err)
+ lastCommit := htmlDoc.GetInputValueByName("last_commit")
+ assert.NotEmpty(t, lastCommit)
+
+ // Submit the edits
+ req, err = http.NewRequest("POST", path.Join(user, repo, "_edit", branch, filePath),
+ bytes.NewBufferString(url.Values{
+ "_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
+ "last_commit": []string{lastCommit},
+ "tree_path": []string{filePath},
+ "content": []string{newContent},
+ "commit_choice": []string{"direct"},
+ }.Encode()),
+ )
+ assert.NoError(t, err)
+ req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
+ resp = session.MakeRequest(t, req)
+ assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
+
+ // Verify the change
+ req, err = http.NewRequest("GET", path.Join(user, repo, "raw", branch, filePath), nil)
+ assert.NoError(t, err)
+ resp = session.MakeRequest(t, req)
+ assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
+ assert.EqualValues(t, newContent, string(resp.Body))
+}
+
+func TestEditFile(t *testing.T) {
+ prepareTestEnv(t)
+ session := loginUser(t, "user2", "password")
+ testEditFile(t, session, "user2", "repo1", "master", "README.md")
+}