mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
Add create_superuser method and update tests
This commit is contained in:
@@ -35,6 +35,10 @@ class UserManager(object):
|
|||||||
|
|
||||||
return self.get(email=email)
|
return self.get(email=email)
|
||||||
|
|
||||||
|
def create_superuser(self, email, password):
|
||||||
|
u = self.create_user(email, password, is_staff=True, is_active=True)
|
||||||
|
return u
|
||||||
|
|
||||||
def get(self, email=None, id=None):
|
def get(self, email=None, id=None):
|
||||||
if not email and not id:
|
if not email and not id:
|
||||||
raise User.DoesNotExist, 'User matching query does not exits.'
|
raise User.DoesNotExist, 'User matching query does not exits.'
|
||||||
|
@@ -9,36 +9,28 @@ from django.utils import unittest
|
|||||||
from django.test.client import Client, RequestFactory
|
from django.test.client import Client, RequestFactory
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from auth.models import AnonymousUser
|
|
||||||
|
|
||||||
from seahub.base.accounts import User
|
from seahub.base.accounts import User
|
||||||
from seahub.views import myhome
|
|
||||||
|
|
||||||
class BaseTestCase(TestCase):
|
class BaseTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
Helper base class for all the follow test cases.
|
Helper base class for all the follow test cases.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user = User.objects.create_user('lennon@thebeatles.com', 'testpassword', is_active=True)
|
self.user = User.objects.create_superuser('admin@admin.com', 'testpassword')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.user.delete()
|
self.user.delete()
|
||||||
|
|
||||||
class SimpleTest(BaseTestCase):
|
class BasicTest(BaseTestCase):
|
||||||
"""
|
|
||||||
Use TestClient to do integration testing (ie: entire user checkout process
|
|
||||||
in shop which includes many steps) and RequestFactory to test independent
|
|
||||||
view functions behavior and their output (ie. adding product to cart).
|
|
||||||
"""
|
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
response = self.client.post('/accounts/login/', {
|
response = self.client.post('/accounts/login/', {
|
||||||
'username': 'lennon@thebeatles.com',
|
'username': 'admin@admin.com',
|
||||||
'password': 'testpassword',
|
'password': 'testpassword',
|
||||||
})
|
})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
def test_details(self):
|
def test_my_home(self):
|
||||||
self.login()
|
self.login()
|
||||||
r = self.client.get('/home/my/')
|
r = self.client.get('/home/my/')
|
||||||
|
|
||||||
@@ -48,3 +40,18 @@ class SimpleTest(BaseTestCase):
|
|||||||
self.assertEqual(len(r.context['owned_repos']), 0)
|
self.assertEqual(len(r.context['owned_repos']), 0)
|
||||||
self.assertEqual(len(r.context['in_repos']), 0)
|
self.assertEqual(len(r.context['in_repos']), 0)
|
||||||
|
|
||||||
|
def test_useradmin(self):
|
||||||
|
self.login()
|
||||||
|
r = self.client.get('/sys/useradmin/')
|
||||||
|
|
||||||
|
# Check that response is 200 OK
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
def test_notificationadmin(self):
|
||||||
|
self.login()
|
||||||
|
r = self.client.get('/sys/notificationadmin/')
|
||||||
|
|
||||||
|
# Check that response is 200 OK
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
self.assertEqual(len(r.context['notes']), 0)
|
||||||
|
Reference in New Issue
Block a user