2019-05-30 20:39:05 +05:30
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2019-05-30 20:39:05 +05:30
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2019-05-30 20:39:05 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2021-01-26 21:06:53 +05:30
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/contexttest"
|
2019-05-30 20:39:05 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepoEdit(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
unittest.PrepareTestEnv(t)
|
2019-05-30 20:39:05 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
|
|
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Repo.Owner = ctx.Doer
|
2019-05-30 20:39:05 +05:30
|
|
|
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
|
2024-02-13 04:07:23 +05:30
|
|
|
allowFastForwardOnlyMerge := false
|
2019-05-30 20:39:05 +05:30
|
|
|
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,
|
2024-02-13 04:07:23 +05:30
|
|
|
AllowFastForwardOnly: &allowFastForwardOnlyMerge,
|
2019-05-30 20:39:05 +05:30
|
|
|
Archived: &archived,
|
|
|
|
}
|
|
|
|
|
2023-05-21 07:20:53 +05:30
|
|
|
web.SetForm(ctx, &opts)
|
|
|
|
Edit(ctx)
|
2019-05-30 20:39:05 +05:30
|
|
|
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
2021-12-10 06:57:50 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
2019-05-30 20:39:05 +05:30
|
|
|
ID: 1,
|
2021-11-16 14:23:21 +05:30
|
|
|
}, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
|
2019-05-30 20:39:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoEditNameChange(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
unittest.PrepareTestEnv(t)
|
2019-05-30 20:39:05 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
|
|
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2022-03-22 12:33:22 +05:30
|
|
|
ctx.Repo.Owner = ctx.Doer
|
2019-05-30 20:39:05 +05:30
|
|
|
name := "newname"
|
|
|
|
opts := api.EditRepoOption{
|
|
|
|
Name: &name,
|
|
|
|
}
|
|
|
|
|
2023-05-21 07:20:53 +05:30
|
|
|
web.SetForm(ctx, &opts)
|
|
|
|
Edit(ctx)
|
2019-05-30 20:39:05 +05:30
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
2019-05-30 20:39:05 +05:30
|
|
|
ID: 1,
|
2021-11-16 14:23:21 +05:30
|
|
|
}, unittest.Cond("name = ?", opts.Name))
|
2019-05-30 20:39:05 +05:30
|
|
|
}
|