Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

user_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 models
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestGetUserEmailsByNames(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. // ignore none active user email
  13. assert.Equal(t, []string{"user8@example.com"}, GetUserEmailsByNames([]string{"user8", "user9"}))
  14. assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, GetUserEmailsByNames([]string{"user8", "user5"}))
  15. }
  16. func TestCanCreateOrganization(t *testing.T) {
  17. assert.NoError(t, PrepareTestDatabase())
  18. admin := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
  19. assert.True(t, admin.CanCreateOrganization())
  20. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  21. assert.True(t, user.CanCreateOrganization())
  22. // Disable user create organization permission.
  23. user.AllowCreateOrganization = false
  24. assert.False(t, user.CanCreateOrganization())
  25. setting.Admin.DisableRegularOrgCreation = true
  26. user.AllowCreateOrganization = true
  27. assert.True(t, admin.CanCreateOrganization())
  28. assert.False(t, user.CanCreateOrganization())
  29. }