修改account和announcement中的测试用例,改为当前为管理员用户的登录状态

This commit is contained in:
hohoTT
2015-08-09 19:19:59 +08:00
parent 77a83f7085
commit b089455bba
2 changed files with 16 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ from rest_framework.test import APITestCase, APIClient
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import User
from .models import User, SUPER_ADMIN
from .decorators import login_required, admin_required
@@ -178,29 +178,32 @@ class UserAdminAPITest(APITestCase):
def setUp(self):
self.client = APIClient()
self.url = reverse("user_admin_api")
user = User.objects.create(username="test")
user = User.objects.create(username="test", admin_type=SUPER_ADMIN)
user.set_password("testaa")
user.save()
def test_put_invalid_data(self):
self.client.login(username="test", password="test")
self.client.login(username="test", password="testaa")
data = {"username": "test", "password": "testaa", "email": "60@qq.com", "admin_type": "2"}
response = self.client.put(self.url, data=data)
self.assertEqual(response.data["code"], 1)
def test_user_does_not_exist(self):
self.client.login(username="test", password="testaa")
data = {"id": 2, "username": "test0", "real_name": "test00",
"password": "testaa","email": "60@qq.com", "admin_type": "2"}
response = self.client.put(self.url, data=data)
self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"})
def test_success_user_edit_not_password(self):
self.client.login(username="test", password="testaa")
data = {"id": 1, "username": "test0", "real_name": "test00",
"email": "60@qq.com", "admin_type": "2"}
response = self.client.put(self.url, data=data)
self.assertEqual(response.data["code"], 0)
def test_success_user_edit_change_password(self):
self.client.login(username="test", password="testaa")
data = {"id": 1, "username": "test0", "real_name": "test00", "password": "111111",
"email": "60@qq.com", "admin_type": "2"}
response = self.client.put(self.url, data=data)