Add some api integration tests (#18872)
depends on #18871 Added some api integration tests to help testing of #18798. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
@ -167,6 +167,33 @@ func TestAPICreateUserInvalidEmail(t *testing.T) {
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
}
|
||||
|
||||
func TestAPICreateAndDeleteUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
adminUsername := "user1"
|
||||
session := loginUser(t, adminUsername)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
req := NewRequestWithValues(
|
||||
t,
|
||||
"POST",
|
||||
fmt.Sprintf("/api/v1/admin/users?token=%s", token),
|
||||
map[string]string{
|
||||
"email": "deleteme@domain.com",
|
||||
"full_name": "delete me",
|
||||
"login_name": "deleteme",
|
||||
"must_change_password": "true",
|
||||
"password": "password",
|
||||
"send_notify": "true",
|
||||
"source_id": "0",
|
||||
"username": "deleteme",
|
||||
},
|
||||
)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/admin/users/deleteme?token=%s", token))
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
}
|
||||
|
||||
func TestAPIEditUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
adminUsername := "user1"
|
||||
@ -209,3 +236,20 @@ func TestAPIEditUser(t *testing.T) {
|
||||
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
||||
assert.True(t, user2.IsRestricted)
|
||||
}
|
||||
|
||||
func TestAPICreateRepoForUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
adminUsername := "user1"
|
||||
session := loginUser(t, adminUsername)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
req := NewRequestWithJSON(
|
||||
t,
|
||||
"POST",
|
||||
fmt.Sprintf("/api/v1/admin/users/%s/repos?token=%s", adminUsername, token),
|
||||
&api.CreateRepoOption{
|
||||
Name: "admincreatedrepo",
|
||||
},
|
||||
)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
}
|
||||
|
Reference in New Issue
Block a user