forked from GeriLife/caregiving
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request GeriLife#41 from GeriLife/home-residents
Add Home residents feature with activity level listing
- Loading branch information
Showing
10 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import factory | ||
from .models import Home | ||
|
||
|
||
class HomeFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Home | ||
django_get_or_create = ("name",) | ||
|
||
name: str = factory.Sequence(lambda n: f"Home {n}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
# Create your tests here. | ||
from django.test import TestCase | ||
|
||
from .factories import HomeFactory | ||
from residents.factories import ResidentFactory, ResidencyFactory | ||
|
||
|
||
class HomeModelTests(TestCase): | ||
def setUp(self): | ||
# Create test data using factories | ||
self.home1 = HomeFactory(name="Home 1") | ||
|
||
self.home_1_current_resident = ResidentFactory(first_name="Alice") | ||
self.home_1_past_resident = ResidentFactory(first_name="Bob") | ||
|
||
ResidencyFactory( | ||
resident=self.home_1_current_resident, | ||
home=self.home1, | ||
move_in="2020-01-01", | ||
move_out=None, | ||
) | ||
ResidencyFactory( | ||
resident=self.home_1_past_resident, | ||
home=self.home1, | ||
move_in="2020-01-02", | ||
move_out="2020-02-01", | ||
) | ||
|
||
def test_home_current_residencies(self): | ||
current_residencies_home1 = self.home1.current_residencies | ||
self.assertEqual(current_residencies_home1.count(), 1) | ||
self.assertTrue( | ||
current_residencies_home1.filter( | ||
resident=self.home_1_current_resident, | ||
).exists(), | ||
) | ||
self.assertFalse( | ||
current_residencies_home1.filter( | ||
resident=self.home_1_past_resident, | ||
).exists(), | ||
) | ||
|
||
def test_home_current_residents(self): | ||
current_residents_home1 = self.home1.current_residents | ||
self.assertEqual(current_residents_home1.count(), 1) | ||
self.assertIn( | ||
self.home_1_current_resident, | ||
current_residents_home1, | ||
) | ||
self.assertNotIn( | ||
self.home_1_past_resident, | ||
current_residents_home1, | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import factory | ||
import random | ||
import string | ||
|
||
from .models import Resident, Residency | ||
|
||
|
||
class ResidentFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Resident | ||
django_get_or_create = ("first_name", "last_initial") | ||
|
||
first_name: str = factory.Sequence(lambda n: f"First {n}") | ||
# choose a random alphabetical character for the last initial | ||
last_initial = factory.LazyFunction(lambda: random.choice(string.ascii_uppercase)) | ||
url_uuid: str = factory.Sequence(lambda n: f"url-uuid-{n}") | ||
|
||
|
||
class ResidencyFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Residency | ||
django_get_or_create = ("resident", "home") | ||
|
||
resident = factory.SubFactory(ResidentFactory) | ||
home = factory.SubFactory("homes.factories.HomeFactory") | ||
move_in = factory.Faker("date") | ||
move_out = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters