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

Commit

Permalink
test: Contest model test case
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizaMaluf committed Nov 2, 2023
1 parent 558624f commit bd2b726
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
40 changes: 36 additions & 4 deletions apps/contests/tests_contests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
from datetime import timedelta

from django.test import TestCase
from django.utils import timezone

from apps.contests.enums import ContestStatus
from apps.contests.models import Contest


class ContestModelFormTestCase(TestCase):
def setUp(self) -> None:
now = timezone.now()
self.contest = Contest(
id=1,
title="Test Contest",
description="This is a test contest",
start_time=now,
end_time=now + timedelta(hours=1),
cancelled=False,
)

def test_status_pending(self) -> None:
self.contest.start_time = timezone.now() + timedelta(hours=1)
self.assertEqual(self.contest.status, ContestStatus.PENDING)

def test_status_running(self) -> None:
self.contest.start_time = timezone.now() - timedelta(hours=1)
self.contest.end_time = timezone.now() + timedelta(hours=1)
self.assertEqual(self.contest.status, ContestStatus.RUNNING)

def test_status_finished(self) -> None:
self.contest.end_time = timezone.now() - timedelta(hours=1)
self.assertEqual(self.contest.status, ContestStatus.FINISHED)

def test_status_cancelled(self) -> None:
self.contest.cancelled = True
self.assertEqual(self.contest.status, ContestStatus.CANCELLED)


class IndexViewTestCase(TestCase):
Expand All @@ -17,9 +53,5 @@ class ContestStatusTestCase(TestCase):
pass


class ContestModelFormTestCase(TestCase):
pass


class ContestAdminTestCase(TestCase):
pass
6 changes: 1 addition & 5 deletions apps/problems/tests_problems.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from django.test import TestCase


class DetailViewTestCase(TestCase):
pass


class ProblemTestCase(TestCase):
pass


class ProblemModelFormTestCase(TestCase):
class DetailViewTestCase(TestCase):
pass


Expand Down
12 changes: 2 additions & 10 deletions apps/users/tests_users.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
from django.test import TestCase

from .admin import UserAdmin
from .models import User
from apps.users.admin import UserAdmin
from apps.users.models import User


class UserModelTestCase(TestCase):
def test_user_fields(self) -> None:
self.user_data = {
"email": "[email protected]",
"username": "user_test",
"password": "testpassword",
}
self.user = User.objects.create(**self.user_data)

def test_username_field_is_email(self) -> None:
self.assertEqual(User().USERNAME_FIELD, "email")

Expand Down

0 comments on commit bd2b726

Please sign in to comment.