summaryrefslogtreecommitdiffstats
path: root/integrations/repo_generate_test.go
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-11-11 09:15:29 -0600
committerLunny Xiao <xiaolunwen@gmail.com>2019-11-11 23:15:29 +0800
commit74a6add4d90beb8133bcbf8ca6b43de35e0aa983 (patch)
tree868e452d41d71094c5b2cccce67f4211fd14e77b /integrations/repo_generate_test.go
parent74bb292fe3f4c02fc1dc5f32622c74d820cadd78 (diff)
downloadgitea-74a6add4d90beb8133bcbf8ca6b43de35e0aa983.tar.gz
gitea-74a6add4d90beb8133bcbf8ca6b43de35e0aa983.zip
Template Repositories (#8768)
* Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'integrations/repo_generate_test.go')
-rw-r--r--integrations/repo_generate_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/integrations/repo_generate_test.go b/integrations/repo_generate_test.go
new file mode 100644
index 0000000000..b8f2a45e1e
--- /dev/null
+++ b/integrations/repo_generate_test.go
@@ -0,0 +1,67 @@
+// 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 integrations
+
+import (
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "code.gitea.io/gitea/models"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, templateRepoName, generateOwnerName, generateRepoName string) *httptest.ResponseRecorder {
+ generateOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: generateOwnerName}).(*models.User)
+
+ // Step0: check the existence of the generated repo
+ req := NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName)
+ resp := session.MakeRequest(t, req, http.StatusNotFound)
+
+ // Step1: go to the main page of template repo
+ req = NewRequestf(t, "GET", "/%s/%s", templateOwnerName, templateRepoName)
+ resp = session.MakeRequest(t, req, http.StatusOK)
+
+ // Step2: click the "Use this template" button
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/create\"]").Attr("href")
+ assert.True(t, exists, "The template has changed")
+ req = NewRequest(t, "GET", link)
+ resp = session.MakeRequest(t, req, http.StatusOK)
+
+ // Step3: fill the form of the create
+ htmlDoc = NewHTMLParser(t, resp.Body)
+ link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/create\"]").Attr("action")
+ assert.True(t, exists, "The template has changed")
+ _, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", generateOwner.ID)).Attr("data-value")
+ assert.True(t, exists, fmt.Sprintf("Generate owner '%s' is not present in select box", generateOwnerName))
+ req = NewRequestWithValues(t, "POST", link, map[string]string{
+ "_csrf": htmlDoc.GetCSRF(),
+ "uid": fmt.Sprintf("%d", generateOwner.ID),
+ "repo_name": generateRepoName,
+ "git_content": "true",
+ })
+ resp = session.MakeRequest(t, req, http.StatusFound)
+
+ // Step4: check the existence of the generated repo
+ req = NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName)
+ resp = session.MakeRequest(t, req, http.StatusOK)
+
+ return resp
+}
+
+func TestRepoGenerate(t *testing.T) {
+ prepareTestEnv(t)
+ session := loginUser(t, "user1")
+ testRepoGenerate(t, session, "user27", "template1", "user1", "generated1")
+}
+
+func TestRepoGenerateToOrg(t *testing.T) {
+ prepareTestEnv(t)
+ session := loginUser(t, "user2")
+ testRepoGenerate(t, session, "user27", "template1", "user2", "generated2")
+}