func (s *S) TestFindTeamByAlias(c *C) { err := team.Create(owner) t, err := account.FindTeamByAlias(team.Alias) c.Check(t, Not(IsNil)) c.Check(err, IsNil) defer team.Delete(owner) }
func (s *S) TestRemoveUsers(c *C) { team.Create(owner) alice.Create() err := team.AddUsers([]string{alice.Email}) c.Check(err, IsNil) t, err := account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 2) err = team.RemoveUsers([]string{alice.Email}) c.Check(err, IsNil) t, err = account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 1) defer alice.Delete() defer team.Delete(owner) }
func (s *S) TestAddUsersWithSameUsername(c *C) { team.Create(owner) err := team.AddUsers([]string{owner.Email}) c.Assert(err, IsNil) t, err := account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 1) defer team.Delete(owner) }
func (s *S) TestAddUsersWithInvalidUser(c *C) { team.Create(owner) err := team.AddUsers([]string{"*****@*****.**"}) c.Assert(err, IsNil) t, err := account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 1) defer team.Delete(owner) }
func findTeamAndCheckUser(alias string, user *account.User) (*account.Team, error) { team, err := account.FindTeamByAlias(alias) if err != nil { return nil, err } if _, err := team.ContainsUser(user); err != nil { return nil, err } return team, nil }
func (s *S) TestRemoveUsersWithInvalidUser(c *C) { team.Create(owner) alice.Create() err := team.RemoveUsers([]string{"*****@*****.**"}) c.Check(err, IsNil) t, err := account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 1) defer alice.Delete() defer team.Delete(owner) }
func (s *S) TestRemoveUsersWhenTheUserIsOwner(c *C) { team.Create(owner) owner.Create() err := team.RemoveUsers([]string{owner.Email}) _, ok := err.(errors.ValidationError) c.Assert(ok, Equals, true) t, err := account.FindTeamByAlias(team.Alias) c.Assert(len(t.Users), Equals, 1) defer team.Delete(owner) defer owner.Delete() }
func (api *Api) teamDelete(rw http.ResponseWriter, r *http.Request, user *account.User) { team, err := account.FindTeamByAlias(mux.Vars(r)["alias"]) if err != nil { handleError(rw, err) return } if err = team.Delete(*user); err != nil { handleError(rw, err) return } Ok(rw, team) }
func (s *S) TestFindTeamByAliasNotFound(c *C) { t, err := account.FindTeamByAlias("not-found") c.Check(t, IsNil) _, ok := err.(errors.NotFoundError) c.Assert(ok, Equals, true) }