Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(validators): contest admin form validator test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizaMaluf committed Nov 14, 2023
1 parent 8daf84f commit 224345c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# intended to in multiple environments; otherwise, check them in:
# .python-version

# pipenv
Expand Down
17 changes: 17 additions & 0 deletions apps/contests/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta

from django.contrib.admin import AdminSite
from django.core.exceptions import ValidationError
from django.forms import CharField, Textarea
from django.test import TestCase
from django.urls import resolve, reverse
Expand All @@ -9,6 +10,7 @@
from apps.contests.admin import ContestAdmin, ContestModelForm
from apps.contests.enums import ContestStatus
from apps.contests.models import Contest
from apps.users.models import User


class ContestTestCase(TestCase):
Expand All @@ -18,6 +20,7 @@ def setUp(self) -> None:
description="This is a test contest",
cancelled=False,
)
self.user = User(username="test_user")

def test_status_pending(self) -> None:
self.contest.start_time = timezone.now() + timedelta(hours=1)
Expand All @@ -38,6 +41,20 @@ def test_status_cancelled(self) -> None:
self.contest.cancelled = True
self.assertEqual(self.contest.status, ContestStatus.CANCELLED)

def test_clean_method(self) -> None:
invalid_contest = Contest(
title="Invalid Contest",
description="This contest has invalid times",
start_time=timezone.now() + timedelta(days=2),
end_time=timezone.now() + timedelta(days=1),
)
with self.assertRaises(ValidationError) as context:
invalid_contest.clean()

self.assertEqual(
context.exception.messages, ["Start time must be before end time."]
)


class ContestStatusTestCase(TestCase):
def test_pending(self) -> None:
Expand Down

0 comments on commit 224345c

Please sign in to comment.