1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-27 15:37:43 +00:00
seahub/tests/api/test_obtain_auth_token.py

55 lines
1.7 KiB
Python
Raw Normal View History

2015-11-10 06:07:56 +00:00
import json
from seahub.profile.models import Profile
from seahub.test_utils import BaseTestCase
from .urls import TOKEN_URL
class ObtainAuthTokenTest(BaseTestCase):
def setUp(self):
self.p = Profile.objects.add_or_update(self.user.username, '', '')
self.p.login_id = 'test_login_id'
self.p.save()
def test_correct_email_passwd(self):
resp = self.client.post(TOKEN_URL, {
'username': self.user.username,
'password': self.user_password,
})
json_resp = json.loads(resp.content)
assert json_resp['token'] is not None
assert len(json_resp['token']) == 40
def test_correct_loginID_password(self):
resp = self.client.post(TOKEN_URL, {
'username': self.p.login_id,
'password': self.user_password,
})
json_resp = json.loads(resp.content)
assert json_resp['token'] is not None
assert len(json_resp['token']) == 40
def test_invalid_password(self):
resp = self.client.post(TOKEN_URL, {
'username': self.user.username,
'password': 'random_password',
})
self.assertEqual(400, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['non_field_errors'] == ['Unable to login with provided credentials.']
def test_empty_login_id(self):
self.p.login_id = ""
self.p.save()
resp = self.client.post(TOKEN_URL, {
'username': self.p.login_id,
'password': self.user_password,
})
self.assertEqual(400, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['non_field_errors'] == ['Must include "username" and "password"']