0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-04 14:36:16 +02:00

fix more tests

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-11-24 00:09:32 -05:00
parent d9e9d0bf5a
commit 41c1e208b9
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C
5 changed files with 13 additions and 13 deletions

View File

@ -31,7 +31,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
// public only token should be forbidden
publicOnlyToken := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopePublicOnly, auth_model.AccessTokenScopeWriteRepository)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo3.Name)) // a plain repo
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches", maybeGroupSegment(repo3.GroupID), repo3.Name)) // a plain repo
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
@ -45,7 +45,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
assert.Equal(t, "test_branch", branches[0].Name)
assert.Equal(t, "master", branches[1].Name)
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo3.Name))
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch", maybeGroupSegment(repo3.GroupID), repo3.Name))
MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
@ -79,7 +79,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
assert.Equal(t, "test_branch2", branches[1].Name)
assert.Equal(t, "master", branches[2].Name)
link3, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch2", repo3.Name))
link3, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch2", maybeGroupSegment(repo3.GroupID), repo3.Name))
MakeRequest(t, NewRequest(t, "DELETE", link3.String()), http.StatusNotFound)
MakeRequest(t, NewRequest(t, "DELETE", link3.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
@ -96,7 +96,7 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
session := loginUser(t, user1.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo5.Name)) // a mirror repo
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches", maybeGroupSegment(repo5.GroupID), repo5.Name)) // a mirror repo
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
@ -107,7 +107,7 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
assert.Equal(t, "test_branch", branches[0].Name)
assert.Equal(t, "master", branches[1].Name)
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo5.Name))
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch", maybeGroupSegment(repo5.GroupID), repo5.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
assert.NoError(t, err)

View File

@ -398,11 +398,11 @@ func TestAPIRepoEdit(t *testing.T) {
// Test using org repo "org3/repo3" where user2 is a collaborator
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", org3.Name, repo3.Name), &repoEditOption).
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/group/%d/%s", org3.Name, repo3.GroupID, repo3.Name), &repoEditOption).
AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK)
// reset repo in db
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", org3.Name, *repoEditOption.Name), &origRepoEditOption).
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/group/%d/%s", org3.Name, repo3.GroupID, *repoEditOption.Name), &origRepoEditOption).
AddTokenAuth(token2)
_ = MakeRequest(t, req, http.StatusOK)

View File

@ -73,12 +73,12 @@ func TestAPIApplyDiffPatchFileOptions(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
// Test using org repo "org3/repo3" where user2 is a collaborator
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions()).
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/diffpatch", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), getApplyDiffPatchFileOptions()).
AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated)
// Test using org repo "org3/repo3" with no user token
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions())
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/diffpatch", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), getApplyDiffPatchFileOptions())
MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator

View File

@ -122,7 +122,7 @@ func testEditorActionEdit(t *testing.T, session *TestSession, groupID int64, use
params["tree_path"] = util.IfZero(params["tree_path"], filePath)
newBranchName := util.Iif(params["commit_choice"] == "direct", branch, params["new_branch_name"])
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s/%s%s/%s/%s", user, maybeGroupSegment(groupID), repo, editorAction, branch, filePath), params)
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s%s/%s/%s/%s", user, maybeGroupSegment(groupID), repo, editorAction, branch, filePath), params)
assert.Equal(t, http.StatusOK, resp.Code)
assert.NotEmpty(t, test.RedirectURL(resp))
req := NewRequest(t, "GET", path.Join(user, repo, "raw/branch", newBranchName, params["tree_path"]))

View File

@ -445,19 +445,19 @@ func TestIssueRedirect(t *testing.T) {
session := loginUser(t, "user2")
// Test external tracker where style not set (shall default numeric)
req := NewRequest(t, "GET", "/org26/repo_external_tracker/issues/1")
req := NewRequest(t, "GET", "/org26/group/49/repo_external_tracker/issues/1")
resp := session.MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker/issues/1", test.RedirectURL(resp))
// Test external tracker with numeric style
req = NewRequest(t, "GET", "/org26/repo_external_tracker_numeric/issues/1")
req = NewRequest(t, "GET", "/org26/group/53/repo_external_tracker_numeric/issues/1")
resp = session.MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker_numeric/issues/1", test.RedirectURL(resp))
// Test external tracker with alphanumeric style (for a pull request)
req = NewRequest(t, "GET", "/org26/repo_external_tracker_alpha/issues/1")
resp = session.MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "/org26/repo_external_tracker_alpha/pulls/1", test.RedirectURL(resp))
assert.Equal(t, "/org26/group/41/repo_external_tracker_alpha/pulls/1", test.RedirectURL(resp))
// test to check that the PR redirection works if the issue unit is disabled
// repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)