Skip to content

Commit

Permalink
Add tests for resident activity level
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Nov 28, 2023
1 parent 61e41ac commit ea2e813
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions residents/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from unittest.mock import MagicMock, patch

from .models import Residency, Resident
from homes.models import Home
Expand Down Expand Up @@ -60,3 +61,45 @@ def test_overlapping_residency_not_allowed(self):
# saving a model instance
# https://docs.djangoproject.com/en/4.0/ref/models/instances/#django.db.models.Model.clean
overlapping_residency.clean()


class TestResidentActivityLevel(TestCase):
def setUp(self):
self.resident = Resident.objects.create(first_name="John", last_initial="W")

def test_activity_levels(self):
expected_results = {
0: {"color": "danger", "text": "Inactive"},
1: {"color": "warning", "text": "Low"},
2: {"color": "warning", "text": "Low"},
3: {"color": "warning", "text": "Low"},
4: {"color": "warning", "text": "Low"},
5: {"color": "success", "text": "Moderate"},
6: {"color": "success", "text": "Moderate"},
7: {"color": "success", "text": "Moderate"},
8: {"color": "success", "text": "Moderate"},
9: {"color": "success", "text": "Moderate"},
10: {"color": "warning", "text": "High"},
11: {"color": "warning", "text": "High"},
12: {"color": "warning", "text": "High"},
13: {"color": "warning", "text": "High"},
14: {"color": "warning", "text": "High"},
}

for count in range(0, 15):
with self.subTest(count=count):
with patch(
"residents.models.Resident.activities",
new_callable=MagicMock,
) as mock_activities:
# Set up the method chain to return the correct count
mock_activities.filter.return_value.count.return_value = count

# Test the actual functionality
expected = expected_results.get(count)
self.assertEqual(self.resident.activity_level, expected)

def test_on_hiatus(self):
self.resident.on_hiatus = True
expected = {"color": "info", "text": "On hiatus"}
self.assertEqual(self.resident.activity_level, expected)

0 comments on commit ea2e813

Please sign in to comment.