From 1ddad17a1e7f616c0cd77cc96d24034678b280e9 Mon Sep 17 00:00:00 2001 From: Shreyas Mayya <2022smayya@tjhsst.edu> Date: Thu, 17 Feb 2022 10:10:21 -0500 Subject: [PATCH] fix(profile): use Decimal in GPA tests --- .../migrations/0013_alter_user_gpa.py | 14 ++++++++++---- tjdests/apps/authentication/models.py | 9 ++++++++- tjdests/apps/profile/forms.py | 3 ++- tjdests/apps/profile/tests.py | 8 +++++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tjdests/apps/authentication/migrations/0013_alter_user_gpa.py b/tjdests/apps/authentication/migrations/0013_alter_user_gpa.py index facd2ff..454bc94 100644 --- a/tjdests/apps/authentication/migrations/0013_alter_user_gpa.py +++ b/tjdests/apps/authentication/migrations/0013_alter_user_gpa.py @@ -6,13 +6,19 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('authentication', '0012_user_preferred_name'), + ("authentication", "0012_user_preferred_name"), ] operations = [ migrations.AlterField( - model_name='user', - name='GPA', - field=models.DecimalField(blank=True, decimal_places=3, help_text='Weighted GPA', max_digits=4, null=True), + model_name="user", + name="GPA", + field=models.DecimalField( + blank=True, + decimal_places=3, + help_text="Weighted GPA", + max_digits=4, + null=True, + ), ), ] diff --git a/tjdests/apps/authentication/models.py b/tjdests/apps/authentication/models.py index a4c3588..86e81c2 100644 --- a/tjdests/apps/authentication/models.py +++ b/tjdests/apps/authentication/models.py @@ -8,7 +8,14 @@ class User(AbstractUser): accepted_terms = models.BooleanField(default=False) graduation_year = models.PositiveSmallIntegerField(null=True) - GPA = models.DecimalField(null=True, blank=True, name="GPA", help_text="Weighted GPA", max_digits=4, decimal_places=3) + GPA = models.DecimalField( + null=True, + blank=True, + name="GPA", + help_text="Weighted GPA", + max_digits=4, + decimal_places=3, + ) is_senior = models.BooleanField(default=False) is_student = models.BooleanField(default=False) diff --git a/tjdests/apps/profile/forms.py b/tjdests/apps/profile/forms.py index 76acad6..2f1f9aa 100644 --- a/tjdests/apps/profile/forms.py +++ b/tjdests/apps/profile/forms.py @@ -1,3 +1,4 @@ +from decimal import Decimal from typing import Any, Dict from crispy_forms.helper import FormHelper @@ -28,7 +29,7 @@ class ProfilePublishForm(forms.ModelForm): # Check the GPA: 0.0 <= GPA <= 5.0 if cleaned_data.get("GPA"): gpa = cleaned_data.get("GPA") - assert isinstance(gpa, float) + assert isinstance(gpa, Decimal) if not 0.0 <= gpa <= 5.0: self.add_error("GPA", "This is not a valid GPA") diff --git a/tjdests/apps/profile/tests.py b/tjdests/apps/profile/tests.py index 9c787bb..799cec4 100644 --- a/tjdests/apps/profile/tests.py +++ b/tjdests/apps/profile/tests.py @@ -1,3 +1,5 @@ +from decimal import Decimal + from django.urls import reverse from tjdests.apps.authentication.models import User @@ -44,7 +46,7 @@ class ProfileTest(TJDestsTestCase): self.assertEqual( 1, User.objects.filter( - GPA=4.000, + GPA=Decimal(4.000), id=user.id, biography="hello", attending_decision=None, @@ -92,7 +94,7 @@ class ProfileTest(TJDestsTestCase): 1, User.objects.filter( id=user.id, - GPA=3.141, + GPA=Decimal(3.141), biography="hello2", attending_decision=decision, publish_data=True, @@ -123,7 +125,7 @@ class ProfileTest(TJDestsTestCase): 1, User.objects.filter( id=user.id, - GPA=3.141, + GPA=Decimal(3.141), biography="hello2", attending_decision=decision, publish_data=True,