separate contest submission and regular submission
This commit is contained in:
@@ -2,7 +2,7 @@ from django.db import models
|
||||
from django.utils.timezone import now
|
||||
from jsonfield import JSONField
|
||||
|
||||
from account.models import User
|
||||
from account.models import User, AdminType
|
||||
from utils.models import RichTextField
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ class Contest(models.Model):
|
||||
return ContestType.PASSWORD_PROTECTED_CONTEST
|
||||
return ContestType.PUBLIC_CONTEST
|
||||
|
||||
def is_contest_admin(self, user):
|
||||
return user.is_authenticated() and (self.created_by == user or user.admin_type == AdminType.SUPER_ADMIN)
|
||||
|
||||
class Meta:
|
||||
db_table = "contest"
|
||||
ordering = ("-create_time",)
|
||||
|
||||
@@ -74,17 +74,17 @@ class ContestAPITest(APITestCase):
|
||||
response = self.client.get("{}?id={}".format(self.url, contest_id))
|
||||
self.assertSuccess(response)
|
||||
|
||||
def test_contest_password(self):
|
||||
def test_regular_user_validate_contest_password(self):
|
||||
contest_id = self.create_contest().data["data"]["id"]
|
||||
self.create_user("test", "test123")
|
||||
url = self.reverse("contest_password_api")
|
||||
resp = self.client.post(url, {"contest_id": contest_id, "password": "error_password"})
|
||||
self.assertFailed(resp)
|
||||
self.assertDictEqual(resp.data, {"error": "error", "data": "Password doesn't match."})
|
||||
|
||||
resp = self.client.post(url, {"contest_id": contest_id, "password": DEFAULT_CONTEST_DATA["password"]})
|
||||
self.assertSuccess(resp)
|
||||
|
||||
def test_contest_access(self):
|
||||
def test_regular_user_access_contest(self):
|
||||
contest_id = self.create_contest().data["data"]["id"]
|
||||
self.create_user("test", "test123")
|
||||
url = self.reverse("contest_access_api")
|
||||
@@ -97,18 +97,6 @@ class ContestAPITest(APITestCase):
|
||||
resp = self.client.get(url + "?contest_id=" + str(contest_id))
|
||||
self.assertSuccess(resp)
|
||||
|
||||
# def test_get_not_started_contest(self):
|
||||
# contest_id = self.create_contest().data["data"]["id"]
|
||||
# resp = self.client.get(self.url + "?id=" + str(contest_id))
|
||||
# self.assertSuccess(resp)
|
||||
#
|
||||
# self.create_user("test", "1234")
|
||||
# url = self.reverse("contest_password_api")
|
||||
# resp = self.client.post(url, {"contest_id": contest_id, "password": DEFAULT_CONTEST_DATA["password"]})
|
||||
# self.assertSuccess(resp)
|
||||
# resp = self.client.get(self.url + "?id=" + str(contest_id))
|
||||
# self.assertFailed(resp)
|
||||
|
||||
|
||||
class ContestAnnouncementAPITest(APITestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -18,7 +18,7 @@ class ContestAPI(APIView):
|
||||
data["created_by"] = request.user
|
||||
if data["end_time"] <= data["start_time"]:
|
||||
return self.error("Start time must occur earlier than end time")
|
||||
if not data["password"]:
|
||||
if data.get("password") and data["password"] == "":
|
||||
data["password"] = None
|
||||
contest = Contest.objects.create(**data)
|
||||
return self.success(ContestAdminSerializer(contest).data)
|
||||
|
||||
Reference in New Issue
Block a user