2011-03-19 05:15:02 +00:00
|
|
|
"""
|
|
|
|
This file demonstrates two different styles of tests (one doctest and one
|
|
|
|
unittest). These will both pass when you run "manage.py test".
|
|
|
|
|
|
|
|
Replace these with more appropriate tests for your application.
|
|
|
|
"""
|
|
|
|
|
2012-08-08 02:09:02 +00:00
|
|
|
from django.utils import unittest
|
|
|
|
from django.test.client import Client, RequestFactory
|
2011-03-19 05:15:02 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2012-08-08 02:09:02 +00:00
|
|
|
from seahub.base.accounts import User
|
2011-03-19 05:15:02 +00:00
|
|
|
|
2012-08-08 02:09:02 +00:00
|
|
|
class BaseTestCase(TestCase):
|
|
|
|
"""
|
|
|
|
Helper base class for all the follow test cases.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
2012-08-19 08:47:02 +00:00
|
|
|
self.user = User.objects.create_superuser('admin@admin.com', 'testpassword')
|
2012-08-08 02:09:02 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.user.delete()
|
|
|
|
|
2012-08-19 08:47:02 +00:00
|
|
|
class BasicTest(BaseTestCase):
|
2012-08-08 02:09:02 +00:00
|
|
|
|
|
|
|
def login(self):
|
|
|
|
response = self.client.post('/accounts/login/', {
|
2012-08-19 08:47:02 +00:00
|
|
|
'username': 'admin@admin.com',
|
2012-08-08 02:09:02 +00:00
|
|
|
'password': 'testpassword',
|
|
|
|
})
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
2012-08-19 08:47:02 +00:00
|
|
|
def test_my_home(self):
|
2012-08-08 02:09:02 +00:00
|
|
|
self.login()
|
|
|
|
r = self.client.get('/home/my/')
|
|
|
|
|
|
|
|
# Check that response is 200 OK
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
|
|
|
|
self.assertEqual(len(r.context['owned_repos']), 0)
|
|
|
|
self.assertEqual(len(r.context['in_repos']), 0)
|
2011-03-19 05:15:02 +00:00
|
|
|
|
2012-08-19 08:47:02 +00:00
|
|
|
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)
|