Example #1
0
// TestUpdateTeam tests the ability to updatee an
// existing Team in the database.
func TestUpdateTeam(t *testing.T) {
	Setup()
	defer Teardown()

	// get the user we plan to update
	team, err := database.GetTeam(1)
	if err != nil {
		t.Error(err)
	}

	// update fields
	team.Email = "*****@*****.**"
	team.Gravatar = "61024896f291303615bcd4f7a0dcfb74"

	// update the database
	if err := database.SaveTeam(team); err != nil {
		t.Error(err)
	}

	// get the updated team
	updatedTeam, err := database.GetTeam(1)
	if err != nil {
		t.Error(err)
	}

	// verify the updated fields
	if team.Email != updatedTeam.Email {
		t.Errorf("Exepected Email %s, got %s", team.Email, updatedTeam.Email)
	}

	if team.Gravatar != updatedTeam.Gravatar {
		t.Errorf("Exepected Gravatar %s, got %s", team.Gravatar, updatedTeam.Gravatar)
	}
}
Example #2
0
// Repository Settings
func RepoSettingsForm(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {

	// get the list of teams
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}

	data := struct {
		Repo  *Repo
		User  *User
		Teams []*Team
		Owner *User
		Team  *Team
	}{Repo: repo, User: u, Teams: teams}

	// get the repo owner
	if repo.TeamID > 0 {
		data.Team, err = database.GetTeam(repo.TeamID)
		if err != nil {
			return err
		}
	}

	// get the team owner
	data.Owner, err = database.GetUser(repo.UserID)
	if err != nil {
		return err
	}

	return RenderTemplate(w, "repo_settings.html", &data)
}
Example #3
0
func TeamMemberAccept(w http.ResponseWriter, r *http.Request, u *User) error {
	// get the team name from the token
	token := r.FormValue("token")
	teamToken := authcookie.Login(token, secret)
	teamId, err := strconv.Atoi(teamToken)
	if err != nil || teamId == 0 {
		return ErrInvalidTeamName
	}

	// get the team from the database
	team, err := database.GetTeam(int64(teamId))
	if err != nil {
		return RenderError(w, err, http.StatusNotFound)
	}

	// add the user to the team.
	// by default the user has write access to the team, which means
	// they can add and manage new repositories.
	if err := database.SaveMember(u.ID, team.ID, RoleWrite); err != nil {
		return RenderError(w, err, http.StatusInternalServerError)
	}

	// send the user to the dashboard
	http.Redirect(w, r, "/dashboard/team/"+team.Slug, http.StatusSeeOther)
	return nil
}
Example #4
0
// TestGetTeam tests the ability to retrieve a Team
// from the database by Unique ID.
func TestGetTeam(t *testing.T) {
	Setup()
	defer Teardown()

	team, err := database.GetTeam(1)
	if err != nil {
		t.Error(err)
	}

	if team.ID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, team.ID)
	}

	if team.Name != "Drone" {
		t.Errorf("Exepected Name %s, got %s", "Drone", team.Name)
	}

	if team.Slug != "drone" {
		t.Errorf("Exepected Slug %s, got %s", "drone", team.Slug)
	}

	if team.Email != "*****@*****.**" {
		t.Errorf("Exepected Email %s, got %s", "*****@*****.**", team.Email)
	}

	if team.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" {
		t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", team.Gravatar)
	}
}
Example #5
0
// Test the ability to delete a Team.
func TestDeleteTeam(t *testing.T) {
	Setup()
	defer Teardown()

	// get the team we plan to update
	if err := database.DeleteTeam(1); err != nil {
		t.Error(err)
	}

	// now try to get the team from the database
	_, err := database.GetTeam(1)
	if err == nil {
		t.Fail()
	}
}