Remove session in api tests (#21984)

It's no meaning to request an API route with session.
This commit is contained in:
Lunny Xiao 2022-12-02 11:39:42 +08:00 committed by GitHub
parent 665d02efaf
commit df676a47d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 387 additions and 433 deletions

View file

@ -24,9 +24,8 @@ type apiUserOrgPermTestCase struct {
func TestTokenNeeded(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := emptyTestSession(t)
req := NewRequest(t, "GET", "/api/v1/users/user1/orgs/user6/permissions")
session.MakeRequest(t, req, http.StatusUnauthorized)
MakeRequest(t, req, http.StatusUnauthorized)
}
func sampleTest(t *testing.T, auoptc apiUserOrgPermTestCase) {
@ -36,7 +35,7 @@ func sampleTest(t *testing.T, auoptc apiUserOrgPermTestCase) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/orgs/%s/permissions?token=%s", auoptc.User, auoptc.Organization, token))
resp := session.MakeRequest(t, req, http.StatusOK)
resp := MakeRequest(t, req, http.StatusOK)
var apiOP api.OrganizationPermissions
DecodeJSON(t, resp, &apiOP)
@ -129,7 +128,7 @@ func TestUnknowUser(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/unknow/orgs/org25/permissions?token=%s", token))
resp := session.MakeRequest(t, req, http.StatusNotFound)
resp := MakeRequest(t, req, http.StatusNotFound)
var apiError api.APIError
DecodeJSON(t, resp, &apiError)
@ -143,7 +142,7 @@ func TestUnknowOrganization(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/user1/orgs/unknow/permissions?token=%s", token))
resp := session.MakeRequest(t, req, http.StatusNotFound)
resp := MakeRequest(t, req, http.StatusNotFound)
var apiError api.APIError
DecodeJSON(t, resp, &apiError)
assert.Equal(t, "GetUserByName", apiError.Message)