From ea2e81330f3c7c611c37216b7a52449e679ae85c Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 28 Nov 2023 07:13:22 +0200 Subject: [PATCH] Add tests for resident activity level --- residents/tests.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/residents/tests.py b/residents/tests.py index 3caa284..3e3c6db 100644 --- a/residents/tests.py +++ b/residents/tests.py @@ -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 @@ -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)