From 38f3091552dea42d82812afa3ed347ec9c880f28 Mon Sep 17 00:00:00 2001 From: kyomi Date: Wed, 8 Nov 2023 09:31:58 -0300 Subject: [PATCH] test(apps/users): fix some tests for user app --- apps/problems/tests.py | 46 ------------------------- apps/users/{tests_users.py => tests.py} | 30 +++++++++++----- 2 files changed, 22 insertions(+), 54 deletions(-) rename apps/users/{tests_users.py => tests.py} (75%) diff --git a/apps/problems/tests.py b/apps/problems/tests.py index 9511daf..8ab9c8e 100644 --- a/apps/problems/tests.py +++ b/apps/problems/tests.py @@ -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() diff --git a/apps/users/tests_users.py b/apps/users/tests.py similarity index 75% rename from apps/users/tests_users.py rename to apps/users/tests.py index f6561d9..b509386 100644 --- a/apps/users/tests_users.py +++ b/apps/users/tests.py @@ -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 @@ -19,6 +20,7 @@ def test_create_user(self) -> None: email="test@example.com", password="testpassword", ) + self.assertEqual(user.email, "test@example.com") self.assertEqual(user.username, "testuser") self.assertFalse(user.is_staff) @@ -30,6 +32,7 @@ def test_create_superuser(self) -> None: email="admin@example.com", password="adminpassword", ) + self.assertEqual(superuser.email, "admin@example.com") self.assertEqual(superuser.username, "adminuser") self.assertTrue(superuser.is_staff) @@ -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", @@ -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 = ( @@ -71,4 +84,5 @@ def test_add_fieldsets(self) -> None: }, ), ) + self.assertEqual(UserAdmin.add_fieldsets, expected_add_fieldsets)