Skip to content

Commit

Permalink
Fix 500 for GET /teams/:id endpoints (#1811)
Browse files Browse the repository at this point in the history
* Fix 500 for GET /teams/:id endpoints

* Integration test for GET /team/:id

* Clean up integration test
  • Loading branch information
ethantkoenig authored and appleboy committed May 26, 2017
1 parent 3611a3e commit 7e6ff69
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
38 changes: 38 additions & 0 deletions integrations/api_team_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
48 changes: 24 additions & 24 deletions models/fixtures/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
name: user3
full_name: User Three
email: user3@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar3
avatar_email: user3@example.com
Expand All @@ -52,9 +52,9 @@
name: user4
full_name: User Four
email: user4@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar4
avatar_email: user4@example.com
Expand All @@ -67,9 +67,9 @@
name: user5
full_name: User Five
email: user5@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar5
avatar_email: user5@example.com
Expand All @@ -84,9 +84,9 @@
name: user6
full_name: User Six
email: user6@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar6
avatar_email: user6@example.com
Expand All @@ -100,9 +100,9 @@
name: user7
full_name: User Seven
email: user7@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar7
avatar_email: user7@example.com
Expand All @@ -116,9 +116,9 @@
name: user8
full_name: User Eight
email: user8@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar8
avatar_email: user8@example.com
Expand All @@ -133,9 +133,9 @@
name: user9
full_name: User Nine
email: user9@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar9
avatar_email: user9@example.com
Expand All @@ -148,9 +148,9 @@
name: user10
full_name: User Ten
email: user10@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar10
avatar_email: user10@example.com
Expand All @@ -163,9 +163,9 @@
name: user11
full_name: User Eleven
email: user11@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar11
avatar_email: user11@example.com
Expand All @@ -178,9 +178,9 @@
name: user12
full_name: User 12
email: user12@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar12
avatar_email: user12@example.com
Expand All @@ -193,9 +193,9 @@
name: user13
full_name: User 13
email: user13@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar13
avatar_email: user13@example.com
Expand All @@ -208,9 +208,9 @@
name: user14
full_name: User 14
email: user14@example.com
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar14
avatar_email: user13@example.com
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func RegisterRoutes(m *macaron.Macaron) {
Put(org.AddTeamRepository).
Delete(org.RemoveTeamRepository)
})
}, reqOrgMembership(), orgAssignment(false, true))
}, orgAssignment(false, true), reqOrgMembership())

m.Any("/*", func(ctx *context.Context) {
ctx.Error(404)
Expand Down

0 comments on commit 7e6ff69

Please sign in to comment.