mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 01:44:13 +00:00
[tests] Fix fails
This commit is contained in:
@@ -1,84 +1,58 @@
|
||||
import json
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
import requests
|
||||
|
||||
from seahub.group.models import PublicGroup
|
||||
from seahub.share.models import FileShare
|
||||
from seahub.test_utils import Fixtures
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
from tests.common.utils import randstring
|
||||
|
||||
class GroupAddTest(TestCase, Fixtures):
|
||||
def test_can_add(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
class GroupAddTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.user)
|
||||
|
||||
def test_can_add(self):
|
||||
resp = self.client.post(reverse('group_add'), {
|
||||
'group_name': 'test_group_%s' % randstring(6)
|
||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
|
||||
assert json.loads(resp.content)['success'] is True
|
||||
|
||||
def test_can_add_with_blank(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
resp = self.client.post(reverse('group_add'), {
|
||||
'group_name': 'test group %s' % randstring(6)
|
||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
assert json.loads(resp.content)['success'] is True
|
||||
|
||||
def test_can_add_with_hyphen(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
resp = self.client.post(reverse('group_add'), {
|
||||
'group_name': 'test-group-%s' % randstring(6)
|
||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
assert json.loads(resp.content)['success'] is True
|
||||
|
||||
def test_can_add_with_blank_and_hyphen(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
resp = self.client.post(reverse('group_add'), {
|
||||
'group_name': 'test-group %s' % randstring(6)
|
||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
assert json.loads(resp.content)['success'] is True
|
||||
|
||||
def test_can_not_add_with_invalid_name(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
resp = self.client.post(reverse('group_add'), {
|
||||
'group_name': 'test*group(name)'
|
||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(400, resp.status_code)
|
||||
|
||||
class GroupDiscussTest(TestCase, Fixtures):
|
||||
|
||||
class GroupDiscussTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
grp = self.group
|
||||
self.login_as(self.user)
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_group()
|
||||
|
||||
def test_can_render(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
resp = self.client.get(reverse('group_discuss', args=[self.group.id]))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed(resp, 'group/group_discuss.html')
|
||||
|
@@ -1,18 +1,13 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
|
||||
from seahub.base.accounts import User
|
||||
from seahub.test_utils import Fixtures
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
from seaserv import ccnet_threaded_rpc
|
||||
|
||||
|
||||
class DeleteUserAccountTest(TestCase, Fixtures):
|
||||
class DeleteUserAccountTest(BaseTestCase):
|
||||
def test_can_delete(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
self.login_as(self.user)
|
||||
|
||||
username = self.user.username
|
||||
|
||||
|
@@ -6,9 +6,9 @@ from django.core.urlresolvers import reverse
|
||||
import requests
|
||||
|
||||
from seahub.share.models import FileShare
|
||||
from seahub.test_utils import Fixtures
|
||||
from seahub.test_utils import Fixtures, BaseTestCase
|
||||
|
||||
class ListSharedLinksTest(TestCase, Fixtures):
|
||||
class ListSharedLinksTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
share_file_info = {
|
||||
'username': 'test@test.com',
|
||||
@@ -22,14 +22,8 @@ class ListSharedLinksTest(TestCase, Fixtures):
|
||||
def tearDown(self):
|
||||
self.remove_repo()
|
||||
|
||||
def login(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
def test_can_render(self):
|
||||
self.login()
|
||||
self.login_as(self.user)
|
||||
|
||||
resp = self.client.get(reverse('list_shared_links'))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
@@ -53,7 +47,7 @@ class ListSharedLinksTest(TestCase, Fixtures):
|
||||
}
|
||||
fs = FileShare.objects.create_file_link(**share_file_info)
|
||||
|
||||
self.login()
|
||||
self.login_as(self.user)
|
||||
|
||||
resp = self.client.get(reverse('list_shared_links'))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
@@ -16,10 +16,10 @@ class LoginTest(TestCase):
|
||||
self.client.get(LOGIN_URL)
|
||||
|
||||
resp = self.client.post(LOGIN_URL, {
|
||||
'username': USERNAME,
|
||||
'login': USERNAME,
|
||||
'password': 'fakepasswd',
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert resp.context['form'].errors['__all__'] == [
|
||||
u'Please enter a correct username and password. Note that both fields are case-sensitive.'
|
||||
u'Please enter a correct email/username and password. Note that both fields are case-sensitive.'
|
||||
]
|
||||
|
@@ -1,10 +1,9 @@
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
|
||||
from seahub.test_utils import Fixtures
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
class DirDownloadTest(TestCase, Fixtures):
|
||||
class DirDownloadTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.folder_path = self.folder
|
||||
self.user2 = self.create_user('test2@test.com')
|
||||
@@ -15,34 +14,24 @@ class DirDownloadTest(TestCase, Fixtures):
|
||||
self.remove_user(self.user2.username)
|
||||
|
||||
def test_can_download(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
self.login_as(self.user)
|
||||
|
||||
dl_url = reverse('repo_download_dir', args=[self.repo.id]) + \
|
||||
'?p=' + self.folder_path
|
||||
resp = self.client.get(dl_url)
|
||||
self.assertEqual(302, resp.status_code)
|
||||
assert '8082/files/' in resp.get('location')
|
||||
|
||||
|
||||
def test_can_download_root(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
self.login_as(self.user)
|
||||
|
||||
dl_url = reverse('repo_download_dir', args=[self.repo.id])
|
||||
resp = self.client.get(dl_url)
|
||||
self.assertEqual(302, resp.status_code)
|
||||
assert '8082/files/' in resp.get('location')
|
||||
|
||||
|
||||
def test_permission_error(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.user2.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
self.login_as(self.user2)
|
||||
|
||||
dl_url = reverse('repo_download_dir', args=[self.repo.id]) + \
|
||||
'?p=' + self.folder_path
|
||||
|
@@ -1,19 +1,16 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http.cookie import parse_cookie
|
||||
from django.test import TestCase
|
||||
|
||||
from seahub.base.accounts import User
|
||||
from seahub.test_utils import Fixtures, BaseTestCase
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
from seaserv import ccnet_threaded_rpc
|
||||
|
||||
class UserToggleStatusTest(TestCase, Fixtures):
|
||||
def test_can_activate(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.admin.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
class UserToggleStatusTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
def test_can_activate(self):
|
||||
old_passwd = self.user.enc_password
|
||||
resp = self.client.get(
|
||||
reverse('user_toggle_status', args=[self.user.username]) + '?s=1',
|
||||
@@ -27,11 +24,6 @@ class UserToggleStatusTest(TestCase, Fixtures):
|
||||
assert u.enc_password == old_passwd
|
||||
|
||||
def test_can_deactivate(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.admin.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
|
||||
old_passwd = self.user.enc_password
|
||||
resp = self.client.get(
|
||||
reverse('user_toggle_status', args=[self.user.username]) + '?s=0',
|
||||
@@ -45,13 +37,11 @@ class UserToggleStatusTest(TestCase, Fixtures):
|
||||
assert u.enc_password == old_passwd
|
||||
|
||||
|
||||
class UserResetTest(TestCase, Fixtures):
|
||||
def test_can_reset(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.admin.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
class UserResetTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
def test_can_reset(self):
|
||||
old_passwd = self.user.enc_password
|
||||
resp = self.client.post(
|
||||
reverse('user_reset', args=[self.user.email])
|
||||
@@ -62,13 +52,11 @@ class UserResetTest(TestCase, Fixtures):
|
||||
assert u.enc_password != old_passwd
|
||||
|
||||
|
||||
class BatchUserMakeAdminTest(TestCase, Fixtures):
|
||||
def test_can_make_admins(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.admin.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
class BatchUserMakeAdminTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
def test_can_make_admins(self):
|
||||
resp = self.client.post(
|
||||
reverse('batch_user_make_admin'), {
|
||||
'set_admin_emails': self.user.username
|
||||
@@ -102,13 +90,11 @@ class BatchUserMakeAdminTest(TestCase, Fixtures):
|
||||
# assert u.enc_password == old_passwd
|
||||
|
||||
|
||||
class UserRemoveTest(TestCase, Fixtures):
|
||||
def test_can_remove(self):
|
||||
self.client.post(
|
||||
reverse('auth_login'), {'username': self.admin.username,
|
||||
'password': 'secret'}
|
||||
)
|
||||
class UserRemoveTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
def test_can_remove(self):
|
||||
# create one user
|
||||
username = self.user.username
|
||||
|
||||
|
Reference in New Issue
Block a user