contest type 的表示类型修改为常量
0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
This commit is contained in:
@@ -10,6 +10,7 @@ from account.models import User
|
||||
from group.models import Group
|
||||
from contest.models import Contest, ContestProblem
|
||||
from .models import ContestSubmission
|
||||
from .models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST
|
||||
from announcement.models import Announcement
|
||||
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||
from decorators import check_user_contest_permission
|
||||
@@ -32,15 +33,17 @@ class ContestAdminAPITest(APITestCase):
|
||||
join_group_setting=0, visible=True,
|
||||
admin=user2)
|
||||
self.group2 = Group.objects.create(name="group2", description="des0",
|
||||
join_group_setting=0, visible=True,
|
||||
admin=user1)
|
||||
join_group_setting=0, visible=True,
|
||||
admin=user1)
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
self.group_contest = Contest.objects.create(title="titley", description="descriptiony", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -54,7 +57,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_global_contest_does_not_has_privileges(self):
|
||||
self.client.login(username="test2", password="testbb")
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 2,
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -62,7 +65,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_global_contest_password_exists(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 2,
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -70,7 +73,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_group_contest_group_at_least_one(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 0,
|
||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": GROUP_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -78,7 +81,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_global_contest_successfully(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "title1", "description": "description1", "mode": 1, "contest_type": 2,
|
||||
data = {"title": "title1", "description": "description1", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -86,7 +89,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_group_contest_super_admin_successfully(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "title3", "description": "description3", "mode": 1, "contest_type": 0,
|
||||
data = {"title": "title3", "description": "description3", "mode": 1, "contest_type": GROUP_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -94,7 +97,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_group_contest_admin_successfully(self):
|
||||
self.client.login(username="test2", password="testbb")
|
||||
data = {"title": "title6", "description": "description6", "mode": 2, "contest_type": 0,
|
||||
data = {"title": "title6", "description": "description6", "mode": 2, "contest_type": GROUP_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -102,7 +105,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_time_error(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "title2", "description": "description2", "mode": 1, "contest_type": 2,
|
||||
data = {"title": "title2", "description": "description2", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T12:00:00.000Z",
|
||||
"end_time": "2015-08-15T10:00:00.000Z", "password": "aabb", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -110,7 +113,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
|
||||
def test_contest_has_exists(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"title": "titlex", "description": "descriptionx", "mode": 1, "contest_type": 2,
|
||||
data = {"title": "titlex", "description": "descriptionx", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||
response = self.client.post(self.url, data=data)
|
||||
@@ -126,7 +129,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_contest_does_not_exist(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.global_contest.id + 10, "title": "title2", "description": "description2", "mode": 1,
|
||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||
"visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -135,7 +138,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_global_contest_successfully(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.global_contest.id, "title": "titlez", "description": "descriptionz", "mode": 1,
|
||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "password": "aabb",
|
||||
"visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -146,7 +149,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_group_contest_successfully(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
||||
"groups": [self.group.id], "visible": False}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -158,7 +161,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_group_contest_unsuccessfully(self):
|
||||
self.client.login(username="test2", password="testbb")
|
||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
||||
"groups": [self.group.id], "visible": False}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -167,7 +170,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_group_at_least_one(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertEqual(response.data, {"code": 1, "data": u"请至少选择一个小组"})
|
||||
@@ -175,7 +178,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_contest_has_exists(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.global_contest.id, "title": "titley", "description": "descriptiony", "mode": 1,
|
||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||
"visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -184,7 +187,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_global_contest_does_not_has_privileges(self):
|
||||
self.client.login(username="test2", password="testbb")
|
||||
data = {"id": self.global_contest.id, "title": "titlexxxxxxxxx", "description": "descriptionxxxxxx", "mode": 1,
|
||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||
"visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -193,8 +196,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_global_contest_password_exists(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.global_contest.id, "title": "title0", "description": "description0", "mode": 1,
|
||||
"contest_type": 2,
|
||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertEqual(response.data, {"code": 1, "data": u"此比赛为有密码的公开赛,密码不可为空"})
|
||||
@@ -202,7 +204,7 @@ class ContestAdminAPITest(APITestCase):
|
||||
def test_edit_time_error(self):
|
||||
self.client.login(username="test1", password="testaa")
|
||||
data = {"id": self.global_contest.id, "title": "titleaaaa", "description": "descriptionaaaaa", "mode": 1,
|
||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
||||
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||
"start_time": "2015-08-15T12:00:00.000Z", "end_time": "2015-08-15T10:00:00.000Z", "password": "aabb",
|
||||
"visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
@@ -245,7 +247,8 @@ class ContestProblemAdminAPItEST(APITestCase):
|
||||
self.user3.save()
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -373,7 +376,7 @@ class ContestProblemAdminAPItEST(APITestCase):
|
||||
|
||||
def test_query_contest_problem_exists_by_contest_id(self):
|
||||
self.client.login(username="test3", password="testaa")
|
||||
response = self.client.get(self.url + "?contest_id="+ str(self.global_contest.id))
|
||||
response = self.client.get(self.url + "?contest_id=" + str(self.global_contest.id))
|
||||
self.assertEqual(response.data["code"], 0)
|
||||
self.assertEqual(len(response.data["data"]), 0)
|
||||
|
||||
@@ -414,7 +417,8 @@ class ContestPasswordVerifyAPITest(APITestCase):
|
||||
self.user2.save()
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -453,7 +457,8 @@ class ContestPageTest(TestCase):
|
||||
self.user1.save()
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -476,7 +481,8 @@ class ContestProblemPageTest(TestCase):
|
||||
self.user1.save()
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -519,7 +525,8 @@ class ContestProblemListPageTest(TestCase):
|
||||
self.user1.save()
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
@@ -555,7 +562,8 @@ class ContestListPageTest(TestCase):
|
||||
self.url = reverse('contest_list_page')
|
||||
self.client.login(username="test1", password="testaa")
|
||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||
contest_type=2, show_rank=True, show_user_submission=True,
|
||||
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||
show_user_submission=True,
|
||||
start_time="2015-08-15T10:00:00.000Z",
|
||||
end_time="2015-08-15T12:00:00.000Z",
|
||||
password="aacc", created_by=User.objects.get(username="test1"))
|
||||
|
||||
Reference in New Issue
Block a user