mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-04 03:22:06 +00:00
修改account和announcement中的测试用例,改为当前为管理员用户的登录状态
This commit is contained in:
parent
77a83f7085
commit
b089455bba
@ -10,7 +10,7 @@ from rest_framework.test import APITestCase, APIClient
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from .models import User
|
from .models import User, SUPER_ADMIN
|
||||||
from .decorators import login_required, admin_required
|
from .decorators import login_required, admin_required
|
||||||
|
|
||||||
|
|
||||||
@ -178,29 +178,32 @@ class UserAdminAPITest(APITestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = APIClient()
|
self.client = APIClient()
|
||||||
self.url = reverse("user_admin_api")
|
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.set_password("testaa")
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
def test_put_invalid_data(self):
|
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"}
|
data = {"username": "test", "password": "testaa", "email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 1)
|
self.assertEqual(response.data["code"], 1)
|
||||||
|
|
||||||
def test_user_does_not_exist(self):
|
def test_user_does_not_exist(self):
|
||||||
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"id": 2, "username": "test0", "real_name": "test00",
|
data = {"id": 2, "username": "test0", "real_name": "test00",
|
||||||
"password": "testaa","email": "60@qq.com", "admin_type": "2"}
|
"password": "testaa","email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"})
|
self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"})
|
||||||
|
|
||||||
def test_success_user_edit_not_password(self):
|
def test_success_user_edit_not_password(self):
|
||||||
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"id": 1, "username": "test0", "real_name": "test00",
|
data = {"id": 1, "username": "test0", "real_name": "test00",
|
||||||
"email": "60@qq.com", "admin_type": "2"}
|
"email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 0)
|
self.assertEqual(response.data["code"], 0)
|
||||||
|
|
||||||
def test_success_user_edit_change_password(self):
|
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",
|
data = {"id": 1, "username": "test0", "real_name": "test00", "password": "111111",
|
||||||
"email": "60@qq.com", "admin_type": "2"}
|
"email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
|
@ -5,43 +5,45 @@ from rest_framework.test import APITestCase, APIClient
|
|||||||
|
|
||||||
from account.models import User
|
from account.models import User
|
||||||
from announcement.models import Announcement
|
from announcement.models import Announcement
|
||||||
|
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
|
|
||||||
|
|
||||||
class AnnouncementAdminAPITest(APITestCase):
|
class AnnouncementAdminAPITest(APITestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = APIClient()
|
self.client = APIClient()
|
||||||
self.url = reverse("announcement_admin_api")
|
self.url = reverse("announcement_admin_api")
|
||||||
user = User.objects.create(username="test")
|
user = User.objects.create(username="test", admin_type=SUPER_ADMIN)
|
||||||
user.set_password("test")
|
user.set_password("testaa")
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
# 以下是发布公告的测试
|
# 以下是发布公告的测试
|
||||||
def test_invalid_format(self):
|
def test_invalid_format(self):
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"title": "test1"}
|
data = {"title": "test1"}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 1)
|
self.assertEqual(response.data["code"], 1)
|
||||||
|
|
||||||
def test_success_announcement(self):
|
def test_success_announcement(self):
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"title": "title0", "content": "content0"}
|
data = {"title": "title0", "content": "content0"}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"})
|
self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"})
|
||||||
|
|
||||||
def test_post_invalid_data(self):
|
def test_post_invalid_data(self):
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"title": "test"}
|
data = {"title": "test"}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 1)
|
self.assertEqual(response.data["code"], 1)
|
||||||
|
|
||||||
# 以下是编辑公告的测试
|
# 以下是编辑公告的测试
|
||||||
def test_put_invalid_data(self):
|
def test_put_invalid_data(self):
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="testaa")
|
||||||
data = {"title": "test0", "content": "test0", "visible": "True"}
|
data = {"title": "test0", "content": "test0", "visible": "True"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 1)
|
self.assertEqual(response.data["code"], 1)
|
||||||
|
|
||||||
def test_announcement_does_not_exist(self):
|
def test_announcement_does_not_exist(self):
|
||||||
|
self.client.login(username="test", password="testaa")
|
||||||
announcement = Announcement.objects.create(title="aa",
|
announcement = Announcement.objects.create(title="aa",
|
||||||
content="AA",
|
content="AA",
|
||||||
created_by=User.objects.get(username="test"))
|
created_by=User.objects.get(username="test"))
|
||||||
@ -50,6 +52,7 @@ class AnnouncementAdminAPITest(APITestCase):
|
|||||||
self.assertEqual(response.data, {"code": 1, "data": u"该公告不存在!"})
|
self.assertEqual(response.data, {"code": 1, "data": u"该公告不存在!"})
|
||||||
|
|
||||||
def test_success_edit_announcement(self):
|
def test_success_edit_announcement(self):
|
||||||
|
self.client.login(username="test", password="testaa")
|
||||||
announcement = Announcement.objects.create(title="bb",
|
announcement = Announcement.objects.create(title="bb",
|
||||||
content="BB",
|
content="BB",
|
||||||
created_by=User.objects.get(username="test"))
|
created_by=User.objects.get(username="test"))
|
||||||
@ -63,7 +66,7 @@ class AnnouncementAPITest(APITestCase):
|
|||||||
self.client = APIClient()
|
self.client = APIClient()
|
||||||
self.url = reverse("announcement_list_api")
|
self.url = reverse("announcement_list_api")
|
||||||
user = User.objects.create(username="test")
|
user = User.objects.create(username="test")
|
||||||
user.set_password("test")
|
user.set_password("testaa")
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
def test_success_get_data(self):
|
def test_success_get_data(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user