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

Commit

Permalink
test(apps/users): fix some tests for user app
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Nov 8, 2023
1 parent 22e98f6 commit 38f3091
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
46 changes: 0 additions & 46 deletions apps/problems/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,52 +67,6 @@ def test_cancelled_contest_is_not_accessible(self) -> None:
self.assertFalse(problem.is_accessible)


# teste a seguir passou, porém na
# hora do commit apresenta erros
# class ProblemModelFormTesteCase(TestCase):


# def test_form_fields(self) -> None:
# data = {"description":
# "Problem description",
# "score": 10,"memory_limit":
# 1024,"time_limit": 60,}
# form = ProblemModelForm(data)
# self.assertIsInstance
# (form.fields["description"], CharField)
# self.assertIsInstance
# (form.fields["score"], IntegerField)


# self.assertIsInstance
# (form.fields["memory_limit"], IntegerField)
# self.assertIsInstance(form.fields
# ["time_limit"], IntegerField)
# self.assertEqual(
# form.fields["description"]
# .widget.attrs, {"rows": 14, "cols": 80})


# self.assertEqual(form.fields
# ["score"].min_value, 0)
# self.assertFalse(form.fields
# ["score"].required)
# self.assertEqual(form.fields
# ["memory_limit"].min_value, 0)


# self.assertFalse(form.fields
# ["memory_limit"].required)
# self.assertEqual(form.fields
# ["memory_limit"].help_text, "In bytes.")
# self.assertEqual(form.fields
# ["time_limit"].min_value, 0)
# self.assertFalse(form.fields
# ["time_limit"].required)
# self.assertEqual(form.fields["time_limit"]
# .help_text, "In seconds.")


class ProblemAdminTestCase(TestCase):
def setUp(self) -> None:
now = timezone.now()
Expand Down
30 changes: 22 additions & 8 deletions apps/users/tests_users.py → apps/users/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.test import TestCase
from django.utils.translation import gettext as _

from apps.users.admin import UserAdmin
from apps.users.models import User
Expand All @@ -19,6 +20,7 @@ def test_create_user(self) -> None:
email="[email protected]",
password="testpassword",
)

self.assertEqual(user.email, "[email protected]")
self.assertEqual(user.username, "testuser")
self.assertFalse(user.is_staff)
Expand All @@ -30,6 +32,7 @@ def test_create_superuser(self) -> None:
email="[email protected]",
password="adminpassword",
)

self.assertEqual(superuser.email, "[email protected]")
self.assertEqual(superuser.username, "adminuser")
self.assertTrue(superuser.is_staff)
Expand All @@ -38,16 +41,25 @@ def test_create_superuser(self) -> None:

class UserAdminTestCase(TestCase):
def test_list_display(self) -> None:
self.assertEqual(
UserAdmin.list_display,
("username", "email", "is_staff", "is_active"),
)
list_display = UserAdmin.list_display
expected = ("username", "email", "is_staff", "is_active")

self.assertEqual(list_display, expected)

def test_list_filter(self) -> None:
list_filter = UserAdmin.list_filter
expected = ("is_staff", "is_superuser", "is_active", "groups")

self.assertEqual(list_filter, expected)

def test_fieldsets(self) -> None:
expected_fieldsets = [
(("Personal info"), {"fields": ("username", "email", "password")}),
expected = [
(
_("Personal info"),
{"fields": ("username", "email", "password")},
),
(
("Permissions"),
_("Permissions"),
{
"fields": (
"user_permissions",
Expand All @@ -59,7 +71,8 @@ def test_fieldsets(self) -> None:
},
),
]
self.assertEqual(UserAdmin.fieldsets, expected_fieldsets)

self.assertEqual(UserAdmin.fieldsets, expected)

def test_add_fieldsets(self) -> None:
expected_add_fieldsets = (
Expand All @@ -71,4 +84,5 @@ def test_add_fieldsets(self) -> None:
},
),
)

self.assertEqual(UserAdmin.add_fieldsets, expected_add_fieldsets)

0 comments on commit 38f3091

Please sign in to comment.