summaryrefslogtreecommitdiffstats
path: root/integrations/user_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-07-07 15:36:47 -0400
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-07-07 21:36:47 +0200
commitf1adaef45849fc260b07be39a39b9c1ee5146923 (patch)
treebc33151ef4021ae14adf2e6cfc694b9e4729cef8 /integrations/user_test.go
parent5651cc7413640f12a9eb8dee64d332ea9597afce (diff)
downloadgitea-f1adaef45849fc260b07be39a39b9c1ee5146923.tar.gz
gitea-f1adaef45849fc260b07be39a39b9c1ee5146923.zip
Less verbose integration tests (#2123)
* Helper functions for intergration test boilerplate
Diffstat (limited to 'integrations/user_test.go')
-rw-r--r--integrations/user_test.go48
1 files changed, 14 insertions, 34 deletions
diff --git a/integrations/user_test.go b/integrations/user_test.go
index 4b7d81cfb5..ddb46da317 100644
--- a/integrations/user_test.go
+++ b/integrations/user_test.go
@@ -18,27 +18,19 @@ func TestViewUser(t *testing.T) {
prepareTestEnv(t)
req := NewRequest(t, "GET", "/user2")
- resp := MakeRequest(req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
+ MakeRequest(t, req, http.StatusOK)
}
func TestRenameUsername(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user2")
-
- req := NewRequest(t, "GET", "/user/settings")
- resp := session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
-
- htmlDoc := NewHTMLParser(t, resp.Body)
- req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
- "_csrf": htmlDoc.GetCSRF(),
+ req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
+ "_csrf": GetCSRF(t, session, "/user/settings"),
"name": "newUsername",
"email": "user2@example.com",
})
- resp = session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
+ session.MakeRequest(t, req, http.StatusFound)
models.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
models.AssertNotExistsBean(t, &models.User{Name: "user2"})
@@ -58,19 +50,14 @@ func TestRenameInvalidUsername(t *testing.T) {
session := loginUser(t, "user2")
for _, invalidUsername := range invalidUsernames {
t.Logf("Testing username %s", invalidUsername)
- req := NewRequest(t, "GET", "/user/settings")
- resp := session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
- htmlDoc := NewHTMLParser(t, resp.Body)
- req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
- "_csrf": htmlDoc.GetCSRF(),
+ req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
+ "_csrf": GetCSRF(t, session, "/user/settings"),
"name": invalidUsername,
"email": "user2@example.com",
})
- resp = session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
- htmlDoc = NewHTMLParser(t, resp.Body)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
assert.Contains(t,
htmlDoc.doc.Find(".ui.negative.message").Text(),
i18n.Tr("en", "form.alpha_dash_dot_error"),
@@ -92,23 +79,16 @@ func TestRenameReservedUsername(t *testing.T) {
session := loginUser(t, "user2")
for _, reservedUsername := range reservedUsernames {
t.Logf("Testing username %s", reservedUsername)
- req := NewRequest(t, "GET", "/user/settings")
- resp := session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
-
- htmlDoc := NewHTMLParser(t, resp.Body)
- req = NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
- "_csrf": htmlDoc.GetCSRF(),
+ req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
+ "_csrf": GetCSRF(t, session, "/user/settings"),
"name": reservedUsername,
"email": "user2@example.com",
})
- resp = session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
+ resp := session.MakeRequest(t, req, http.StatusFound)
- req = NewRequest(t, "GET", "/user/settings")
- resp = session.MakeRequest(t, req)
- assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
- htmlDoc = NewHTMLParser(t, resp.Body)
+ req = NewRequest(t, "GET", RedirectURL(t, resp))
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
assert.Contains(t,
htmlDoc.doc.Find(".ui.negative.message").Text(),
i18n.Tr("en", "user.newName_reserved"),