You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "bytes"
  7. "net/http"
  8. "net/url"
  9. "testing"
  10. "code.gitea.io/gitea/models"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestDeleteUser(t *testing.T) {
  14. prepareTestEnv(t)
  15. session := loginUser(t, "user1", "password")
  16. req, err := http.NewRequest("GET", "/admin/users/8", nil)
  17. assert.NoError(t, err)
  18. resp := session.MakeRequest(t, req)
  19. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  20. doc, err := NewHtmlParser(resp.Body)
  21. assert.NoError(t, err)
  22. req, err = http.NewRequest("POST", "/admin/users/8/delete",
  23. bytes.NewBufferString(url.Values{
  24. "_csrf": []string{doc.GetInputValueByName("_csrf")},
  25. }.Encode()))
  26. assert.NoError(t, err)
  27. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  28. resp = session.MakeRequest(t, req)
  29. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  30. models.AssertNotExistsBean(t, &models.User{ID: 8})
  31. models.CheckConsistencyFor(t, &models.User{})
  32. }