From 7e6ff69c00119f5bd5977bc4b5a561fe606e15e4 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Fri, 26 May 2017 09:15:45 -0400 Subject: [PATCH] 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 --- integrations/api_team_test.go | 38 +++++++++++++++++++++++++++ models/fixtures/user.yml | 48 +++++++++++++++++------------------ routers/api/v1/api.go | 2 +- 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 integrations/api_team_test.go diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go new file mode 100644 index 000000000..543e1579c --- /dev/null +++ b/integrations/api_team_test.go @@ -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) +} diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 1777cff77..dbf991bb8 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 96e3830a2..5dd06c37f 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -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)