Remove session in api tests (#21984)
It's no meaning to request an API route with session.
This commit is contained in:
parent
665d02efaf
commit
df676a47d0
46 changed files with 387 additions and 433 deletions
|
@ -154,7 +154,6 @@ func TestAPICreateFile(t *testing.T) {
|
|||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
|
||||
// Test creating a file in repo1 which user2 owns, try both with branch and empty branch
|
||||
for _, branch := range [...]string{
|
||||
|
@ -167,7 +166,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath := fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
|
||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||
|
@ -194,7 +193,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath := fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var fileResponse api.FileResponse
|
||||
DecodeJSON(t, resp, &fileResponse)
|
||||
expectedSHA := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
|
||||
|
@ -212,7 +211,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp = MakeRequest(t, req, http.StatusCreated)
|
||||
DecodeJSON(t, resp, &fileResponse)
|
||||
expectedMessage := "Add '" + treePath + "'\n"
|
||||
assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
|
||||
|
@ -222,7 +221,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = "README.md"
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
expectedAPIError := context.APIError{
|
||||
Message: "repository file already exists [path: " + treePath + "]",
|
||||
URL: setting.API.SwaggerURL,
|
||||
|
@ -237,7 +236,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Tests a repo with no token given so will fail
|
||||
createFileOptions = getCreateFileOptions()
|
||||
|
@ -245,7 +244,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test using access token for a private repo that the user of the token owns
|
||||
createFileOptions = getCreateFileOptions()
|
||||
|
@ -253,7 +252,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token2)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusCreated)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// Test using org repo "user3/repo3" where user2 is a collaborator
|
||||
createFileOptions = getCreateFileOptions()
|
||||
|
@ -261,7 +260,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusCreated)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// Test using org repo "user3/repo3" with no user token
|
||||
createFileOptions = getCreateFileOptions()
|
||||
|
@ -269,7 +268,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user3.Name, repo3.Name, treePath)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test using repo "user2/repo1" where user4 is a NOT collaborator
|
||||
createFileOptions = getCreateFileOptions()
|
||||
|
@ -277,7 +276,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token4)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
// Test creating a file in an empty repository
|
||||
doAPICreateRepository(NewAPITestContext(t, "user2", "empty-repo"), true)(t)
|
||||
|
@ -286,7 +285,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, "empty-repo", treePath, token2)
|
||||
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
|
||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp = MakeRequest(t, req, http.StatusCreated)
|
||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
|
||||
gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
|
||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue