當前位置: 首頁>>代碼示例>>Golang>>正文


Golang account.Team類代碼示例

本文整理匯總了Golang中github.com/apihub/apihub/account.Team的典型用法代碼示例。如果您正苦於以下問題:Golang Team類的具體用法?Golang Team怎麽用?Golang Team使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Team類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestAppInfoNotMember

func (s *S) TestAppInfoNotMember(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	t := account.Team{Name: "example"}
	t.Create(alice)
	app.Create(alice, t)

	defer func() {
		ap, _ := s.store.FindAppByClientId(app.ClientId)
		s.store.DeleteApp(ap)
		s.store.DeleteTeamByAlias(t.Alias)
		alice.Delete()
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusForbidden,
		Method:         "GET",
		Path:           fmt.Sprintf("/api/apps/%s", app.ClientId),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:25,代碼來源:apps_test.go

示例2: TestUpdateServiceNotMember

func (s *S) TestUpdateServiceNotMember(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	t := account.Team{Name: "example"}
	t.Create(alice)
	service.Create(alice, t)
	defer func() {
		serv, _ := s.store.FindServiceBySubdomain(service.Subdomain)
		s.store.DeleteService(serv)
		s.store.DeleteTeamByAlias(t.Alias)
		alice.Delete()
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusOK,
		Method:         "PUT",
		Path:           fmt.Sprintf("/api/services/%s", service.Subdomain),
		Body:           `{}`,
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:25,代碼來源:services_test.go

示例3: TestRemoveUserWithoutSignIn

func (s *S) TestRemoveUserWithoutSignIn(c *C) {
	team := account.Team{Name: "ApiHub Team", Alias: "apihub"}
	team.Create(user)
	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	testWithoutSignIn(requests.Args{
		AcceptableCode: http.StatusUnauthorized,
		Method:         "DELETE",
		Path:           fmt.Sprintf("/api/teams/%s/users", team.Alias),
		Body:           `{"users": ["[email protected]"]}`},
		c)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:14,代碼來源:teams_test.go

示例4: teamCreate

func (api *Api) teamCreate(rw http.ResponseWriter, r *http.Request, user *account.User) {
	team := account.Team{}
	if err := json.NewDecoder(r.Body).Decode(&team); err != nil {
		handleError(rw, errors.ErrBadRequest)
		return
	}

	if err := team.Create(*user); err != nil {
		handleError(rw, err)
		return
	}

	Created(rw, team)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:14,代碼來源:teams.go

示例5: TestDeleteTeam

func (s *S) TestDeleteTeam(c *C) {
	team := account.Team{Name: "ApiHub Team", Alias: "apihub"}
	team.Create(user)

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusOK,
		Method:         "DELETE",
		Path:           fmt.Sprintf("/api/teams/%s", team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusOK)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, fmt.Sprintf(`{"name":"%s","alias":"%s","users":["%s"],"owner":"%s"}`, team.Name, team.Alias, user.Email, user.Email))
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:15,代碼來源:teams_test.go

示例6: TestCreateTeamWhenAlreadyExists

func (s *S) TestCreateTeamWhenAlreadyExists(c *C) {
	team := account.Team{Name: "ApiHub Team", Alias: "apihub"}
	team.Create(user)

	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusBadRequest,
		Method:         "POST",
		Path:           "/api/teams",
		Body:           fmt.Sprintf(`{"name": "ApiHub Team", "alias": "%s"}`, team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusBadRequest)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"bad_request","error_description":"Someone already has that team alias. Could you try another?"}`)

}
開發者ID:sinzone,項目名稱:apihub,代碼行數:21,代碼來源:teams_test.go

示例7: TestTeamInfoWithoutPermission

func (s *S) TestTeamInfoWithoutPermission(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	defer alice.Delete()

	team := account.Team{Name: "ApiHub Team", Alias: "apihub"}
	team.Create(alice)
	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusForbidden,
		Method:         "GET",
		Path:           fmt.Sprintf("/api/teams/%s", team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:22,代碼來源:teams_test.go

示例8: TestRemoveUser

func (s *S) TestRemoveUser(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	defer alice.Delete()

	team := account.Team{Name: "ApiHub Team", Alias: "apihub", Users: []string{alice.Email}}
	team.Create(user)
	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusOK,
		Method:         "DELETE",
		Path:           fmt.Sprintf("/api/teams/%s/users", team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
		Body:           fmt.Sprintf(`{"users": ["%s"]}`, alice.Email),
	})

	c.Assert(code, Equals, http.StatusOK)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"name":"ApiHub Team","alias":"apihub","users":["[email protected]"],"owner":"[email protected]"}`)
}
開發者ID:sinzone,項目名稱:apihub,代碼行數:23,代碼來源:teams_test.go


注:本文中的github.com/apihub/apihub/account.Team類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。