fix(profile): use Decimal in GPA tests

This commit is contained in:
Shreyas Mayya 2022-02-17 10:10:21 -05:00
parent 1c70273a1c
commit 1ddad17a1e
No known key found for this signature in database
GPG Key ID: 42522E3641BA2E31
4 changed files with 25 additions and 9 deletions

View File

@ -6,13 +6,19 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('authentication', '0012_user_preferred_name'), ("authentication", "0012_user_preferred_name"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='user', model_name="user",
name='GPA', name="GPA",
field=models.DecimalField(blank=True, decimal_places=3, help_text='Weighted GPA', max_digits=4, null=True), field=models.DecimalField(
blank=True,
decimal_places=3,
help_text="Weighted GPA",
max_digits=4,
null=True,
),
), ),
] ]

View File

@ -8,7 +8,14 @@ class User(AbstractUser):
accepted_terms = models.BooleanField(default=False) accepted_terms = models.BooleanField(default=False)
graduation_year = models.PositiveSmallIntegerField(null=True) 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_senior = models.BooleanField(default=False)
is_student = models.BooleanField(default=False) is_student = models.BooleanField(default=False)

View File

@ -1,3 +1,4 @@
from decimal import Decimal
from typing import Any, Dict from typing import Any, Dict
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
@ -28,7 +29,7 @@ class ProfilePublishForm(forms.ModelForm):
# Check the GPA: 0.0 <= GPA <= 5.0 # Check the GPA: 0.0 <= GPA <= 5.0
if cleaned_data.get("GPA"): if cleaned_data.get("GPA"):
gpa = cleaned_data.get("GPA") gpa = cleaned_data.get("GPA")
assert isinstance(gpa, float) assert isinstance(gpa, Decimal)
if not 0.0 <= gpa <= 5.0: if not 0.0 <= gpa <= 5.0:
self.add_error("GPA", "This is not a valid GPA") self.add_error("GPA", "This is not a valid GPA")

View File

@ -1,3 +1,5 @@
from decimal import Decimal
from django.urls import reverse from django.urls import reverse
from tjdests.apps.authentication.models import User from tjdests.apps.authentication.models import User
@ -44,7 +46,7 @@ class ProfileTest(TJDestsTestCase):
self.assertEqual( self.assertEqual(
1, 1,
User.objects.filter( User.objects.filter(
GPA=4.000, GPA=Decimal(4.000),
id=user.id, id=user.id,
biography="hello", biography="hello",
attending_decision=None, attending_decision=None,
@ -92,7 +94,7 @@ class ProfileTest(TJDestsTestCase):
1, 1,
User.objects.filter( User.objects.filter(
id=user.id, id=user.id,
GPA=3.141, GPA=Decimal(3.141),
biography="hello2", biography="hello2",
attending_decision=decision, attending_decision=decision,
publish_data=True, publish_data=True,
@ -123,7 +125,7 @@ class ProfileTest(TJDestsTestCase):
1, 1,
User.objects.filter( User.objects.filter(
id=user.id, id=user.id,
GPA=3.141, GPA=Decimal(3.141),
biography="hello2", biography="hello2",
attending_decision=decision, attending_decision=decision,
publish_data=True, publish_data=True,