mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-10-30 06:09:26 +01:00
Fix 500 for GET /teams/:id endpoints (#1811)
* Fix 500 for GET /teams/:id endpoints * Integration test for GET /team/:id * Clean up integration test
This commit is contained in:
parent
3611a3e552
commit
7e6ff69c00
3 changed files with 63 additions and 25 deletions
38
integrations/api_team_test.go
Normal file
38
integrations/api_team_test.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package integrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAPITeam(t *testing.T) {
|
||||||
|
prepareTestEnv(t)
|
||||||
|
teamUser := models.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
|
||||||
|
team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
|
||||||
|
user := models.AssertExistsAndLoadBean(t, &models.User{ID: teamUser.UID}).(*models.User)
|
||||||
|
|
||||||
|
session := loginUser(t, user.Name, "password")
|
||||||
|
url := fmt.Sprintf("/api/v1/teams/%d", teamUser.TeamID)
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
resp := session.MakeRequest(t, req)
|
||||||
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||||||
|
|
||||||
|
var apiTeam api.Team
|
||||||
|
decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
|
||||||
|
assert.NoError(t, decoder.Decode(&apiTeam))
|
||||||
|
assert.EqualValues(t, team.ID, apiTeam.ID)
|
||||||
|
assert.Equal(t, team.Name, apiTeam.Name)
|
||||||
|
}
|
|
@ -36,9 +36,9 @@
|
||||||
name: user3
|
name: user3
|
||||||
full_name: User Three
|
full_name: User Three
|
||||||
email: user3@example.com
|
email: user3@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 1 # organization
|
type: 1 # organization
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar3
|
avatar: avatar3
|
||||||
avatar_email: user3@example.com
|
avatar_email: user3@example.com
|
||||||
|
@ -52,9 +52,9 @@
|
||||||
name: user4
|
name: user4
|
||||||
full_name: User Four
|
full_name: User Four
|
||||||
email: user4@example.com
|
email: user4@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar4
|
avatar: avatar4
|
||||||
avatar_email: user4@example.com
|
avatar_email: user4@example.com
|
||||||
|
@ -67,9 +67,9 @@
|
||||||
name: user5
|
name: user5
|
||||||
full_name: User Five
|
full_name: User Five
|
||||||
email: user5@example.com
|
email: user5@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar5
|
avatar: avatar5
|
||||||
avatar_email: user5@example.com
|
avatar_email: user5@example.com
|
||||||
|
@ -84,9 +84,9 @@
|
||||||
name: user6
|
name: user6
|
||||||
full_name: User Six
|
full_name: User Six
|
||||||
email: user6@example.com
|
email: user6@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 1 # organization
|
type: 1 # organization
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar6
|
avatar: avatar6
|
||||||
avatar_email: user6@example.com
|
avatar_email: user6@example.com
|
||||||
|
@ -100,9 +100,9 @@
|
||||||
name: user7
|
name: user7
|
||||||
full_name: User Seven
|
full_name: User Seven
|
||||||
email: user7@example.com
|
email: user7@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 1 # organization
|
type: 1 # organization
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar7
|
avatar: avatar7
|
||||||
avatar_email: user7@example.com
|
avatar_email: user7@example.com
|
||||||
|
@ -116,9 +116,9 @@
|
||||||
name: user8
|
name: user8
|
||||||
full_name: User Eight
|
full_name: User Eight
|
||||||
email: user8@example.com
|
email: user8@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar8
|
avatar: avatar8
|
||||||
avatar_email: user8@example.com
|
avatar_email: user8@example.com
|
||||||
|
@ -133,9 +133,9 @@
|
||||||
name: user9
|
name: user9
|
||||||
full_name: User Nine
|
full_name: User Nine
|
||||||
email: user9@example.com
|
email: user9@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar9
|
avatar: avatar9
|
||||||
avatar_email: user9@example.com
|
avatar_email: user9@example.com
|
||||||
|
@ -148,9 +148,9 @@
|
||||||
name: user10
|
name: user10
|
||||||
full_name: User Ten
|
full_name: User Ten
|
||||||
email: user10@example.com
|
email: user10@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar10
|
avatar: avatar10
|
||||||
avatar_email: user10@example.com
|
avatar_email: user10@example.com
|
||||||
|
@ -163,9 +163,9 @@
|
||||||
name: user11
|
name: user11
|
||||||
full_name: User Eleven
|
full_name: User Eleven
|
||||||
email: user11@example.com
|
email: user11@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar11
|
avatar: avatar11
|
||||||
avatar_email: user11@example.com
|
avatar_email: user11@example.com
|
||||||
|
@ -178,9 +178,9 @@
|
||||||
name: user12
|
name: user12
|
||||||
full_name: User 12
|
full_name: User 12
|
||||||
email: user12@example.com
|
email: user12@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar12
|
avatar: avatar12
|
||||||
avatar_email: user12@example.com
|
avatar_email: user12@example.com
|
||||||
|
@ -193,9 +193,9 @@
|
||||||
name: user13
|
name: user13
|
||||||
full_name: User 13
|
full_name: User 13
|
||||||
email: user13@example.com
|
email: user13@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar13
|
avatar: avatar13
|
||||||
avatar_email: user13@example.com
|
avatar_email: user13@example.com
|
||||||
|
@ -208,9 +208,9 @@
|
||||||
name: user14
|
name: user14
|
||||||
full_name: User 14
|
full_name: User 14
|
||||||
email: user14@example.com
|
email: user14@example.com
|
||||||
passwd: password
|
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
|
||||||
type: 0 # individual
|
type: 0 # individual
|
||||||
salt: salt
|
salt: ZogKvWdyEx
|
||||||
is_admin: false
|
is_admin: false
|
||||||
avatar: avatar14
|
avatar: avatar14
|
||||||
avatar_email: user13@example.com
|
avatar_email: user13@example.com
|
||||||
|
|
|
@ -490,7 +490,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
Put(org.AddTeamRepository).
|
Put(org.AddTeamRepository).
|
||||||
Delete(org.RemoveTeamRepository)
|
Delete(org.RemoveTeamRepository)
|
||||||
})
|
})
|
||||||
}, reqOrgMembership(), orgAssignment(false, true))
|
}, orgAssignment(false, true), reqOrgMembership())
|
||||||
|
|
||||||
m.Any("/*", func(ctx *context.Context) {
|
m.Any("/*", func(ctx *context.Context) {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
|
|
Loading…
Reference in a new issue