2019-05-30 23:09:05 +08:00
|
|
|
// Copyright 2019 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 repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-19 19:49:59 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-05-30 23:09:05 +08:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
2021-01-26 23:36:53 +08:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2019-05-30 23:09:05 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepoEdit(t *testing.T) {
|
2021-09-19 19:49:59 +08:00
|
|
|
db.PrepareTestEnv(t)
|
2019-05-30 23:09:05 +08:00
|
|
|
|
|
|
|
ctx := test.MockContext(t, "user2/repo1")
|
|
|
|
test.LoadRepo(t, ctx, 1)
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
ctx.Repo.Owner = ctx.User
|
|
|
|
description := "new description"
|
|
|
|
website := "http://wwww.newwebsite.com"
|
|
|
|
private := true
|
|
|
|
hasIssues := false
|
|
|
|
hasWiki := false
|
|
|
|
defaultBranch := "master"
|
|
|
|
hasPullRequests := true
|
|
|
|
ignoreWhitespaceConflicts := true
|
|
|
|
allowMerge := false
|
|
|
|
allowRebase := false
|
|
|
|
allowRebaseMerge := false
|
|
|
|
allowSquashMerge := false
|
|
|
|
archived := true
|
|
|
|
opts := api.EditRepoOption{
|
|
|
|
Name: &ctx.Repo.Repository.Name,
|
|
|
|
Description: &description,
|
|
|
|
Website: &website,
|
|
|
|
Private: &private,
|
|
|
|
HasIssues: &hasIssues,
|
|
|
|
HasWiki: &hasWiki,
|
|
|
|
DefaultBranch: &defaultBranch,
|
|
|
|
HasPullRequests: &hasPullRequests,
|
|
|
|
IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts,
|
|
|
|
AllowMerge: &allowMerge,
|
|
|
|
AllowRebase: &allowRebase,
|
|
|
|
AllowRebaseMerge: &allowRebaseMerge,
|
|
|
|
AllowSquash: &allowSquashMerge,
|
|
|
|
Archived: &archived,
|
|
|
|
}
|
|
|
|
|
2021-01-26 23:36:53 +08:00
|
|
|
var apiCtx = &context.APIContext{Context: ctx, Org: nil}
|
|
|
|
web.SetForm(apiCtx, &opts)
|
|
|
|
Edit(apiCtx)
|
2019-05-30 23:09:05 +08:00
|
|
|
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
2021-09-19 19:49:59 +08:00
|
|
|
db.AssertExistsAndLoadBean(t, &models.Repository{
|
2019-05-30 23:09:05 +08:00
|
|
|
ID: 1,
|
2021-09-19 19:49:59 +08:00
|
|
|
}, db.Cond("name = ? AND is_archived = 1", *opts.Name))
|
2019-05-30 23:09:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoEditNameChange(t *testing.T) {
|
2021-09-19 19:49:59 +08:00
|
|
|
db.PrepareTestEnv(t)
|
2019-05-30 23:09:05 +08:00
|
|
|
|
|
|
|
ctx := test.MockContext(t, "user2/repo1")
|
|
|
|
test.LoadRepo(t, ctx, 1)
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
ctx.Repo.Owner = ctx.User
|
|
|
|
name := "newname"
|
|
|
|
opts := api.EditRepoOption{
|
|
|
|
Name: &name,
|
|
|
|
}
|
|
|
|
|
2021-01-26 23:36:53 +08:00
|
|
|
var apiCtx = &context.APIContext{Context: ctx, Org: nil}
|
|
|
|
web.SetForm(apiCtx, &opts)
|
|
|
|
Edit(apiCtx)
|
2019-05-30 23:09:05 +08:00
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2021-09-19 19:49:59 +08:00
|
|
|
db.AssertExistsAndLoadBean(t, &models.Repository{
|
2019-05-30 23:09:05 +08:00
|
|
|
ID: 1,
|
2021-09-19 19:49:59 +08:00
|
|
|
}, db.Cond("name = ?", opts.Name))
|
2019-05-30 23:09:05 +08:00
|
|
|
}
|