Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 500 for GET /teams/:id endpoints #1811

Merged
merged 3 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (
"encoding/json"
"bytes"
"fmt"
"net/http"
"testing"

api "code.gitea.io/sdk/gitea"
"code.gitea.io/gitea/models"

"github.com/stretchr/testify/assert"
)

func TestAPITeam(t *testing.T) {
assert.NoError(t, models.LoadFixtures())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepareTestEnv is better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

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: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar3
avatar_email: [email protected]
Expand All @@ -52,9 +52,9 @@
name: user4
full_name: User Four
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar4
avatar_email: [email protected]
Expand All @@ -67,9 +67,9 @@
name: user5
full_name: User Five
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar5
avatar_email: [email protected]
Expand All @@ -84,9 +84,9 @@
name: user6
full_name: User Six
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar6
avatar_email: [email protected]
Expand All @@ -100,9 +100,9 @@
name: user7
full_name: User Seven
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 1 # organization
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar7
avatar_email: [email protected]
Expand All @@ -116,9 +116,9 @@
name: user8
full_name: User Eight
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar8
avatar_email: [email protected]
Expand All @@ -133,9 +133,9 @@
name: user9
full_name: User Nine
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar9
avatar_email: [email protected]
Expand All @@ -148,9 +148,9 @@
name: user10
full_name: User Ten
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar10
avatar_email: [email protected]
Expand All @@ -163,9 +163,9 @@
name: user11
full_name: User Eleven
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar11
avatar_email: [email protected]
Expand All @@ -178,9 +178,9 @@
name: user12
full_name: User 12
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar12
avatar_email: [email protected]
Expand All @@ -193,9 +193,9 @@
name: user13
full_name: User 13
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar13
avatar_email: [email protected]
Expand All @@ -208,9 +208,9 @@
name: user14
full_name: User 14
email: [email protected]
passwd: password
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
type: 0 # individual
salt: salt
salt: ZogKvWdyEx
is_admin: false
avatar: avatar14
avatar_email: [email protected]
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